Ant*_*nik 7 react-native aws-amplify cognito
我正在使用:https : //github.com/aws-amplify/amplify-js
是否有任何工作示例如何使用经过身份验证的 AWS 访问?我正在使用这个:
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 }));
Run Code Online (Sandbox Code Playgroud)
如果没问题(没问题):
PubSub.publish(configs.broker.topic, JSON.stringify(data))
.then(res => resolve({
code: 200,
message: 'OK'
}))
.catch(err => resolve({
code: 500,
message: err.toString()
}));
Run Code Online (Sandbox Code Playgroud)
但我不断得到:
[未处理的承诺拒绝:NotAuthorizedException:此身份池不支持未经身份验证的访问。]
您是否设置了身份验证amplify-cli?我对 graphql 和 cognito 有类似的问题。通过转到身份池设置并设置Unauthenticated role和解决它Authenticated role。我刚刚使用了用 amplify cli 创建的那些。
我试图从记忆中回忆这一点,所以可能缺少某些部分。但粗略的步骤是:
Support是Edit Identity Pool。单击那个。Unauthenticated role和Authenticated role。单击选择框并选择适当的角色。如果您创建了放大堆栈,它应该有两个角色,其中包含单词unauthdRole并authRole选择它们。它现在应该可以工作了。那是假设您有正确的身份池和用户池设置。
| 归档时间: |
|
| 查看次数: |
3457 次 |
| 最近记录: |