question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Credentials._setCredentialsFromSession generates invalid provider name

See original GitHub issue

Credentials._setCredentialsFromSession generates invalid provider name when identity and user pools are on different regions

To Reproduce:

  1. Have Cognito user and identity pools in different regions
  2. Log in with amplify-js client
  3. Observe the failing https://cognito-identity.REGION.amazonaws.com/ call
    • Request body has a provider name of form cognito-idp.eu-west-1.amazonaws.com/eu-central-1_XXXXXXXXX in Logins structure (note the conflicting regions)
    • Response: NotAuthorizedException: Invalid login token. Issuer doesn't match providerName

Expected behavior

The regions in the provider name should be consistent with the region of the user pool that issued the id token, to successfully produce federated credentials.

Code Snippet

Provider name is constructed here: https://github.com/aws-amplify/amplify-js/blob/aws-amplify%403.0.22/packages/core/src/Credentials.ts#L356

Screenshots

invalid_key

What is Configured?

"aws-amplify": "^3.0.22",
  Auth.configure({
    userPoolId: 'eu-central-1_XXXXXXXXX',
    userPoolWebClientId: 'XXXXXXXXXXXXXXXXXXXX',
    identityPoolId: 'eu-west-1:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXXX',
    identityPoolRegion: 'eu-west-1',
    region: 'eu-central-1',
    mandatorySignIn: false,
  });

  Analytics.configure({
    disabled: false,
    AWSPinpoint: {
      appId: 'XXXXXXXXXXXXXXXXXXXXXXXX',
      region: 'eu-west-1',
      mandatorySignIn: false,
    }
  })

We don’t use Amplify CLI to set up resources; only the javascript client in a browser, so far.

But I think resource configuration is correct, because everything works when I apply these changes: https://github.com/juranki/amplify-js/commit/29af87c566749002c1f3d0a65c801940f8cd1d83

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
ashika01commented, Aug 1, 2020

@juranki thank you for the intense research. Okay I got it now. I will look into this and see we can make changes in our end. Thank you 😊

2reactions
jurankicommented, Aug 1, 2020

The patched version is one with this change applied: https://github.com/juranki/amplify-js/commit/29af87c566749002c1f3d0a65c801940f8cd1d83

I’m happy to submit that as a pull request if it’s selected as the correct way to fix the problem. But it very narrowly focuses on finding the correct provider name in this specific situation. I’m not familiar with amplify-js codebase so I chose a solution that can be applied locally in that one method.

But why was id pool region used, even if the configuration has entries for the regions of both id and user pools? This line caught my eye: https://github.com/aws-amplify/amplify-js/blob/aws-amplify%403.0.22/packages/auth/src/Auth.ts#L179

It appears to collapse the id and user pool regions into one setting and might have implications, besides the one I bumped into.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting credentials - Amazon Cognito - AWS Documentation
This section describes how to get credentials and how to retrieve an Amazon Cognito identity from an identity pool.
Read more >
Credentials Provider Not Firing Session Callback · Issue #3970
Hello,. I'm having trouble with using Credentials Provider where it's not firing the session callback. I've logged the whole process from signin ...
Read more >
NextAuth with custom Credential Provider Not creating session
I am following the official documentation. But for one reason or the other, it seems like the user session object is not generated...
Read more >
How to implement NextAuth credentials provider with external ...
In this post, we'll learn how to use NextAuth credentials provider with a custom backend and a custom login page.
Read more >
assume-role-with-web-identity gets invalid credentials
I am trying to use OpenID Connect authentication. I created my identity provider and am able to retrieve credentials using `aws sts ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found