I have an app registration in which test.user
is my scope. In API permissions, I have delegated permissions for test.user
scope.
In Postman, I tried like this:
Grant_type : client_credentials
Clienid : my appid
scope : api:\\.....id\.default
Client_secret: secret
I'm able to get an access token. But if I pass this token as authorization bearer, my app is always treating as user authenticated as false with no claims. Please help why no claims.
Also if I don't add .default and simply add scope value as api//myid/test.user
it's throwing error as you have to use .default
. Why?
Hi, Thankyou for your answer. I need to wait for admin to turn on application permission for the role as I do not have access.
Meanwhile, I want to explain the actual problem.
I have my application backend (api). I have created appregistration with clientid, clientsecret, scope etc., NOW from my UI (angular) was able to authenticate api (Swagger) by passing my microsoft login and user is authenticated its fine. My api swagger is below. swagger looks like below
However, I have few other clients who want to call my api endpoints. So for that, it should not be interactive login. as there is some kind of job they run and it has to get api response automatically without prompting for user logins etc., So I thought, i can use client credentials for this. Please let me know is client credentials grant is really needed or do i need to go with some other granttype. If so please explain.
EDIT2: httpcontext claims are as below. Claims
Thankyou.
Note that: Client credential flow uses its client ID and client secret to the authorization server and performs authentication.
In your scenario, test.user
scope is a delegated type of API permission hence the access token will not contain the scp claim with value as test.user
.
/.default
and its by default and cannot pass the scope name directly.Hence, you have to Expose an API and create App roles while use client credential flow:
Now the app role will be an application type API permission:
Generated the token:
GET https://login.microsoftonline.com/TenantID/oauth2/v2.0/token
Grant_type : client_credentials
Clienid : ClientID
scope : api://ClientID/.default
Client_secret: ClientSecret
When decoded, the roles claim is present in the access token:
displayname
, objectid
and tags
can only be used. Refer this SO Thread by me.