piisexactly3
piisexactly3

Reputation: 779

Why aren't the application permissions being added to my MS Graph token?

I'm trying to get a subscription created with the callRecord resource (https://learn.microsoft.com/en-us/graph/api/subscription-post-subscriptions?view=graph-rest-beta&tabs=http)

In the app registration section of the Azure portal, I've created a multi-tenant app with a client secret. That app has permissions for application-level "CallRecords.Read.All" as well as the default delegated "User.Read". The statuses also have a green checkbox for being granted against my organization by an admin.

I am able to get an access token with the following HTTP POST request to https://login.microsoftonline.com/common/oauth2/v2.0/token:

grant_type:authorization_code
scope:https://graph.microsoft.com/.default
client_secret:<client_secret>
client_id:<client_id>
code:<code>
redirect_uri:http://localhost:3000 

However, that token is not able to generate a subscription to my callRecord resource. I get a response with this message: "Operation: Create; Exception: [Status Code: Forbidden; Reason: The request is not authorized for this user or application.]"

The message suggests that the app has not been granted admin-level authorization, but in fact it has. This used to work for me. I'm wondering if there has been a regression on the MS Graph side.

Further, when I examine the JWT, I see that the scope is "User.Read profile openid email". There is no mention of the application-level permission (specifically, CallRecords.Read.All)

Thanks.

Upvotes: 0

Views: 1071

Answers (1)

Joy Wang
Joy Wang

Reputation: 42063

Because when you use the auth code flow, just the Delegated permission will take effect. So even if you grant the Application permission, the token you got will not include the permission.

From the doc, to call this API Get callRecord, just the Application permission is supported.

enter image description here

To get the token which include the permission, your option is to use the client credential flow.

Note: You need to use <tenant-id> instead of common in this flow.

POST https://login.microsoftonline.com/<tenant-id>/oauth2/v2.0/token

client_id=xxxxxxx
&scope=https://graph.microsoft.com/.default
&client_secret=xxxxxxx
&grant_type=client_credentials

enter image description here

Decode the token in https://jwt.io, the roles includes the CallRecords.Read.All permission:

enter image description here

Upvotes: 3

Related Questions