question

GuruKarnik-6372 avatar image
0 Votes"
GuruKarnik-6372 asked totallyGizmo commented

Invalid Scope for grant_type client credentials but works for grant_type password

I'm able to generate an OAUTH bearer token against https://login.microsoft.com/<tenant_id>/oauth2/v2.0/token with the following params:

client_id, tenant, grant_type : password, client_secret, scope: api://<guid>/Employees.Read, username and password.

However, if I change the grant_type to client_credentials and exclude username and password, I am able to generate the token only when the scope is api://<guid>/.default. If I pass a specific scope as in the previous case, I get invalid_scope error.

Why is this so?

azure-active-directoryazure-ad-authentication
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

soumi-MSFT avatar image
0 Votes"
soumi-MSFT answered totallyGizmo commented

Hello @GuruKarnik-6372, thank you for reaching out. There can be a couple of reasons for these errors. Let's check them out one by one:

When you prepare the request to fetch a token from AAD using the Resource_Owner_Password_Grant_Flow of OAuth using the following parameters:
client_id, tenant, grant_type : password, client_secret, scope: api://<guid>/Employees.Read, username and password.

It works as I believe you might have used delegated permissions, However, when you update the grant_type from password to client_credentials and then specify a specific scope lets say https://graph.microsoft.com/User.Read it would throw that following error:

 AADSTS70011: The provided request must include a 'scope' input parameter. The provided value for the input parameter 'scope' is not valid. The scope https://graph.microsoft.com/User.Read is not valid.\r\nTrace ID: 99018132-68a0-4329-b624-3f7d29e41e01\r\nCorrelation ID: 6ee20c43-2e13-4267-bb00-6fc35aa25529\r\nTimestamp: 2020-10-27 07:42:46Z

The reason behind that is, client_credentials flow of OAuth requires application permission to work, but instead, you provided a delegated permission(user permission) and hence it rejected the scope with that error.

I tried to repro this same and I too get the same error when I use specific permission. Please refer to the screenshots below:

Resource_Owner_Password_Grant_Flow:
35383-ropc.png

Modified the same request and updated the grant_type with "Client_Credentials" and it worked as you mentioned:
35326-clientcredentialsflow.png

Until this, it works as the permission User.Read has been provided Admin consent and api://<guid>/.default lists down all the permissions that have been added in the app registration of this app. Since Client_Credentials only supports application permissions, hence even though AAD would issue you an access-token, but then that access-token won't have that user.read permission as that is a delegated permission and not application permission.

But as soon as you specific permission like api://<guid>/user.read or in my case I used https://graph.microsoft.com/User.Read and AAD threw the error of invalid_scope:
35310-clientcredentialsflow-withscopeerror.png

Summary: To get this working, you would either have to use ./default, or if trying to specify specific permission, it has to be application permission for it to work with Client_Credentials flow.

Hope this helps.

Do let us know if this helps and if there are any more queries around this, please do let us know so that we can help you further. Also, please do not forget to accept the response as an Answer; if the above response helped in answering your query.







· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I would be interested to know the current settings that would be required to update in https:///portal.azure.com to be able to grant application permission. Currently, User.Read only shows up as delegated permission. This reproduces all the errors noted above. Any insight would be helpful.

@soumi-MSFT

0 Votes 0 ·