Refresh Token in JWT - azure-ad-b2c

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.

Related

how to secure JWT both client and server

I'm using JWT authentication for my back-end system written with Django rest frame work,
I've read many articles about JWT security but I have some question yet,
our solution for not saving the access token in browsers local was that we save the refresh token in cookie and client request access token with this cookie in every request for not saving access token anywhere,is this approach save enough?
what can I do for server side?for example is using dynamic secret key for JWT a good idea?
I mean create an secret key for each user and use it for token.or any idea that can secure our system.

Is it safe to embed an ID token within a JWT token?

I'm new to JWT and authorization of micro-services in general. We are using Azure to do our authentication for an application backed by micro-services. However, we are using a separate home grown micro-service to do RBAC/ABAC authorization. I was thinking that the general scheme to use in order to secure all of the micro-services is to use JWT. My thought was that once authenticated and I have an Azure ID token, that ID token would be passed within a JWT token to my authorization service in order to get an authorization token from my authorization service. It would use the Azure ID token to validate that the user actually authenticated themselves by validating the ID token and the generate my application access token to use from then on. In general, is it safe/secure to pass around an ID token within a JWT payload? Hopefully that all makes sense.

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

What is the workflow for validating a refresh token and issuing a new bearer token?

This is not a coding question, but a conceptual question for the correct handling and processing of a refresh token.
I have a single page app which issues a jwt token when logging in. The token works just fine. Now, I want to set the expiration to a low value, and use a refresh token to refresh the bearer token.
The question is, what claims should be stored in the refresh token? And what steps are supposed to be done to validate the refresh token before issuing a new token?
For example, right now my refresh token is a jwt which stores an expiration, so the client knows when the refresh token expires, and a username claim so that I know what user the refresh token is associated with.
So then when the refresh token is recieved:
Check that it is not expired.
Check that it has not been revoked.
Use the UserName in the refresh token to issue a new short-lived bearer token.
Is this the correct workflow for this? I just want to make sure I am not missing any security checks.
If your application is a single page application, you should not use long lived refresh tokens as you have no way of securely storing them.
OAuth2 defines a number of grant flows for different types of clients (which I've described here). Refresh tokens are only meant for confidential clients (like web applications living on a secured server).
Your refresh token is just as vulnerable to theft as your access token, since both are bearer tokens stored on the client.
Some OAuth libraries allow SPA or other non-confidential clients to get a new access token by talking to the token endpoint of the authorization server using a session token in a cookie. As long as the cookie is valid, the user can get a new access token. After that, the user will need to re-authenticate. Of course cookies can be marked secure and http only, making them harder to steal.
If you issue the JWT tokens from the same service endpoint that consumes the access tokens, you could have the client include a nonce in the token request that you hash and include as a claim in the token. The client can send the JWT in the Authorization header and the nonce in a custom header. Your token verification would hash the nonce again and compare it to the claim in the JWT. That way, if your token is stolen is harder to use without the nonce value. Of course, in a targeted attack, your nonce could also be stolen.

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

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.

Resources