Hi @Aashutosh Aryal , thanks for reaching us.
I understand you trying to use NextAuth for next.js with Azure Active directory for single-sign-on. You will be able to decode the id_token but get a Signature verification failed error when trying to decode the access token.
Register two applications in Azure AD for Front-end and Back-end.
Sign into the Azure portal -> select Azure Active Directory in the tenant ->register the application.
Create second application as followed above step.
To use OAuth 2.0 On-Behalf-Of flow (OBO) to get access tokens. Scope should be the Api://{client_id} so that no consent is required.
Azure active directory ->App registration -> select your Application
->Expose an API ->Add an Application ID URI as api://{clientid}
->Add scope and Client Application.
Go to second application ->Expose an API and add Application1 API as client application.
Use www.jwt.io to validate your access token.
• audience - Verifies that the ID token was intended to be given to your application. Access tokens are created based on the audience of the token,
meaning the application that owns the scopes in the token.
• not before and expiration time - Verifies that the ID token hasn't expired.
• issuer - Verifies that the token was issued to your application by Azure AD.
• nonce - A strategy for token replay attack mitigation.
To get User information using access token, you can use Graph API and make sure to use authorization as Bearer Token.
For your reference: https://microsoft.github.io/MicrosoftCloud/tutorials/docs/Authentication-App-With-NextJs-And-Microsoft-Graph/
https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-on-behalf-of-flow
Thanks,
Navya.
Hopes this helps. Do let us know if you have any queries.
Please "Accept the answer" if the information helped you. This will help us and others in the community as well.