1

This could be a duplicate question but I'm not able to resolve it.

We have three websites running on Angular 10:

sso.mywebsite.com

dev.mywebsite.com

demo.mywebsite.com

When somebody comes to dev or demo site, they click on login icon and redirects to sso.mywebsite.com. There user is authenticated with Cognito using Amplify + Angular.

Now the user is redirected back to the dev or demo site from where login was initiated. Here if the user is already authenticated from sso website, s/he should be redirected to the main pages of website which is not happening.

After some research on the internet, I found that Amplify should be able to load authentication data if cookieStorage is defined something like this in Angular:

export const environment = {
  AMPLIFY: {
    region: 'us-east-2',
    userPoolId: 'us-east-2_xxxxxx',
    authenticationFlowType: 'USER_PASSWORD_AUTH',
    userPoolWebClientId: '2xxx6j8xxxx1u2dixxxxnge',
    cookieStorage: {
      domain: 'mywebsite.com',
      secure: false,
      path: '/',
      expires: 365,
    }
  }
};

The cookieStorage settings are same in all three websites. But Amplify still cannot read authentication data. What am I doing wrong here?

Ashutosh
  • 4,371
  • 10
  • 59
  • 105
  • Shouldn't `domain: 'mywebsite.com',` be `demo.mywebsite.com` and `dev.mywebsite.com`? the cookies won't get sent unless the domains match. – Zze Apr 13 '22 at 19:08
  • If I set domain to individual subdomain, will Amplify able to match them by domain name? – Ashutosh Apr 14 '22 at 04:14
  • Cookies will not get sent unless it is an exact match. See this: https://stackoverflow.com/questions/1336126/does-every-web-request-send-the-browser-cookies – Zze Apr 14 '22 at 04:31

1 Answers1

0

I fixed this with following settings:

Set .mywebsite.com instead of mywebsite.com

export const environment = {
  AMPLIFY: {
    region: 'us-east-2',
    userPoolId: 'us-east-2_xxxxxx',
    authenticationFlowType: 'USER_PASSWORD_AUTH',
    userPoolWebClientId: '2xxx6j8xxxx1u2dixxxxnge',
    cookieStorage: {
      domain: '.mywebsite.com',
      secure: false,
      path: '/',
      expires: 365,
    }
  }
};
Ashutosh
  • 4,371
  • 10
  • 59
  • 105