Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS-Amplify: Unauthenticated access is not supported for this identity pool

I'm using: https://github.com/aws-amplify/amplify-js

Is there any working example how to use authenticated access to AWS? I'm using this:

Amplify.configure({
        Auth: {
            identityPoolId: configs.broker.identityPoolId,
            region: configs.broker.aws_pubsub_region,
            userPoolId: configs.broker.userPoolId,
            userPoolWebClientId: configs.broker.userPoolWebClientId,
        }
});

Amplify.addPluggable(new AWSIoTProvider(configs.broker));

Auth.signIn(configs.broker.username, configs.broker.password)
    .then(user => {                
        resolve({ code: 200, message: 'Authorized access to AWS is used' })
    })
    .catch(singInErr => resolve({ code: 500, message: singInErr.message }));

And if it is OK (it is ok):

    PubSub.publish(configs.broker.topic, JSON.stringify(data))
         .then(res => resolve({
              code: 200,
              message: 'OK'
         }))
         .catch(err => resolve({
              code: 500,
              message: err.toString()
         }));

But I keep getting:

[Unhandled promise rejection: NotAuthorizedException: Unauthenticated access is not supported for this identity pool.]

like image 481
Anton Smatanik Avatar asked Sep 04 '18 13:09

Anton Smatanik


1 Answers

Did you setup auth with amplify-cli? I had a similar issue with graphql and cognito. Solved it by going to Identity pool settings and setting up Unauthenticated role and Authenticated role. I've just used the ones which where created with amplify cli.

I'm trying to recall this from memory so there might be some parts missing. But rough steps are:

  1. Go to https://eu-west-1.console.aws.amazon.com/cognito/federated
  2. From the top bar select the region you are in.
  3. If you have identity pools you should see a table. Above it there is a link to its settings. Click that.
  4. In the top right corner, below Support there is Edit Identity Pool. Click that.
  5. You should see a screen with two options Unauthenticated roleand Authenticated role. Click the select boxes and select the appropriate roles. If you created amplify stacks it should have two roles which have words unauthdRole and authRole select those.

It should work now. That's assuming that you have right identity pool and user pool setup.

like image 97
T.Chmelevskij Avatar answered Sep 20 '22 11:09

T.Chmelevskij