Reputation: 2460
I can't get optional claims to appear in the JWT ID token for an asp.net core API app I'm creating. For testing I'm using POSTMAN to obtain a Bearer token via its inbuilt Oauth2 mechanism. Specifically, I want the user
and profile
scopes, that fall under MS Graph, so that I can access the user's verified email address and their first and last name.
I seem have an identical problem to this question - the first part, where the OP couldn't get the claims to appear at all (e.g. when inspecting the token in debug or via jwt.ms), and this one. In my scenario, I am developing a web API only, that has no UI component. The expectation is that requests will be made in a user context, such that the API can perform Authorization based on user claims.
Beyond wiring up the asp.net core API, I have done the following:
Registered the API app (all following done in Azure portal)
accessTokenAcceptedVersion
to 2
in manifestRegistered a client app (again, in Azure portal, in same tenant)
Oauth2
Authorization method with grant type Authorization Code (With PKCE)
and using the relevant URLs for auth and token, Client ID of the client app registration, and setting scope to the custom scope of my API.Authentication
(my API is configured correctly, associated to the API app registration, and the JWT is coming through correctly to my context in the API). Consent prompt shows the expected permissions when POSTMAN uses the browser to get auth.openid email profile
to the scopes requested (made no difference)I'm expecting to see the additional claims within the Bearer token that I get from POSTMAN, so I can already see they're not present even without my own API running. So I suspect I've missed a configuration step rather than have a bug in my code.
It's clear to me that I've missed and/or misunderstood something here, and I'm stuck.
Upvotes: 2
Views: 2395
Reputation: 58723
As discussed in the comments, you need to configure the optional claims on the access token for the API, not the ID token. Since you are getting an access token in Postman.
Upvotes: 3