📝

[小ネタ] Cognito ユーザープールで MFA を設定する API は複数ある

に公開

以下の API で MFA を設定できます。

各 API のユースケースについては以下のドキュメントをご参照ください。
Adding MFA to a user pool - Amazon Cognito

CreateUserPool

CreateUserPool - Amazon Cognito User Pools

MfaConfiguration
Sets multi-factor authentication (MFA) to be on, off, or optional. When ON, all users must set up MFA before they can sign in.

ユーザープール作成時に MFA を設定する API が CreateUserPool です。

# 例
$ aws cognito-idp create-user-pool \
--pool-name test \
--mfa-configuration ON \
--auto-verified-attributes phone_number \
--sms-configuration "SnsCallerArn=arn:aws:iam::012345678901:role/service-role/sms-role-name,ExternalId=0123456789"
{

UpdateUserPool

UpdateUserPool - Amazon Cognito User Pools

MfaConfiguration
Sets multi-factor authentication (MFA) to be on, off, or optional. When ON, all users must set up MFA before they can sign in.

ユーザープール更新時に MFA を設定する API が UpdateUserPool です。

# 例
$ aws cognito-idp update-user-pool \
--user-pool-id your-userpool-id \
--mfa-configuration OPTIONAL

SetUserPoolMfaConfig

SetUserPoolMfaConfig - Amazon Cognito User Pools

MfaConfiguration
Sets multi-factor authentication (MFA) to be on, off, or optional. When ON, all users must set up MFA before they can sign in.

Cognito のコンソールから MFA を編集した場合には SetUserPoolMfaConfig が実行されていました。

"requestParameters": {
    "userPoolId": "ap-northeast-1_B3fT42kSb",
    "mfaConfiguration": "OFF"
},
"responseElements": {
    "mfaConfiguration": "OFF"
},

Adding MFA to a user pool - Amazon Cognito

Also in the Multi-factor authentication configuration, the MFA methods setting determines the MFA factors that users can set up. The API equivalent of this setting is the SetUserPoolMfaConfig operation.

SetUserPoolMfaConfig では既存のユーザプールの MFA の設定やユーザーが使用できる MFA 要素を設定するできます。

SetUserMFAPreference

Adding MFA to a user pool - Amazon Cognito

After your user has set an MFA preference, Amazon Cognito prompts them at sign-in to provide a code from their preferred MFA method.

ユーザーが希望する MFA を設定する API が SetUserMFAPreference です。
ユーザー自身で MFA の設定を変更できます。

# 例
$ aws cognito-idp set-user-mfa-preference \
--software-token-mfa-settings Enabled=true,PreferredMfa=false \
--access-token ***

AdminSetUserMFAPreference

Adding MFA to a user pool - Amazon Cognito

In an administrator-managed or confidential application, AdminSetUserPreference, authorized with administrative AWS credentials, sets MFA configuration.

管理者がユーザーの MFA を設定する API が AdminSetUserMFAPreference です。
Cognito コンソールからユーザーの MFA を設定する場合にも AdminSetUserMFAPreference が実行されます。

まとめ

今回は Cognito ユーザープールで MFA を設定する API は複数あるという内容を紹介しました。
どなたかの参考になれば幸いです。

参考資料

Discussion