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 年前2647 查看次数
1 回答
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
已回答 1 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则

相关内容