リファレンス
開発者ガイド
API Reference
AWS Tools for PowerShell Cmdlet Reference(User PoolsはAmazon Cognito Identity Providerの項)
Admin Create User
管理者によるユーザー追加はAdmin Create User、ユーザー自身によるユーザー登録はSign-up。ユーザーがサインインできるようになるまでのフローが違う。ユーザーアカウントのサインアップと確認の図がわかりやすい。
AdminCreateUserではCognitoからユーザーへメッセージ(invitation)が送信される。メッセージにはユーザー名とパスワードが含まれる。指定しなかった場合、パスワードは自動で生成される。
$desiredDeliveryMediums = "EMAIL"
$username = "username"
$userAttributes = @(
@{Name="email"; Value="example@example.com"})
# AdminCreateUser
New-CGIPUserAdmin `
-AccessKey $accesskey `
-SecretKey $secretKey `
-Region $region `
`
-UserPoolId $userPoolId `
-ForceAliasCreation $FALSE`
-MessageAction $NULL`
`
-DesiredDeliveryMediums $desiredDeliveryMediums `
-Username $username `
-UserAttributes $userAttributes
最初のサインイン
管理者が追加したユーザーは最初のサインインのときにパスワードの変更が必要。
# AdminInitiateAuth
$res1 =
Start-CGIPAuthAdmin `
-AccessKey $accesskey `
-SecretKey $secretKey `
-Region $region `
`
-UserPoolId $userPoolId `
-ClientId $clientId `
`
-AuthFlow ADMIN_NO_SRP_AUTH `
-AuthParameters @{USERNAME=$username; PASSWORD=$password}
#$res1
$challengeResponses = @{
USERNAME=$userName;
NEW_PASSWORD=$password;
}
# AdminRespondToAuthChallenge
$res2 =
Send-CGIPAuthChallengeResponseAdmin `
-AccessKey $accesskey `
-SecretKey $secretKey `
-Region $region `
`
-UserPoolId $userPoolId `
-ClientId $clientId `
`
-Session $res1.Session `
-ChallengeName NEW_PASSWORD_REQUIRED `
-ChallengeResponses $challengeResponses
$res2
※invitaionでのみユーザーにパスワードを知らせるのであれば、サインイン成功でverification成功とみなしてよいのでは。verificationの成功は属性email_verified
1の値true
で表す。admin APIではverified属性を直接設定できる。
$challengeResponses = @{
USERNAME=$userName;
NEW_PASSWORD=$password;
EMAIL_VERIFIED=$TRUE;
}
確認コードの送信による電話番号、メールアドレスの確認
admin APIではない。ユーザーのAccessTokenで実行する処理。
Get-CGIPUserAttributeVerificationCodeコマンドでCognitoからユーザーに確認コードが送信される。Test-CGIPUserAttributeコマンドが成功の場合、Cognitoによりユーザーの属性email_verified
1がtrue
に設定される。
# AdminInitiateAuth
$res1 =
Start-CGIPAuthAdmin `
-AccessKey $accesskey `
-SecretKey $secretKey `
-Region $region `
`
-UserPoolId $userPoolId `
-ClientId $clientId `
`
-AuthFlow ADMIN_NO_SRP_AUTH `
-AuthParameters @{USERNAME=$username; PASSWORD=$password}
$res1
# GetUserAttributeVerificationCode
Get-CGIPUserAttributeVerificationCode `
-Region $region `
`
-AccessToken $res1.AuthenticationResult.AccessToken `
-AttributeName email
# VerifyUserAttribute
Test-CGIPUserAttribute `
-Region $region `
`
-AccessToken $res1.AuthenticationResult.AccessToken `
-AttributeName email `
-code (Read-Host -Prompt 'Code')
Secret Hash
app clientにclient secretがある場合には必要になる。
$clientId = ""
$appClientSecret = ""
$userName = ""
$hmac = new-object System.Security.Cryptography.HMACSHA256
$hmac.Key = [Text.Encoding]::ASCII.GetBytes($appClientSecret)
$signature = $hmac.ComputeHash([Text.Encoding]::ASCII.GetBytes($userName + $clientId))
$secretHash = [Convert]::ToBase64String($signature)
-
SMSの場合は属性
phone_number_verified
がtrue
に設定される ↩