【发布时间】:2019-11-23 07:55:43
【问题描述】:
我是 AWS 的新手,我正在寻找一种方法,让我的 Android 应用程序的用户无需经过验证过程即可更改他们的电子邮件(我设法为订阅做到了)。
在我的 Android 应用中:
public void onClickChangeEmail(View view)
{
CognitoUserAttributes attributes = new CognitoUserAttributes();
attributes.getAttributes().put("email", "second@mail.com");
CognitoSettings
.getCognitoUserPool(MainActivity.this)
.getCurrentUser()
.updateAttributesInBackground(attributes, new UpdateAttributesHandler()
{
@Override
public void onSuccess(List<CognitoUserCodeDeliveryDetails> attributesVerificationList)
{
Log.i("tag", "Email updated!");
}
@Override
public void onFailure(Exception e)
{
e.printStackTrace();
}
});
}
然后,在我的 AWS 控制台中,我在 Cognito 中的 自定义消息 上添加了一个触发器,这是我的 lambda 函数,每次用户更新他的电子邮件时都会触发该函数:
const AWS = require('aws-sdk')
AWS.config.update({region: 'eu-central-1'});
exports.handler = (event, context, callback) => {
if (event.triggerSource === 'CustomMessage_UpdateUserAttribute')
{
const params = {
UserAttributes: [
{
Name: 'email_verified',
Value: 'true',
},
],
UserPoolId: event.userPoolId,
Username: event.userName,
};
var cognitoIdServiceProvider = new AWS.CognitoIdentityServiceProvider();
cognitoIdServiceProvider.adminUpdateUserAttributes(params, function(err, data) {
if (err) context.done(err, event); // an error occurred
else context.done(null, event); // successful response
});
}
else
{
context.done(null, event);
}
};
结果是:电子邮件已正确更新(但它在没有 lambda 的情况下工作),但 lambda 崩溃,并出现以下错误:
autoValidationUserEmailModification is not authorized to perform: cognito-idp:AdminUpdateUserAttributes
所以看起来好像缺少授权。
我的问题是:
- 如何修复授权部分?
- 这种方法是在更新用户电子邮件时禁用电子邮件验证的正确方法吗?
感谢您的帮助。
【问题讨论】:
-
autoValidationUserEmailModification是你的函数名吗? -
@hoangdv 是的
-
我刚刚创建了一个答案。
标签: amazon-web-services amazon-cognito