example-oauth2-server icon indicating copy to clipboard operation
example-oauth2-server copied to clipboard

Not getting refresh token in oauth/token api

Open ZTAP0011 opened this issue 4 years ago • 5 comments
trafficstars

I am calling /oauth/token to generate the token by passing the code. I set OAUTH2_REFRESH_TOKEN_GENERATOR=True in my flask app config. But I only get access_token in the response but not refresh_token.

ZTAP0011 avatar Feb 04 '21 06:02 ZTAP0011

@ZTAP0011 can you send your curl command? Which grant_type are you using?

lepture avatar Feb 09 '21 13:02 lepture

Hello @lepture , I am sending authrization_code in grant type. But this is the first time we request for the oauth token and not to get a new token from a refresh token.

image

ZTAP0011 avatar Feb 09 '21 13:02 ZTAP0011

Are you using this demo without any change? I've just verified, this demo works fine.

lepture avatar Feb 09 '21 13:02 lepture

Yes, I am using this to get the access and refresh token $ curl -u ${client_id}:${client_secret} -XPOST http://127.0.0.1:5000/oauth/token -F grant_type=authorization_code -F scope=profile -F code=${code}

But in response I only get access token and not the refresh token.

ZTAP0011 avatar Feb 09 '21 15:02 ZTAP0011

Did you give the refresh_token grant to the client (in addition to the authorization_code grant)?

I ran into the same problem and the reason was that Authlib refuses to even generate a refresh token if the client doesn't have the refresh_token grant. Obvious, in retrospect.

joanbm avatar Mar 11 '21 18:03 joanbm