Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Cognito/Amplify returning empty refresh token

I have a userpool in cognito which uses Google as the identity provider. Now, using Amplify, we do a FederatedSign with provider as 'Google' as shown below.

Auth.federatedSignIn({ provider: "Google" });.

This gives me back the access token, id token. But the refresh token is empty. This is for the oauth responseType:'token' configuration.

I have seen elsewhere that we need to change the grant type to 'code' i.e responseType: 'code' in order to get the refresh token.

But in this scenario, I am getting 'code = some-value' in the callback url and not the access token and refresh token.

What am I missing here?

My aim is to be able to get the refresh token - and using this Amplify would refresh the session once the access token in invalid.

like image 243
user13628417 Avatar asked Oct 15 '22 00:10

user13628417


2 Answers

You need to change oauth.responseType in your config to 'code' instead of 'token'. I'm getting an error when I do that and I'm not sure why, but this is what I found you need to do.

like image 90
Kevin Danikowski Avatar answered Oct 20 '22 17:10

Kevin Danikowski


I am using parseCognitoWebResponse and had the same problem.

  1. Within your User Pool go to App Clients. Check your Cognito App Client and make sure no client secret is generated. If it is filled in recreate an App Client without generating a Client Secret

No Client Secret

  1. Change the response_type to code

window.location.href = `https://${yourCognitoDomain}?response_type=code&client_id=${yourClientId}&redirect_uri=${cognitoRedirectUrl}`

like image 28
WiredIn Avatar answered Oct 20 '22 17:10

WiredIn