I want to fetch the Access Token from AAD application using below snippet.
var tokenCredential = new DefaultAzureCredential();
var accessToken = await tokenCredential.GetTokenAsync(
new TokenRequestContext(scopes: new string[] { ResourceId + "/.default" }) { }
);
I have created AAD application on Azure portal, How to get ResourceId from the AAD application?
2
Answers
It’s the Application ID URI in your screenshot.
You can technically use either the Application (client) ID or the Application ID URI. Both identify the application.
For sample, I passed
https://graph.microsoft.com
asresourceId
to authenticate Microsoft Graph API.I agree with @juunas, if you want to authenticate the web Api you can pass
resourceId
as the ClientID or the API URL of the Azure AD Application like below:Go to the Azure AD App -> Expose an API -> Add client application with
04b07795-8ddb-461a-bbee-02f9e1bf7b46
and check the scope.And make sure to grant the API permissions: