Why can't the google JWT token be decoded by jwt.io - azure

I have Google authentication enabled in an Azure App Service .NET Core application, and I am trying to generate an access token using Postman:
An access token and an id_token get successfully generated, but when I input the access token into jwt.io, I see gibberish back:
I am new to google auth as well as JWT in general, so my expectation may be totally invalid, but shouldn't I be able to decode the token on jwt.io?

The access token is not a JWT. The id_token is a JWT and you should be able to decode it using jwt.io.
The difference is connected to the difference between OAuth 2.0 and OpenID Connect.
The access token is used to make additional requests to Google API:
https://developers.google.com/identity/protocols/OAuth2WebServer#callinganapi
The id_token already holds the information for the authenticating user:
https://developers.google.com/identity/protocols/OpenIDConnect#obtainuserinfo

It seems to me, you pasted only two parts of the token in the Encoded area, I see only 1 dot in the string. In the sample given by jwt.io there is 2 dots in it that separates it to 3 parts.

Related

Update Azure IDP Config so that Refresh Token is in JWT Format

When I retrieve a token from Azure IDP for to be authenticated and authorised to hit one of our services on Azure, the payload includes an "access_token", which has a value in JWT format. It also includes a "refresh_token", and its value is not in JWT format and does not decode, hence failing token validation that our app runs after getting the payload back from IDP.
What should be changed in the manifest? Token format is 0.x.x instead of eyxxx.x.x. I believe the 0 is where the eyxxx should be for token headers?
The refresh token is not meant to be decoded or validated in your client application. It is just a random string issued and that you can return to get a new set of access and refresh tokens.
The client should not care about what it contains or how it is structured, it is just a piece of data.
According to the specification here, it says:
A refresh token is a string representing the authorization granted to
the client by the resource owner. The string is usually opaque to the
client.
ie, the refresh token is never inspected by the client, its just a blob of data that you pass back to the authorization server to get new tokens.

Refresh Token in JWT

How to get the refresh token in JWT format?
Team is working on authentication using AAD and the OIDC library that is being used expects the tokens to be in JWT for decoding purpose.
Refresh token is not returned in JWT. Applications should not be inspecting a RT as it is only useful for the Authorisation server to issue new Access tokens. RT is an encrypted blob that only the authorisation server can decode for this process.

Does Azure Active Directory support the JWT bearer token flow?

We have a number of services that can be called by users via HTTP based protocols (SOAP/REST/WebDAV). The services support various authentication mechanisms (e.g. Basic, and OIDC Bearer tokens). Sometimes a service has to call another service without a live user. For that, we configure technical users, and service A can call B with the credentials of a technical user.
For OAuth/OIDC authentication via Bearer tokens, we use the JWT bearer token flow to acquire access tokens for our technical users: Service A creates a JWT with the name of the technical user and signs it with its own private key. It then calls the OIDC token endpoint with that token and receives an access token for its technical user X. It can then use this token as a bearer token to call service B, which will accept the token for user X. (For more information on the JWT bearer flow, cf. RFC 7523 section 2.1 and RFC 7521 section 4).
This works fine with our Connect2id test server and also with Salesforce, but we haven't been able to get it working with Azure. Accessing Azure's token endpoint always results in the following error response:
AADSTS50027: JWT token is invalid or malformed
According the Microsoft's documentation, this error can have any number of reasons:
doesn't contain nonce claim, sub claim
subject identifier mismatch
duplicate claim in idToken claims
unexpected issuer
unexpected audience
not within its valid time range
token format is not proper
External ID token from issuer failed signature verification.
When trying to find out more about Azure and the JWT bearer flow, the only solid information I've been able to locate is this article:
https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-on-behalf-of-flow
It describes the "On-Behalf-Of" (OBO) flow, which as far as I understand is an extension (by Microsoft?) to the JWT bearer flow, adding a second JWT to the mix along with a parameter called "requested_token_use" set to "on_behalf_of". I can only find "requested_token_use" in relation to the special OBO flow, and its only value seems to be "on_behalf_of".
OBO flow isn't what we want, since it seems to allow a service X to turn a token received by service Y into another token, using the Y token and a self-generated X token to call the token endpoint. Our use case only has a self-generated X token and the name of the user who the app is permitted to impersonate.
After a lengthy trial & error phase we've come to the impression that OBO may in fact be the only (non-standard) version of the JWT bearer flow that Azure knows about, and that it may not support the "normal" JWT bearer flow we're trying to use at all. Is this correct, and we have no option but to give up trying to solve this scenario with standard OIDC when Azure is involved, or does Azure in fact also support the flow we've implemented and we're just doing something wrong (e.g. wrong audience or issuer in our JWT, or a mis-configured app in Azure)?
PS: Our code is written in Java and we use the Nimbus library for our OAuth/OIDC communication.

Unable to successfully validate an access token from Microsoft Graph API

I am using the Microsoft Graph API along with Microsoft Authentication Library (MSAL) to acquire access tokens and I can successfully retrieve the access token, id token and refresh token. I can also successfully validate the id token. However, I cannot do the same for the access token as I'm getting this error:
raise InvalidSignatureError('Signature verification failed')
jwt.exceptions.InvalidSignatureError: Signature verification failed
I've reviewed as best as I can the microsoft documentation regarding validation here:
Microsoft identity platform access tokens
For validation, I can successfully decode using the jwt.ms site for jwt validation. So I know the tokens are good. I can see from the decode the claims and extract the aud(audience) and iss(issuer). These values are not the same for the id token (which I can successfully validate).
I am using the public keys from the following url as documented:
https://login.microsoftonline.com/<TENANT ID>/discovery/keys
So, what I missing in regards to validating the access token? (if I can validate the id token with no issues). How else can i troubleshoot this?
Jim's answer is correct and there are 2 use cases really - so it depends what you are trying to do:
Getting an access token for Microsoft resources - such as Graph - in which case you don't validate them
Getting a token for your own API resources, in which case you need to validate them. For this to work you need to 'expose an API scope' to get a different type of access token
Behaviour is not intuitive in my opinion, since I like to build standards based solutions. If it helps, here is a visual blog post of mine on getting the second scenario above working.
As far as I knew, we do not need to validate Microsoft graph signature. Because MsGraph recognized an opportunity to improve security for users. They achieved this by putting a ‘nonce’ into the jwt header. The JWS is signed with a SHA2 of the nonce, the nonce is replaced before the JWS is serialized. To Validate this token, the nonce will need to be replaced with the SHA2 of the nonce in the header. Now this can change since there is no public contract. So When calling Microsoft Graph, you should treat access tokens as opaque. For more details, please refer here and here

Google Actions Authentication flow not sending JWT token, how to validate the token provided?

I'm trying to implement OAuth authentication for my google home compliant google-actions backend but I'm not sure on how to validate the token that google is giving me on the authorization header, I was expecting an JWT token but it isn't.
I'm doing my backend on express and node.js with express-jwt to parse the token and jwks-rsa to fetch the encryption key. I've setup my Auth0 tenant loosely based on this guide and it works fine, the login screen shows up and works just fine.
An example of a token google sends me is something along the lines of
authorization:"Bearer msuVRoQGJ_aPqH-zShLq053aAEVmlHqi"
I was expecting google to communicate with Auth0 to exchange a JWT token and then use it to authenticate to my API by sending it as a authorization header. But I don't know what is the bearer token google is sending or how do I validate it.
By default Auth0 will send you an opaque access token when you authorize to a non-Custom API (similar to the one you received). JWT Access tokens are only issued to custom APIs. So in order to get it in JWT format, you will need to create an API in Auth0 and set the API identifier you defined as the audience parameter.
You will issued JWT Access tokens for Custom APIs and you can validate and verify the integrity of it (there is an example on how to do this in Nodejs): https://auth0.com/docs/api-auth/tutorials/verify-access-token

Resources