-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Amplify API calls fail to refresh token #2549
Comments
@skylerrichter I reproduced the problem I marked this as a bug and try to send a pr to fix it |
@skylerrichter I found the root cause of your issue. You need to add to _signInWithGoogle = () => {
Google.logInAsync({
iosClientId: 'IOS_CLIENT_ID',
scopes: ['profile', 'email']
}).then((res) => {
if (res.type === 'success') {
Auth.federatedSignIn('google', { token: res.idToken, expires_at:<token_expiration> }, { email: res.user.email })
.then((creds) => {
this.props.navigation.navigate('Main');
});
}
});
} I will mark this as enhancement rather than bug, it should warn in case the expires_at is not there. |
@skylerrichter if you need to refreshTokens you can define a function refreshToken() {
// refresh the token here and get the new token info
// ......
return new Promise(res, rej => {
const data = {
token, // the token from the provider
expires_at, // the timestamp for the expiration
identity_id, // optional, the identityId for the credentials
}
res(data);
});
}
Auth.configure({
refreshHandlers: {
'developer': refreshToken // the property could be 'google', 'facebook', 'amazon', 'developer', OpenId domain
}
}) |
The docs is a bit misleading. It doesn't automatically refresh the token in a non browser environment. One has to implement it. |
Describe the bug
After a successful sign in using Auth.federatedSignIn() I am only able to successfully make 1 API call before my security token expires. If I refresh my app after signing in the API will return a 403. If I refresh a second time Amplify will forget my credentials and I will be back on the login screen.
To Reproduce
App.js
Login.js
Foo.js
Expected behavior
Security tokens should refresh automatically as per the Amplify documentation "When using Authentication with AWS Amplify, you don’t need to refresh Amazon Cognito tokens manually. The tokens are automatically refreshed by the library when necessary."
Smartphone
The text was updated successfully, but these errors were encountered: