-
Notifications
You must be signed in to change notification settings - Fork 57
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 can't recognize that the user already signed in (using Cognito@Edge). #39
Comments
Hi, This may be an issue with your cookie configuration. When you load your app and before you run |
I have the same problem, cognito cookies are not send to *.cloudfront.net domain. |
Here's what you should expect to see in your browser's Network tab when you try to access the CloudFront distribution that is being secured by Cognito@Edge (assuming you're not using a federated auth provider).
The response of 6 should contain the authentication cookies (see source code). |
Leaving the answer for someone who will face this problem in future: To make Amplify able to authenticate user after the cognito-at-edge it should be configured to use cookies storage (it doesn't by default whereas cognito-at-edge saves tokens there). Something like that: Amplify.configure({
Auth: {
region: awsExports.REGION,
userPoolId: awsExports.USER_POOL_ID,
userPoolWebClientId: awsExports.USER_POOL_APP_CLIENT_ID,
mandatorySignIn: true,
cookieStorage: {
domain: 'subdomain.example.com',
secure: true,
path: '/',
expires: 365,
},
oauth: {
domain: '...',
scope: ['email', 'openid'],
redirectSignIn: '...',
redirectSignOut: '...',
responseType: 'code',
},
}
}); Issue author has wrong amplify configuration with local storage, it will fail to find cognito-at-edge tokens. |
Amplify.configure({
Auth: {
// REQUIRED - Amazon Cognito Region
region: 'xxx',
userPoolId: 'xxx',
userPoolWebClientId: 'xxx',
localStorage: {
domain: 'xxx.cloudfront.net',
},
oauth: {
domain: 'xxx.auth.eu-west-1.amazoncognito.com/',
scope: ['openid', 'email'],
redirectSignIn: 'https://xxx.cloudfront.net/',
redirectSignOut: 'https://xxx.cloudfront.net/',
responseType: 'code'
}
},
API: {
"Access-Control-Allow-Origin": "*",
"Content-Type": "text/html; charset=UTF-8",
"X-Content-Type-Options": "nosniff"
}
});
Using this configuration amplify can't recognize that the user already signed in (using Cognito@Edge).
Running Auth.currentAuthenticatedUser() gives user not authenticated error, however if I run this after Auth.SignIn() i get a valid response.
The text was updated successfully, but these errors were encountered: