Getting error "No Cognito Identity pool provided for unauthenticated access"

0

I am getting this error in my web application after login. The user is part of Userpool for the Prod environment. The userpool is already connected to identity pool. Also, unauth roll is assigned in identity pool. Its working all find in dev environment, not able to figure out what is wrong in prod environment.

1 Answer
0

The fact that the User Pool is "connected" to the Identity Pool only means that the Identity Pool will consider trusted any valid Identity Token issued by the User Pool and provided as part of the Auth.currentAuthenticatedUser(); to retrieve AWS credentials.

But this does not allow the client to understand to which Identity pool it has to communicate to with the Identity Token it received from the User Pool. You are missing a configuration and therefore got this error.

You can find an example for Javascript at: https://docs.amplify.aws/lib/auth/advanced/q/platform/js/#subscribing-events

import { Auth } from 'aws-amplify';

// To derive necessary data from the provider
const {
    token, // the token you get from the provider
    domainOrProviderName, // Either the domain of the provider(e.g. accounts.your-openid-provider.com) or the provider name, for now the library only supports 'google', 'facebook', 'amazon', 'developer'
    expiresIn, // the time in ms which describes how long the token could live
    user,  // the user object you defined, e.g. { username, email, phone_number }
    identity_id // Optional, the identity id specified by the provider
} = getFromProvider(); // arbitrary function

Auth.federatedSignIn(
    domain,
    {
        token,
        identity_id, // Optional
        expires_at: expiresIn * 1000 + new Date().getTime() // the expiration timestamp
    },
    user
).then(cred => {
    // If success, you will get the AWS credentials
    console.log(cred);
    return Auth.currentAuthenticatedUser();
}).then(user => {
    // If success, the user object you passed in Auth.federatedSignIn
    console.log(user);
}).catch(e => {
    console.log(e)
});

as you can see identity_id must be set for the client to know with which Identity Pool to communicate.

AWS
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions