0

I am using Python ADAL library to Authenticate a user using Azure Active Directory. I successfully receive the access token post authentication. Now, I want to verify the validity of the access token. I need the ID_TOKEN in this case. How do I get it?

import adal
auth_context = adal.AuthenticationContext("https://login.microsoftonline.com/{{tenant_id}}")
token_response = auth_context.acquire_token_with_username_password("https://management.core.windows.net/", username, password, client_id)        

In the token response, I get the access_token and refresh_token but I do not receive the id_token. Following a similar question, How to verify JWT id_token produced by MS Azure AD? I used the code to validate the access token but I need the ID_TOKEN.

Any thoughts on getting this would be great.

1 Answers1

0

No need to get the ID_TOKEN, try the code as below.

import adal
import jwt

auth_context = adal.AuthenticationContext("https://login.microsoftonline.com/{{tenant_id}}")
token_response = auth_context.acquire_token_with_username_password("https://management.core.windows.net/", username, password, client_id)

token_header = jwt.get_unverified_header(token_response['accessToken'])

For more details, you could refer to this similar issue and this doc.

Joy Wang
  • 39,905
  • 3
  • 30
  • 54
  • I tried this. It does work, however even if I add some random values to the token it still sends me back those headers. Any reason why this is happening? – Roshan Joe Vincent Oct 03 '19 at 12:43
  • @RoshanJoeVincent How did you do? Maybe this issue?https://stackoverflow.com/questions/57869775/access-token-validation-in-azure-ad-authentication/57870035#57870035 – Joy Wang Oct 03 '19 at 13:02