Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Cognito cookie storage

I'm trying to set up Cognito to use cookies instead of localStorage for credentials so that I can keep the user logged in between domains, e.g. x.foo.com and y.foo.com. The first step is to get it working on localhost but I'm stuck.

The documentation shows a simple config change should do the trick?

The following debug messages are comitted to the console:

[DEBUG] 37:08.223 AuthClass 
Object { idToken: {…}, refreshToken: {…}, accessToken: {…}, clockDrift: 0 }
ConsoleLogger.js:87

[DEBUG] 37:08.228 Credentials - No Cache module registered in Amplify ConsoleLogger.js:84

[DEBUG] 37:08.230 Credentials - set credentials from session ConsoleLogger.js:84

[DEBUG] 37:08.230 Credentials - No Cognito Federated Identity pool provided ConsoleLogger.js:84

[DEBUG] 37:08.230 AuthClass - cannot get cognito credentials No Cognito Federated Identity pool provided ConsoleLogger.js:94

[DEBUG] 37:08.231 AuthClass - Failed to get user from user pool ConsoleLogger.js:84

[ERROR] 37:08.232 AuthClass - Failed to get the signed in user No current user

It seems when you specify the cookieStorage config you need to manually apply a cache instance? How do I do that and will it solve the problem?

like image 993
Noel Heesen Avatar asked Dec 19 '19 11:12

Noel Heesen


People also ask

Does AWS Cognito use JWT?

After a user logs in, an Amazon Cognito user pool returns a JWT. The JWT is a Base64-encoded JSON string that contains information about the user (called claims). Amazon Cognito returns three tokens: the ID token, the access token, and the refresh token.

Does Cognito store user data?

With Amazon Cognito, you can save user data in datasets that contain key-value pairs. Amazon Cognito associates this data with an identity in your identity pool so that your app can access it across logins and devices.

Where is Cognito data stored?

The data is stored both locally on the device and in the Cognito sync store. Cognito can also sync this data across all of the end user's devices.

Does AWS amplify use cookies?

Authenticating with Cognito and cookies. This solution works seamlessly with the AWS Amplify Framework and the Amazon Cognito Auth SDK for JavaScript. All you need to do when you write a SPA with these frameworks is to configure cookie storage for authentication tokens.


1 Answers

This config works:

{
    region: 'eu-west-1',
    userPoolId: 'eu-west-1_XXXXXX',
    userPoolWebClientId: 'XXXXXX',
    mandatorySignIn: false,
    cookieStorage: {
      domain: 'localhost',
      secure: false,
      path: '/',
      expires: 365,
    },
  }

In particular, secure must be false for localhost unless you are using https (Firefox ignores this for localhost, but Chrome and Safari don't).

like image 170
Eric Petroelje Avatar answered Nov 10 '22 21:11

Eric Petroelje