Skip to content
Advertisement

Cannot pass JWT refresh token as an argument

I’m trying to get a new access token using a refresh token in Spring Boot with OAuth2. It should be done as following: POST: url/oauth/token?grant_type=refresh_token&refresh_token=....

It works fine if I’m using InMemoryTokenStore because the token is tiny and contains only digits/letters but right now I’m using a JWT token and as you probably know it has 3 different parts which probably are breaking the code.

I’m using the official migration guide to 2.4.

When I try to access the URL above, I’m getting the following message:

JavaScript

How do I pass a JWT token in the params? I tried to set a breakpoint on that message, so I could see what the actual argument was, but it didn’t get to it for some reason.

JavaScript

Advertisement

Answer

I assume that the Cannot convert access token to JSON might have been due to incorrectly pasted token.

As for Invalid refresh token, it occurs because when JwtTokenStore reads the refresh token, it validates the scopes and revocation with InMemoryApprovalStore. However, for this implementation, the approvals are registered only during authorization through /oauth/authorize URL (Authorisation Code Grant) by the ApprovalStoreUserApprovalHandler.

Especially for the Authorisation Code Grant (authorization_code), you want to have this validation, so that the refresh token request will not be called with an extended scope without the user knowledge. Moreover, it’s optional to store approvals for future revocation.

The solution is to fill the ApprovalStore with the Approval list for all resource owners either statically or dynamically. Additionally, you might be missing setting the user details service endpoints.userDetailsService(userDetailsService) which is used during the refresh process.

Update:

You can verify this by creating pre-filled InMemoryApprovalStore:

JavaScript

I would also take a look at implementing it in the storeRefreshToken()/storeAccessToken() methods of JwtTokenStore, as they have an empty implementation, and the method parameters contain all the necessary data.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement