简体   繁体   中英

Cognito wont switch unauthenticated user to authenticated user

I'm using a Cognito userpool and Cognito federated identities to pass an IAM role to authenticated and unauthenticated users. When I try to switch a user from unauthenticated to authenticated, the developer console doesn't register that the change has happened; it is showing that I have 100% unauthenticated users.

Right now I instantiate my AWS client as an unauthenticated user and then call a function to update the credentials when they are available so I can switch them to authenticated. Eg:

AWS.config.region = 'us-west-2';
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
  IdentityPoolId: identityPoolId,
  region: 'us-west-2',
  Logins: {}
});

const updateCredentials = () => {
  const auth = store.getState().auth; //this gets the authentication credentials from a global store.
  AWS.config.credentials.Logins = {
    'cognito-idp.us-west-2.amazonaws.com/us-west-2_XXXXXXXXX': auth.idToken
  };
  AWS.config.credentials.expired = true;
};

As best as I can tell, this is the correct way to do this. See the documentation at the bottom of this page , and here , and here .

However, my console shows that I have no authenticated users, so updateCredentials is not switching users to authenticated. What can be done to fix this?

最后调用AWS.config.credentials.get(()....)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM