amazon-archives / amazon-cognito-identity-js

Amazon Cognito Identity SDK for JavaScript
Other
984 stars 454 forks source link

Use this library without a cognito pool, just a federated identity pool #684

Open interestinglive opened 6 years ago

interestinglive commented 6 years ago

Hi, we have a federated identity pool, not a user pool and are successfully authenticating and accessing AWS resources which is all good.

We are having the issue that our sessions seem to expire after 15 minutes and we receive the error "Invalid login token. Token expired: 1518436004076 >= 1518435610394" this occurs even though we are calling refresh on our credentials regularly.

I've run out of ideas and am hoping for a bit of help, any ideas what we are doing incorrectly?

Our auth code is as below:

let Logins = {};
Logins[environment.samlIdpArn] = samlResponse;
AWS.config.region = environment.region;
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
  IdentityPoolId: environment.identityPoolId,
  CustomRoleArn: environment.roleSelectedArn,
  Logins
});

let tmp = this;
AWS.config.getCredentials(function (err) {
  if (err) {
    console.log("error getting creds - check session");
    callback.cognitoCallback(err.message, null);

  } else {
    tmp.cognitoUtil.setCognitoCreds(<AWS.CognitoIdentityCredentials>AWS.config.credentials);
    callback.cognitoCallback(null, "Authenticated");
  }
});

And we are refreshing as per:

 Logins[environment.samlIdpArn] = saml;
  AWS.config.region = environment.region;
  AWS.config.credentials = new AWS.CognitoIdentityCredentials({
    IdentityPoolId: environment.identityPoolId,
    CustomRoleArn: environment.roleSelectedArn,
    Logins
  });

  let tmp = this;
  (<AWS.TemporaryCredentials>AWS.config.credentials).refresh(function (err) {
    if (err) {
      console.log("Error getting creds - check session");
      console.log(err.message);
      callback.isLoggedIn("No credentials", false);

    } else {

      console.log("Well, called refresh");

......

Thanks for your time.