Trying to create a new client secret using powershell script. while executing New-AzureADApplicationPasswordCredential from powershell ISE, getting below error:
New-AzureADApplicationPasswordCredential : Error occurred while executing SetApplication Code: Authorization_RequestDenied Message: Insufficient privileges to complete the operation. RequestId: 1234567-abcd-1234-7890-1234567890 DateTimeStamp: Mon, 12 Dec 2022 05:21:54 GMT HttpStatusCode: Forbidden HttpStatusDescription: Forbidden HttpResponseStatus: Completed
Attached image has the API permissions given for the SP used to authenticate to AD. The SP has read/write access on AD graph and MS Graph and has Admin consent on org as well.
I tried in my environment and got below results:
Initially I tried the same command and got same error.
Console:
Make sure the User or service principal with whom you are trying to login into azure has at least contributor role or owner role at subscription level.
Go to portal -> Subscription -> Access control(IAM) -> Add role assignments ->Add Contributor or Owner
to your user or SP.
Also, make sure User or SP has Azure AD role of at least Application Administrator
.
Go to portal -> Azure-Active-Directory -> Roles and Administrators ->Application Administrator -> Add the role to your User or SP.
After Assigning both roles in my environment, I got the Client-Secret
successfully.
Console: