web-dev-qa-db-ja.com

AWS Cognito-ユーザーが確認済みで止まり、email_verified = false

確認済みであるがemail_verifiedがfalseであるユーザーを確認するメールを送信するにはどうすればよいですか?

シナリオはおおまかにエージェントがユーザーに代わってユーザーをサインアップすることであり、私はadminConfirmSignUpの管理者呼び出しを通じてユーザーを確認します。その時点では、email_verifiedフラグがfalseであるため、ユーザーはパスワードを変更できません。

ユーザーが確認済みのため、resendConfirmationCodeを呼び出すことができません。

Email_verifiedフラグがfalseであるため、forgotPasswordを呼び出すことができません。

ユーザーアカウントを削除し、signUpを呼び出す(パスワードまたは新しいパスワードの再入力を求める)ことで、アカウントを再作成することが、私が考えることができる最良の方法です。

20
user1432403

現在、Cognitoは、ユーザーに代わって外部エージェントがemail_verifiedおよびphone_verified属性を更新することを許可していません。これらをtrueとしてマークできる唯一の方法は、エンドユーザーが実行できるコード検証プロセスを使用することです。これの例外は、以下の回答で説明されているように、管理者レベルのAPIですが、クライアント側から行うべきではありません。

プロセスは次のとおりです。ユーザーがサインインしてアクセストークンを取得します。次に、確認する属性を指定してGetUserAttrbuteVerificationCode APIを呼び出します。これにより、コードがユーザーに配信されます。このコードは、検証済みとして属性を反転するVerifyUserAttributeを呼び出すことで使用できます。

4
Jeff Bailey

AWS CLIを使用して、email_verified属性を更新できます。

aws cognito-idp admin-update-user-attributes 
--user-pool-id eu-west-xxxxxx 
--username [email protected]
--user-attributes Name=email_verified,Value=true
18
LiorH

あなたは変えられる email_verifiedphone_number_verifiedと他の属性は、ラムダとトリガーなしでadminUpdateUserAttributesを呼び出すことによって:

'use strict'

var AWS = require('aws-sdk')

AWS.config.update({
  accessKeyId: 'YOUR_ACCESS_KEY_HERE',
  secretAccessKey: 'YOUR_SECRET_ACCESS_KEY_HERE',
  region: 'us-east-1' // change region if required
});

var CognitoIdentityServiceProvider = AWS.CognitoIdentityServiceProvider

var client = new CognitoIdentityServiceProvider({
  apiVersion: '2016-04-19',
  region: 'us-east-1' // change region if required
})

client.adminUpdateUserAttributes({
  UserAttributes: [{
      Name: 'phone_number_verified',
      Value: 'true'
    }, {
      Name: 'email_verified',
      Value: 'true'
    }
    // other user attributes like phone_number or email themselves, etc
  ],
  UserPoolId: 'COGNITO_USER_POOL_ID_HERE',
  Username: 'USERNAME'
}, function(err) {
  if (err) {
    console.log(err, err.stack)
  } else {
    console.log('Success!')
  }
})
14
aring

サインアップ前のラムダトリガーを使用してemail_verifiedをプログラムでtrueに設定し、返されたイベントをevent.response.autoVerifyEmail = true;で変更することができます。

それはまだドキュメントにはありませんが、 このgithubの問題で参照されています です。 コグニトラムダトリガーの操作 もご覧ください。

5
iflp

これは、エージェントによってユーザーを作成するために使用できる別のアプローチです。ユーザーの代わりにAdminCreateUserを使用できます。このAPIを呼び出すと、ユーザーは一時的なパスワードで作成され、ユーザーのメールアドレスに送信されます。 (つまり、ユーザーはForce_Change_Password状態になります)。次に、RespondToAuthChallenge APIを使用してパスワードを変更します。

注:属性リストで「email_verified」属性を設定する必要があります。ユーザーのメールアドレスが確認されるようにします。

NodeJSのコード例は次のとおりです。

var params = {
 UserPoolId: process.env.userPoolId, /* required */
Username: email,//'STRING_VALUE', /* required */
DesiredDeliveryMediums: [
"EMAIL",
/* more items */
],
ForceAliasCreation: false,


 UserAttributes: [{
Name: 'email_verified',
Value: 'True'
},/* any other Attributes*/],
   };
cognitoidentityserviceprovider.adminCreateUser(params, function (err, data) {
 if (err) {
  console.log(err, err.stack);
  reject(err); // an error occurred
 }
 else {
  console.log(data);
   resolve(data);
 }// successful response 
});
 });
1
Kashif Ali

事前登録のトリガー このラムダ関数(Node.js v6):

exports.handler = function(event, context) {
 event.response.autoConfirmUser = true;
 event.response.autoVerifyEmail = true;
 event.response.autoVerifyPhone = true;
 context.done(null, event);
};

「Configure test event」を使用すると、最初にこのペイロードでテストできます

{
  "version": 1,
  "triggerSource": "PreSignUp_SignUp",
  "region": "<region>",
  "userPoolId": "<userPoolId>",
  "userName": "<userName>",
  "callerContext": {
      "awsSdk": "<calling aws sdk with version>",
      "clientId": "<apps client id>"
  },
  "request": {
      "userAttributes": {
          "email": "[email protected]"
       },
      "validationData": {
          "k1": "v1",
          "k2": "v2"
       }
  },
  "response": {
        "autoConfirmUser": false,
        "autoVerifyEmail": false,
        "autoVerifyPhone": false
  }
}

APIからユーザーを作成すると、これらの検証フラグはtrueになります。

1
panchicore

pythonでaws cognitoのユーザーのメールを確認する

response = client.get_user_attribute_verification_code(AccessToken = 'eyJraWQiOiJtTEM4Vm ......'、AttributeName = 'email')

応答= client.verify_user_attribute(AccessToken = 'eyJraWQiOiJtTEM ......'、AttributeName = 'email'、Code = '230433')

0
Vinod Kumar