Amazon Cognito ユーザーの email_verified 属性に関する問題をトラブルシューティングする方法を教えてください。

所要時間2分
0

Amazon Cognito ユーザーの email_verified 属性に関する問題を解決したいと考えています。

簡単な説明

Amazon Cognito ユーザープールには、個々のユーザーを識別するために使用される一連の標準属性があります。ユーザーの E メールアドレスが確認されたかどうかを示す email_verified 属性は、以下の状況で変化する場合があります。

  • ユーザーが E メールアドレスを更新します。ユーザーが E メールアドレスを更新すると、Amazon Cognito は email_verified 属性を未検証に変更します
  • E メールアドレスはエイリアスとして設定されます。次に、E メールアドレスが重複しているユーザーが作成されます。E メールアドレスがエイリアスとして設定されている場合、email_verified 属性として E メールアドレス値を保持できるのは 1 人のユーザーのみとなります。新規に作成されたユーザーのアカウント確認が成功すると、E メールアドレスのエイリアスが新規に作成されたユーザーに転送されます。その場合、以前のユーザーの E メールアドレスは未検証になります。詳細については、「ユーザープール属性」および「サインイン属性のカスタマイズ」セクションを参照してください。
  • フェデレーションユーザーまたはフェデレーションユーザーにリンクされたユーザーは、E メールマッピングを使用してサインインします。フェデレーションユーザーがサインインする際には、ユーザープールが必要とする各ユーザープール属性にマッピングが存在する必要があります。E メール属性がマッピングされている場合、email_verified 属性はデフォルトで未検証に変更されます

解決方法

email_verified 属性の問題を解決するには、お客様の状況に応じた手順に従ってください。

重要: 次の AWS コマンドラインインターフェイス (AWS CLI) コマンド例では、サンプル文字列のすべてのインスタンスを、ご自分の値に置き換えてください。(例えば、**「example_access_token」**を、ご自分のアクセストークンの値に置き換えてください。)

E メールアドレス更新後の検証

ユーザー更新後に E メールアドレスを検証する:

1.    ユーザープールの E メール検証設定を設定して、Amazon Cognito が更新された E メールアドレスに検証コードを送信するようにします。

2.    必要に応じ、UpdateUserAttributes API または AdminUpdateUserAttributes API を呼び出して、 E メールアドレスを更新してください。

update-user-attributes コマンドの例:

aws cognito-idp update-user-attributes --access-token "example_access_token" --user-attributes Name="email",Value="example_new_email"

admin-update-user-attributes コマンドの例:

aws cognito-idp admin-update-user-attributes --user-pool-id "example_user_pool_id" --username "example_username" --user-attributes Name="email",Value="example_new_email"

重要: AdminUpdateUserAttributes API を使用して email_verified 属性を True に設定することで、E メールアドレスを自動的に検証することもできます。E メールアドレスが AdminUpdateUserAttributes API で自動的に検証される場合は、次の手順は必要ありません。UpdateUserAttributes API を使用するときは、次の手順が必要です。

3.    新しい E メールの受信トレイで検証コードを確認してください。

4.    VerifyUserAttribute API を呼び出します。AccessTokenAttributeName のパラメータを**「E メール」**として指定し、前のステップで取得した検証コードを入力します。

verify-user-attribute コマンドの例:

aws cognito-idp verify-user-attribute --access-token "example_access_token" --attribute-name "email" --code "example_verification_code"

初期コードの有効期限が切れた後に E メールアドレスを検証するには:

1.    アクセストークンを取得するには、ユーザー名でアプリケーションにサインインします。

2.    GetUserAttributeVerificationCode API を呼び出します。AttributeName パラメータを、**「E メール」**に設定します。

get-user-attribute-verification-code コマンドの例:

aws cognito-idp get-user-attribute-verification-code --access-token "example_access_token" --attribute-name "email"

3.    VerifyUserAttribute API を呼び出します。アクセストークンAttributeName のパラメータを、**「E メール」**として指定します。前のステップの検証コードを入力します。

E メールアドレスが重複している新規ユーザーを確認する

E メールアドレスが重複している新規ユーザーを確認できるようにするには:

1.    必要に応じ、SignUp API を呼び出して、設定した E メールアドレスでユーザーを登録します。

sign-up コマンドの例:

aws cognito-idp sign-up --client-id "example_client_id" --username "example_username" --password "example_password" --user-attributes Name="email",Value="example_user_email"

2.    ForceAliasCreation パラメーターを True に設定して、ConfirmSignUp API を呼び出します。

confirm-sign-up コマンドの例:

aws cognito-idp confirm-sign-up --client-id "example_client_id" --username "example_username" --confirmation-code "example_confirmation_code" --force-alias-creation

登録後に E メールアドレスが重複している新規ユーザーの確認を拒否するには:

1.    ForceAliasCreation パラメーターを False に設定して、ConfirmSignUp API を呼び出します。

注: ForceAliasCreation は、デフォルトで False に設定されています。そのため、リクエストのパラメータとして渡される必要はありません。

deny-sign-up コマンドの例:

aws cognito-idp confirm-sign-up --client-id "example_client_id" --username "example_username" --confirmation-code "example_confirmation_code" --no-force-alias-creation

2.    ForceAliasCreation パラメーターを False に設定すると、API は次のエラーを返します。

An error occurred (AliasExistsException) when calling the ConfirmSignUp operation: An account with the email already exists.

重複している E メールアドレスを持つ新規ユーザーを管理者として作成する

重複している E メールアドレスを持つ新規ユーザーを管理者として作成するには:

1.    email_verified 属性を True およびForceAliasCreation パラメータを True に設定して、設定済みの E メールアドレスを使用して AdminCreateUser API を呼び出します。

admin-create-user コマンドの例:

aws cognito-idp admin-create-user --user-pool-id "example_user_pool_id" --username "example_username" --user-attributes Name="email",Value="example_user_email" Name="email_verified",Value="True" --force-alias-creation

email_verified 属性をサードパーティ ID プロバイダー (IdP) にマップする

フェデレーション後も email_verified 属性が検証された状態のままにするには:

1.    Amazon Cognito コンソールから、検証ステータスの IdP 属性を email_verified 属性にマップします

注: ほとんどの OpenID Connect (OIDC) プロバイダーには email_verified 属性が含まれています。


関連情報

E メールアドレスと電話番号の更新を検証する

AWS公式
AWS公式更新しました 1年前
コメントはありません

関連するコンテンツ