App ID shows up in JWT token instead of app ID URI? - azure-active-directory

I have a 2.0 Azure AD application (registered a BF bot), and I have set up an app ID URI so my users can use it as the aud for auth token.
I could use the the app ID URI to get an JWT token successfully, however the token's aud is not the app ID URI, but the APP ID. Is this the expected behavior?
Tried the same thing with old Azure AD applications and the token had the app ID URI as aud. Actually, if I change the "accessTokenAcceptedVersion" property from 2 to null, the 2.0 Azure AD app would work too.
This is very confusing why did such change made to the new version. Is this by intention so the app should always validate that the aud is the app ID?

I check all type tokens (no old Azure AD app). For now, only the audience of MS graph API and Azure AD graph API is the app ID URI, for others almost is app ID/client id.

Related

Why the URL of Azure App service can't be used as the Application ID URI in Azure AD?

The azure app service provided an URL in such format https://your-app-name.azurewebsites.net
When Expose an API in azure app registration the Application ID URI is needed. But when I use the url provided by the azure app service I got the following error:
Values of identifierUris property must use a verified domain of
the organisation or its subdomain: https://your-app-name.azurewebsites.net
the URL provided by the app service is not a verified domain? and how can I make it verified?
Application ID URI is an identifier that can be used instead of the client ID when specifying a scope defined in that app.
It has nothing to do with authentication redirect URIs, where it would need to match your app hosting.
Agree with juunas and this is just additional description. Screenshot below contained the error you met and one of the supported App ID URI pattern.
I'm afraid that the reason for exposing API is that you want to protect your web API with Azure AD. The App ID URI here is used for the authorization. Your web app also requires to configure the audience, then after you integrate Azure AD authorization into your application, the scope, the audience and other claims containing in the incoming access token will all be verified. I have a sample which is based on a web api. You can see the configuration for Azure AD authorization.
And https://your-app-name.azurewebsites.net is for authentication which used for redirect from microsoft identity platform back to your own web app. The scenario can be opening your own web page which requiring user to sign in --> redirect to microsoft sign in page --> sign in then redirect back to your web page. So we need to identify the redirect URL in Azure AD.

ReactJs FE and Django Rest Services with Azure AD for authentication & Authorization

I'm having a Frontend application built in Reactjs connecting to Azure AD using msal for authentication. After authentication, the user needs to click a button which calls a Django rest API which is also authenticated using Azure AD.
React FE and Django connects to two separate App registrations in Azure AD. Even thought 1) FE is added to Django's App registration as known client 2) Django is exposing the API and the scope is given consent.
When the authenticated FE sends requests to the Django Rest service with Bearer token,
it fails to authenticate the request saying 'invalid token'.
I'm able to authenticate FE and Django rest service separately but authenticated FE is not able to connect to the Django Rest service. Please share your thoughts on what else needs to be checked or any solutions.
Please check if any of these configurations can be worked around
Check if you have given your react app’s URL in the redirect URL in portal and code , so that once the Azure AD validates the user and it’ll return back to your react app with ID Token.Also, enable Access Token and ID Token.
Check if you have created a scope for your web api (in Azure Portal > Your API > Expose an API). Then configure it on your client app on the API Permissions menu tab. Then add it on your scopes collection in code settings.Also, add grant admin consent for that API permission.
Check the manifest of your azure ad app: Below value is probably null or one, should be two: If you are using v2.0 endpoint,
"accessTokenAcceptedVersion": 2,
If you are using v2.0 endpoint, the scope should be api://{server_client_id}/.default.
In the code setting.py for your application, you'll need to provide the authority to which your web app delegates sign-in. (ex: authority: 'https://login.microsoftonline.com/(your tenant id>',)
auth: {
clientId: '232a1406-b27b-4667-b8c2-3a865c42b79c',
authority: 'https://login.microsoftonline.com/e4c9ab4e-bd27-40d5-8459-230ba2a757fb',
//
}
When we perform a token validation, Check your jwt token in http://jwt.io
Audience: The token is targeted for the web API.
"aud" value that is being generated for JWT token by azure is also controlled by "accessTokenAcceptedVersion" property in AD application manifest.(see if issuer or iss has v2 to confirm as v2 endpoint )
If you have set the access token accepted version to 2, then the client id and audience needs to be same (i.e. no need to write api:// in audience)
Note that Implicit flow is the only flow supported for SPA. Authorization code flow is intended for webapps, mobile and desktop apps but not for SPA.Please refer this document
References:
See how to configure Azure AD and how to determine the settings for
django-auth-adfs.
You can check this and find your use case scenario.
Check v2-supported-account-types for authentication-flows
Check OAuth2.0 On-Behalf-Of flow

Can't access Azure Appservice protected by AAD from Postman

I have an app service say https://blahablah.azurewebsites.net to which I have hosted an ASP. Net web api project(An api that returns list of to do items by GET request), so that I can access the API without any authentication using https://blahablah.azurewebsites.net/api/TodoItems as i had TodoItems as my controller.
Now when I create an Azure AD and set Advanced Authentication of the app service; I can't access the api on the previous endpoint; When I use postman with the client id, secret, auth and token endpoints, it says my redirect URL is not valid;
So what should be my redirect URL? How can i successfully send a GET request from POSTMAN?
Update 1: My endpoints were wrong, and I corrected it to login.microsoftonline.com instead of login.microsoft.com, so I'm getting the access token, but when I'm sending a get request to above api with that token in header, it still says 401 unauthorised.
And i'm using redirect url as https://www.getpostman.com/oauth2/callback
Update 2: Here is my configuration
1)I have 2 AAD apps: blahablahAAD aap and PostmanAAD app
2)For app service, blahablah i use the first AAD app thru Express authentication of Azure Active Directory;
3)I have made https://blahablah.azurewebsites.net/api as the first AAD app's Application ID URI, and hence am able to expose https://blahablah.azurewebsites.net/api/TodoItems with TodoItems as scope.
4)I have added the API to "API permissions" of the first AAD app; (uptil now it works well in browser asking me for login and then taking me to the endpoint;)
5) For the PostmanAAD, I use it's client id,secret in Postman and get the token; I send it as request header to API;but it failss
6) I have added PostmanAAD's client id in "Expose API->add client application" of blahablahAAD.
7) I have done step 4 for PostmanAAD also
8) I have granted admin consent to all in default directory.
Note: I haven't added any authorization related code to my ASP .NET web api project that i hosted as app service, but i believe i can access it without writing code(as in AAD will do the task for me).
Set resource url as the guid of the azure ad app instead of application id url.
Click azure ad app and choose Application Id in Overview.

Azure app service authentication with Azure AD - Why is an AD app required?

I have been following this link to set up the in-built configuration using Azure AD into my App service instance.
https://learn.microsoft.com/en-us/azure/app-service/configure-authentication-provider-aad
Additionally I dont want users to generate token with audience as client-id of AD app, so I have added App ID Url to my AD app = http://example.com, and added the same URL to allowed audiences in Advanced auth settings in App service instance.
So now users with token having this URL as audience are able to hit my service,
Now that my users are not generating token with audience as the client ID of AD app, I'm not sure why this client ID has to be configured(mandatory) in App service auth settings. Please help me understand.

What's the main reason of AADSTS90009?

In this post,
AAD token: Why aud sometimes shows app id, sometimes it's the app url?
I learn why the aud field in AAD token is sometimes app id, sometimes app url. They seems depend on what you put as resource when requesting token.
But, while I'm experimenting requesting an AAD token for a SPA website with app url (the SPA website's AAD app url), it returns AAD error - AADSTS90009.
AADSTS90009: Application '' is requesting a token for itself. This scenario is supported only if resource is specified using the GUID based App Identifier.
See this post for related discussion.
OAuth 2.0 and Azure Active Directory - error AADSTS90009
I'm curious, what is the main reason behind this error?
Why it cannot support app url as resource identity?
If you are leveraging AAD and you get a token where aud claim contains:
a Uri - it means you are dealing with access_token and the Uri
represents Service Principal Name (read 'unique identifier') of the resource application your client application wants to access.
a Guid - it means you are dealing with id_token and the value corresponds to ObjectId of that app which acquired the token.

Resources