本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用 Amazon Cognito 身份提供商示例 Amazon CLI
以下代码示例向您展示了如何使用 Amazon Command Line Interface 与 Amazon Cognito 身份提供商配合使用来执行操作和实现常见场景。
操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景和跨服务示例的上下文查看操作。
场景是展示如何通过在同一服务中调用多个函数来完成特定任务任务的代码示例。
每个示例都包含一个指向的链接 GitHub,您可以在其中找到有关如何在上下文中设置和运行代码的说明。
主题
操作
以下代码示例演示如何使用 add-custom-attributes
。
- Amazon CLI
-
添加自定义属性
此示例将自定义属性 CustomAttr 1 添加到用户池。它是 String 类型,最少需要 1 个字符,最多 15 个字符。但其并非必要项目。
命令:
aws cognito-idp add-custom-attributes --user-pool-id us-west-2_aaaaaaaaa --custom-attributes Name="CustomAttr1",AttributeDataType="String",DeveloperOnlyAttribute=false,Required=false,StringAttributeConstraints="{MinLength=1,MaxLength=15}"
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考AddCustomAttributes
中的。
-
以下代码示例演示如何使用 admim-disable-user
。
- Amazon CLI
-
禁用用户
此示例禁用用户 jane@example.com。
命令:
aws cognito-idp admin-disable-user --user-pool-id us-west-2_aaaaaaaaa --username jane@example.com
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考AdmimDisableUser
中的。
-
以下代码示例演示如何使用 admim-enable-user
。
- Amazon CLI
-
启用用户
此示例启用用户名 jane@example.com。
命令:
aws cognito-idp admin-enable-user --user-pool-id us-west-2_aaaaaaaaa --username jane@example.com
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考AdmimEnableUser
中的。
-
以下代码示例演示如何使用 admin-add-user-to-group
。
- Amazon CLI
-
将用户添加到群组
此示例将用户 Jane 添加到群组 MyGroup。
命令:
aws cognito-idp admin-add-user-to-group --user-pool-id us-west-2_aaaaaaaaa --username Jane --group-name MyGroup
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考AdminAddUserToGroup
中的。
-
以下代码示例演示如何使用 admin-confirm-sign-up
。
- Amazon CLI
-
确认用户注册
这个例子证实了用户 jane@example.com。
命令:
aws cognito-idp admin-confirm-sign-up --user-pool-id us-west-2_aaaaaaaaa --username jane@example.com
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考AdminConfirmSignUp
中的。
-
以下代码示例演示如何使用 admin-create-user
。
- Amazon CLI
-
创建用户
以下
admin-create-user
示例使用指定设置的电子邮件地址和电话号码创建用户。aws cognito-idp admin-create-user \ --user-pool-id us-west-2_aaaaaaaaa \ --username diego \ --user-attributes Name=email,Value=diego@example.com Name=phone_number,Value="+15555551212" \ --message-action SUPPRESS
输出:
{ "User": { "Username": "diego", "Attributes": [ { "Name": "sub", "Value": "7325c1de-b05b-4f84-b321-9adc6e61f4a2" }, { "Name": "phone_number", "Value": "+15555551212" }, { "Name": "email", "Value": "diego@example.com" } ], "UserCreateDate": 1548099495.428, "UserLastModifiedDate": 1548099495.428, "Enabled": true, "UserStatus": "FORCE_CHANGE_PASSWORD" } }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考AdminCreateUser
中的。
-
以下代码示例演示如何使用 admin-delete-user-attributes
。
- Amazon CLI
-
删除用户属性
此示例删除了用户 diego@example.com 的自定义属性 CustomAttr 1。
命令:
aws cognito-idp admin-delete-user-attributes --user-pool-id us-west-2_aaaaaaaaa --username diego@example.com --user-attribute-names "custom:CustomAttr1"
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考AdminDeleteUserAttributes
中的。
-
以下代码示例演示如何使用 admin-delete-user
。
- Amazon CLI
-
删除用户
此示例删除一个用户。
命令:
aws cognito-idp admin-delete-user --user-pool-id us-west-2_aaaaaaaaa --username diego@example.com
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考AdminDeleteUser
中的。
-
以下代码示例演示如何使用 admin-forget-device
。
- Amazon CLI
-
忘记设备
这个例子忘记了设备作为用户名 jane@example.com
命令:
aws cognito-idp admin-forget-device --user-pool-id us-west-2_aaaaaaaaa --username jane@example.com --device-key us-west-2_abcd_1234-5678
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考AdminForgetDevice
中的。
-
以下代码示例演示如何使用 admin-get-device
。
- Amazon CLI
-
获取设备
这个例子为用户名获取了一台设备 jane@example.com
命令:
aws cognito-idp admin-get-device --user-pool-id us-west-2_aaaaaaaaa --username jane@example.com --device-key us-west-2_abcd_1234-5678
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考AdminGetDevice
中的。
-
以下代码示例演示如何使用 admin-get-user
。
- Amazon CLI
-
获取用户
此示例获取有关用户名 jane@example.com 的信息。
命令:
aws cognito-idp admin-get-user --user-pool-id us-west-2_aaaaaaaaa --username jane@example.com
输出:
{ "Username": "4320de44-2322-4620-999b-5e2e1c8df013", "Enabled": true, "UserStatus": "FORCE_CHANGE_PASSWORD", "UserCreateDate": 1548108509.537, "UserAttributes": [ { "Name": "sub", "Value": "4320de44-2322-4620-999b-5e2e1c8df013" }, { "Name": "email_verified", "Value": "true" }, { "Name": "phone_number_verified", "Value": "true" }, { "Name": "phone_number", "Value": "+01115551212" }, { "Name": "email", "Value": "jane@example.com" } ], "UserLastModifiedDate": 1548108509.537 }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考AdminGetUser
中的。
-
以下代码示例演示如何使用 admin-initiate-auth
。
- Amazon CLI
-
发起身份验证
此示例使用 ADMIN_NO_SRP_AUTH 流程发起对用户名 jane@example.com 的身份验证
客户端必须启用适用于基于服务器的身份验证(ADMIN_NO_SRP_AUTH)的登录 API。
使用返回值中的会话信息调用 admin-respond-to-auth-challenge。
命令:
aws cognito-idp admin-initiate-auth --user-pool-id us-west-2_aaaaaaaaa --client-id 3n4b5urk1ft4fl3mg5e62d9ado --auth-flow ADMIN_NO_SRP_AUTH --auth-parameters USERNAME=jane@example.com,PASSWORD=password
输出:
{ "ChallengeName": "NEW_PASSWORD_REQUIRED", "Session": "SESSION", "ChallengeParameters": { "USER_ID_FOR_SRP": "84514837-dcbc-4af1-abff-f3c109334894", "requiredAttributes": "[]", "userAttributes": "{\"email_verified\":\"true\",\"phone_number_verified\":\"true\",\"phone_number\":\"+01xxx5550100\",\"email\":\"jane@example.com\"}" } }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考AdminInitiateAuth
中的。
-
以下代码示例演示如何使用 admin-list-devices
。
- Amazon CLI
-
为用户列出设备
此示例列出了用户名为 jane@example.com 的设备。
命令:
aws cognito-idp admin-list-devices --user-pool-id us-west-2_aaaaaaaaa --username jane@example.com
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考AdminListDevices
中的。
-
以下代码示例演示如何使用 admin-list-groups-for-user
。
- Amazon CLI
-
列出用户的群组
此示例列出了用户名为 jane@example.com 的群组。
命令:
aws cognito-idp admin-list-groups-for-user --user-pool-id us-west-2_aaaaaaaaa --username diego@example.com
输出:
{ "Groups": [ { "Description": "Sample group", "Precedence": 1, "LastModifiedDate": 1548097827.125, "RoleArn": "arn:aws:iam::111111111111:role/SampleRole", "GroupName": "SampleGroup", "UserPoolId": "us-west-2_aaaaaaaaa", "CreationDate": 1548097827.125 } ] }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考AdminListGroupsForUser
中的。
-
以下代码示例演示如何使用 admin-list-user-auth-events
。
- Amazon CLI
-
列出用户的授权事件
此示例列出了用户名 diego@example.com 的授权事件。
命令:
aws cognito-idp admin-list-user-auth-events --user-pool-id us-west-2_aaaaaaaaa --username diego@example.com
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考AdminListUserAuthEvents
中的。
-
以下代码示例演示如何使用 admin-remove-user-from-group
。
- Amazon CLI
-
从群组中移除用户
此示例将 jane@example.com 从中删除 SampleGroup。
命令:
aws cognito-idp admin-remove-user-from-group --user-pool-id us-west-2_aaaaaaaaa --username jane@example.com --group-name SampleGroup
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考AdminRemoveUserFromGroup
中的。
-
以下代码示例演示如何使用 admin-reset-user-password
。
- Amazon CLI
-
重置用户密码
此示例重置了 diego@example.com 的密码。
命令:
aws cognito-idp admin-reset-user-password --user-pool-id us-west-2_aaaaaaaaa --username diego@example.com
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考AdminResetUserPassword
中的。
-
以下代码示例演示如何使用 admin-set-user-mfa-preference
。
- Amazon CLI
-
设置用户 MFA 首选项
此示例将 SMS MFA 首选项设置为用户名 diego@example.com。
命令:
aws cognito-idp admin-set-user-mfa-preference --user-pool-id us-west-2_aaaaaaaaa --username diego@example.com --sms-mfa-settings Enabled=false,PreferredMfa=false
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考AdminSetUserMfaPreference
中的。
-
以下代码示例演示如何使用 admin-set-user-settings
。
- Amazon CLI
-
设置用户设置
此示例将用户名 diego@example.com 的 MFA 配送首选项设置为 EMAIL。
命令:
aws cognito-idp admin-set-user-settings --user-pool-id us-west-2_aaaaaaaaa --username diego@example.com --mfa-options DeliveryMedium=EMAIL
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考AdminSetUserSettings
中的。
-
以下代码示例演示如何使用 admin-update-auth-event-feedback
。
- Amazon CLI
-
为授权事件提供反馈
此示例将由 event-id 标识的授权事件的反馈值设置为 “有效”。
命令:
aws cognito-idp admin-update-auth-event-feedback --user-pool-id us-west-2_aaaaaaaaa --username diego@example.com --event-id c2c2cf89-c0d3-482d-aba6-99d78a5b0bfe --feedback-value Valid
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考AdminUpdateAuthEventFeedback
中的。
-
以下代码示例演示如何使用 admin-update-device-status
。
- Amazon CLI
-
更新设备状态
此示例将由 device-key 标识的设备的设备记忆状态设置为 not_remembered。
命令:
aws cognito-idp admin-update-device-status --user-pool-id us-west-2_aaaaaaaaa --username diego@example.com --device-key xxxx --device-remembered-status not_remembered
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考AdminUpdateDeviceStatus
中的。
-
以下代码示例演示如何使用 admin-update-user-attributes
。
- Amazon CLI
-
更新用户属性
此示例更新了用户 diego@example.com 的自定义用户属性 CustomAttr 1。
命令:
aws cognito-idp admin-update-user-attributes --user-pool-id us-west-2_aaaaaaaaa --username diego@example.com --user-attributes Name="custom:CustomAttr1",Value="Purple"
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考AdminUpdateUserAttributes
中的。
-
以下代码示例演示如何使用 change-password
。
- Amazon CLI
-
更改密码
此示例更改了密码。
命令:
aws cognito-idp change-password --previous-password OldPassword --proposed-password NewPassword --access-token ACCESS_TOKEN
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考ChangePassword
中的。
-
以下代码示例演示如何使用 confirm-forgot-password
。
- Amazon CLI
-
确认忘记的密码
此示例确认忘记了用户名 diego@example.com 的密码。
命令:
aws cognito-idp confirm-forgot-password --client-id 3n4b5urk1ft4fl3mg5e62d9ado --username=diego@example.com --password PASSWORD --confirmation-code CONF_CODE
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考ConfirmForgotPassword
中的。
-
以下代码示例演示如何使用 confirm-sign-up
。
- Amazon CLI
-
确认注册
此示例确认用户名 diego@example.com 的注册。
命令:
aws cognito-idp confirm-sign-up --client-id 3n4b5urk1ft4fl3mg5e62d9ado --username=diego@example.com --confirmation-code CONF_CODE
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考ConfirmSignUp
中的。
-
以下代码示例演示如何使用 create-group
。
- Amazon CLI
-
创建群组
此示例创建了一个带有描述的群组。
命令:
aws cognito-idp create-group --user-pool-id us-west-2_aaaaaaaaa --group-name MyNewGroup --description "New group."
输出:
{ "Group": { "GroupName": "MyNewGroup", "UserPoolId": "us-west-2_aaaaaaaaa", "Description": "New group.", "LastModifiedDate": 1548270073.795, "CreationDate": 1548270073.795 } }
创建具有角色和优先级的群组
此示例创建了一个带有描述的群组。它还包括角色和优先级。
命令:
aws cognito-idp create-group --user-pool-id us-west-2_aaaaaaaaa --group-name MyNewGroupWithRole --description "New group with a role." --role-arn arn:aws:iam::111111111111:role/MyNewGroupRole --precedence 2
输出:
{ "Group": { "GroupName": "MyNewGroupWithRole", "UserPoolId": "us-west-2_aaaaaaaaa", "Description": "New group with a role.", "RoleArn": "arn:aws:iam::111111111111:role/MyNewGroupRole", "Precedence": 2, "LastModifiedDate": 1548270211.761, "CreationDate": 1548270211.761 } }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateGroup
中的。
-
以下代码示例演示如何使用 create-user-import-job
。
- Amazon CLI
-
创建用户导入任务
此示例创建了一个名为的用户导入作业 MyImportJob。
有关导入用户的更多信息,请参阅从 CSV 文件将用户导入用户池。
命令:
aws cognito-idp create-user-import-job --user-pool-id us-west-2_aaaaaaaaa --job-name MyImportJob --cloud-watch-logs-role-arn arn:aws:iam::111111111111:role/CognitoCloudWatchLogsRole
输出:
{ "UserImportJob": { "JobName": "MyImportJob", "JobId": "import-qQ0DCt2fRh", "UserPoolId": "us-west-2_aaaaaaaaa", "PreSignedUrl": "PRE_SIGNED_URL", "CreationDate": 1548271795.471, "Status": "Created", "CloudWatchLogsRoleArn": "arn:aws:iam::111111111111:role/CognitoCloudWatchLogsRole", "ImportedUsers": 0, "SkippedUsers": 0, "FailedUsers": 0 } }
使用预签名 URL 上传带有 curl 的.csv 文件:
命令:
curl -v -T "PATH_TO_CSV_FILE" -H "x-amz-server-side-encryption:aws:kms" "PRE_SIGNED_URL"
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateUserImportJob
中的。
-
以下代码示例演示如何使用 create-user-pool-client
。
- Amazon CLI
-
创建用户池客户端
此示例创建了一个具有两个显式授权流程的新用户池客户端:USER_PASSWORD_AUTH 和 ADMIN_NO_SRP_AUTH。
命令:
aws cognito-idp create-user-pool-client --user-pool-id us-west-2_aaaaaaaaa --client-name MyNewClient --no-generate-secret --explicit-auth-flows "USER_PASSWORD_AUTH" "ADMIN_NO_SRP_AUTH"
输出:
{ "UserPoolClient": { "UserPoolId": "us-west-2_aaaaaaaaa", "ClientName": "MyNewClient", "ClientId": "6p3bs000no6a4ue1idruvd05ad", "LastModifiedDate": 1548697449.497, "CreationDate": 1548697449.497, "RefreshTokenValidity": 30, "ExplicitAuthFlows": [ "USER_PASSWORD_AUTH", "ADMIN_NO_SRP_AUTH" ], "AllowedOAuthFlowsUserPoolClient": false } }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateUserPoolClient
中的。
-
以下代码示例演示如何使用 create-user-pool-domain
。
- Amazon CLI
-
创建用户池域
此示例使用两个明确的授权流程创建了一个新的用户池域:USER_PASSWORD_AUTH 和 ADMIN_NO_SRP_AUTH。
命令:
aws cognito-idp create-user-pool-domain --user-pool-id us-west-2_aaaaaaaaa --domain my-new-domain
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateUserPoolDomain
中的。
-
以下代码示例演示如何使用 create-user-pool
。
- Amazon CLI
-
创建最低配置的用户池
此示例创建了一个 MyUserPool 使用默认值命名的用户池。没有必要的属性,也没有应用程序客户端。MFA 和高级安全功能已禁用。
命令:
aws cognito-idp create-user-pool --pool-name MyUserPool
输出:
{ "UserPool": { "SchemaAttributes": [ { "Name": "sub", "StringAttributeConstraints": { "MinLength": "1", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": true, "AttributeDataType": "String", "Mutable": false }, { "Name": "name", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "given_name", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "family_name", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "middle_name", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "nickname", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "preferred_username", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "profile", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "picture", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "website", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "email", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "AttributeDataType": "Boolean", "DeveloperOnlyAttribute": false, "Required": false, "Name": "email_verified", "Mutable": true }, { "Name": "gender", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "birthdate", "StringAttributeConstraints": { "MinLength": "10", "MaxLength": "10" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "zoneinfo", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "locale", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "phone_number", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "AttributeDataType": "Boolean", "DeveloperOnlyAttribute": false, "Required": false, "Name": "phone_number_verified", "Mutable": true }, { "Name": "address", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "updated_at", "NumberAttributeConstraints": { "MinValue": "0" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "Number", "Mutable": true } ], "MfaConfiguration": "OFF", "Name": "MyUserPool", "LastModifiedDate": 1547833345.777, "AdminCreateUserConfig": { "UnusedAccountValidityDays": 7, "AllowAdminCreateUserOnly": false }, "EmailConfiguration": {}, "Policies": { "PasswordPolicy": { "RequireLowercase": true, "RequireSymbols": true, "RequireNumbers": true, "MinimumLength": 8, "RequireUppercase": true } }, "CreationDate": 1547833345.777, "EstimatedNumberOfUsers": 0, "Id": "us-west-2_aaaaaaaaa", "LambdaConfig": {} } }
创建具有两个必要属性的用户池
此示例创建了一个用户池 MyUserPool。该池配置为接受电子邮件作为用户名属性。它还使用 Amazon Simple Email Service 将电子邮件源地址设置为经过验证的地址。
命令:
aws cognito-idp create-user-pool --pool-name MyUserPool --username-attributes "email" --email-configuration=SourceArn="arn:aws:ses:us-east-1:111111111111:identity/jane@example.com",ReplyToEmailAddress="jane@example.com"
输出:
{ "UserPool": { "SchemaAttributes": [ { "Name": "sub", "StringAttributeConstraints": { "MinLength": "1", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": true, "AttributeDataType": "String", "Mutable": false }, { "Name": "name", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "given_name", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "family_name", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "middle_name", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "nickname", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "preferred_username", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "profile", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "picture", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "website", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "email", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "AttributeDataType": "Boolean", "DeveloperOnlyAttribute": false, "Required": false, "Name": "email_verified", "Mutable": true }, { "Name": "gender", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "birthdate", "StringAttributeConstraints": { "MinLength": "10", "MaxLength": "10" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "zoneinfo", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "locale", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "phone_number", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "AttributeDataType": "Boolean", "DeveloperOnlyAttribute": false, "Required": false, "Name": "phone_number_verified", "Mutable": true }, { "Name": "address", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "updated_at", "NumberAttributeConstraints": { "MinValue": "0" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "Number", "Mutable": true } ], "MfaConfiguration": "OFF", "Name": "MyUserPool", "LastModifiedDate": 1547837788.189, "AdminCreateUserConfig": { "UnusedAccountValidityDays": 7, "AllowAdminCreateUserOnly": false }, "EmailConfiguration": { "ReplyToEmailAddress": "jane@example.com", "SourceArn": "arn:aws:ses:us-east-1:111111111111:identity/jane@example.com" }, "Policies": { "PasswordPolicy": { "RequireLowercase": true, "RequireSymbols": true, "RequireNumbers": true, "MinimumLength": 8, "RequireUppercase": true } }, "UsernameAttributes": [ "email" ], "CreationDate": 1547837788.189, "EstimatedNumberOfUsers": 0, "Id": "us-west-2_aaaaaaaaa", "LambdaConfig": {} } }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateUserPool
中的。
-
以下代码示例演示如何使用 delete-group
。
- Amazon CLI
-
删除群组
此示例删除群组。
命令:
aws cognito-idp delete-group --user-pool-id us-west-2_aaaaaaaaa --group-name MyGroupName
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteGroup
中的。
-
以下代码示例演示如何使用 delete-identity-provider
。
- Amazon CLI
-
删除身份提供商
此示例删除了身份提供商。
命令:
aws cognito-idp delete-identity-provider --user-pool-id us-west-2_aaaaaaaaa --provider-name Facebook
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteIdentityProvider
中的。
-
以下代码示例演示如何使用 delete-resource-server
。
- Amazon CLI
-
删除资源服务器
此示例删除了一个名为 weather.example.com 的资源服务器。
命令:
aws cognito-idp delete-resource-server --user-pool-id us-west-2_aaaaaaaaa --identifier weather.example.com
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteResourceServer
中的。
-
以下代码示例演示如何使用 delete-user-attributes
。
- Amazon CLI
-
删除用户属性
此示例删除了用户属性 “FAVORITE_ANIMAL”。
命令:
aws cognito-idp delete-user-attributes --access-token ACCESS_TOKEN --user-attribute-names "FAVORITE_ANIMAL"
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteUserAttributes
中的。
-
以下代码示例演示如何使用 delete-user-pool-client
。
- Amazon CLI
-
删除用户池客户端
此示例删除用户池客户端。
命令:
aws cognito-idp delete-user-pool-client --user-pool-id us-west-2_aaaaaaaaa --client-id 38fjsnc484p94kpqsnet7mpld0
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteUserPoolClient
中的。
-
以下代码示例演示如何使用 delete-user-pool-domain
。
- Amazon CLI
-
删除用户池域
以下
delete-user-pool-domain
示例删除名为的用户池域my-domain
aws cognito-idp delete-user-pool-domain \ --user-pool-id us-west-2_aaaaaaaaa \ --domain my-domain
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteUserPoolDomain
中的。
-
以下代码示例演示如何使用 delete-user-pool
。
- Amazon CLI
-
删除用户池
此示例使用用户池 ID us-west-2_aaaaaaaaa 删除用户池。
命令:
aws cognito-idp delete-user-pool --user-pool-id us-west-2_aaaaaaaaa
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteUserPool
中的。
-
以下代码示例演示如何使用 delete-user
。
- Amazon CLI
-
删除用户
此示例删除一个用户。
命令:
aws cognito-idp delete-user --access-token ACCESS_TOKEN
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteUser
中的。
-
以下代码示例演示如何使用 describe-identity-provider
。
- Amazon CLI
-
描述身份提供者
此示例描述了一个名为 Facebook 的身份提供商。
命令:
aws cognito-idp describe-identity-provider --user-pool-id us-west-2_aaaaaaaaa --provider-name Facebook
输出:
{ "IdentityProvider": { "UserPoolId": "us-west-2_aaaaaaaaa", "ProviderName": "Facebook", "ProviderType": "Facebook", "ProviderDetails": { "attributes_url": "https://graph.facebook.com/me?fields=", "attributes_url_add_attributes": "true", "authorize_scopes": myscope", "authorize_url": "https://www.facebook.com/v2.9/dialog/oauth", "client_id": "11111", "client_secret": "11111", "token_request_method": "GET", "token_url": "https://graph.facebook.com/v2.9/oauth/access_token" }, "AttributeMapping": { "username": "id" }, "IdpIdentifiers": [], "LastModifiedDate": 1548105901.736, "CreationDate": 1548105901.736 } }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DescribeIdentityProvider
中的。
-
以下代码示例演示如何使用 describe-resource-server
。
- Amazon CLI
-
描述资源服务器
此示例描述了资源服务器 weather.example.com。
命令:
aws cognito-idp describe-resource-server --user-pool-id us-west-2_aaaaaaaaa --identifier weather.example.com
输出:
{ "ResourceServer": { "UserPoolId": "us-west-2_aaaaaaaaa", "Identifier": "weather.example.com", "Name": "Weather", "Scopes": [ { "ScopeName": "weather.update", "ScopeDescription": "Update weather forecast" }, { "ScopeName": "weather.read", "ScopeDescription": "Read weather forecasts" }, { "ScopeName": "weather.delete", "ScopeDescription": "Delete a weather forecast" } ] } }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DescribeResourceServer
中的。
-
以下代码示例演示如何使用 describe-risk-configuration
。
- Amazon CLI
-
描述风险配置
此示例描述了与池 us-west-2_aaaaaaaaa 相关的风险配置。
命令:
aws cognito-idp describe-risk-configuration --user-pool-id us-west-2_aaaaaaaaa
输出:
{ "RiskConfiguration": { "UserPoolId": "us-west-2_aaaaaaaaa", "CompromisedCredentialsRiskConfiguration": { "EventFilter": [ "SIGN_IN", "SIGN_UP", "PASSWORD_CHANGE" ], "Actions": { "EventAction": "BLOCK" } }, "AccountTakeoverRiskConfiguration": { "NotifyConfiguration": { "From": "diego@example.com", "ReplyTo": "diego@example.com", "SourceArn": "arn:aws:ses:us-east-1:111111111111:identity/diego@example.com", "BlockEmail": { "Subject": "Blocked sign-in attempt", "HtmlBody": "<!DOCTYPE html>\n<html>\n<head>\n\t<title>HTML email context</title>\n\t<meta charset=\"utf-8\">\n</head>\n<body>\n<pre>We blocked an unrecognized sign-in to your account with this information:\n<ul>\n<li>Time: {login-time}</li>\n<li>Device: {device-name}</li>\n<li>Location: {city}, {country}</li>\n</ul>\nIf this sign-in was not by you, you should change your password and notify us by clicking on <a href={one-click-link-invalid}>this link</a>\nIf this sign-in was by you, you can follow <a href={one-click-link-valid}>this link</a> to let us know</pre>\n</body>\n</html>", "TextBody": "We blocked an unrecognized sign-in to your account with this information:\nTime: {login-time}\nDevice: {device-name}\nLocation: {city}, {country}\nIf this sign-in was not by you, you should change your password and notify us by clicking on {one-click-link-invalid}\nIf this sign-in was by you, you can follow {one-click-link-valid} to let us know" }, "NoActionEmail": { "Subject": "New sign-in attempt", "HtmlBody": "<!DOCTYPE html>\n<html>\n<head>\n\t<title>HTML email context</title>\n\t<meta charset=\"utf-8\">\n</head>\n<body>\n<pre>We observed an unrecognized sign-in to your account with this information:\n<ul>\n<li>Time: {login-time}</li>\n<li>Device: {device-name}</li>\n<li>Location: {city}, {country}</li>\n</ul>\nIf this sign-in was not by you, you should change your password and notify us by clicking on <a href={one-click-link-invalid}>this link</a>\nIf this sign-in was by you, you can follow <a href={one-click-link-valid}>this link</a> to let us know</pre>\n</body>\n</html>", "TextBody": "We observed an unrecognized sign-in to your account with this information:\nTime: {login-time}\nDevice: {device-name}\nLocation: {city}, {country}\nIf this sign-in was not by you, you should change your password and notify us by clicking on {one-click-link-invalid}\nIf this sign-in was by you, you can follow {one-click-link-valid} to let us know" }, "MfaEmail": { "Subject": "New sign-in attempt", "HtmlBody": "<!DOCTYPE html>\n<html>\n<head>\n\t<title>HTML email context</title>\n\t<meta charset=\"utf-8\">\n</head>\n<body>\n<pre>We required you to use multi-factor authentication for the following sign-in attempt:\n<ul>\n<li>Time: {login-time}</li>\n<li>Device: {device-name}</li>\n<li>Location: {city}, {country}</li>\n</ul>\nIf this sign-in was not by you, you should change your password and notify us by clicking on <a href={one-click-link-invalid}>this link</a>\nIf this sign-in was by you, you can follow <a href={one-click-link-valid}>this link</a> to let us know</pre>\n</body>\n</html>", "TextBody": "We required you to use multi-factor authentication for the following sign-in attempt:\nTime: {login-time}\nDevice: {device-name}\nLocation: {city}, {country}\nIf this sign-in was not by you, you should change your password and notify us by clicking on {one-click-link-invalid}\nIf this sign-in was by you, you can follow {one-click-link-valid} to let us know" } }, "Actions": { "LowAction": { "Notify": true, "EventAction": "NO_ACTION" }, "MediumAction": { "Notify": true, "EventAction": "MFA_IF_CONFIGURED" }, "HighAction": { "Notify": true, "EventAction": "MFA_IF_CONFIGURED" } } } } }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DescribeRiskConfiguration
中的。
-
以下代码示例演示如何使用 describe-user-import-job
。
- Amazon CLI
-
描述用户导入任务
此示例描述了用户输入作业。
有关导入用户的更多信息,请参阅从 CSV 文件将用户导入用户池。
命令:
aws cognito-idp describe-user-import-job --user-pool-id us-west-2_aaaaaaaaa --job-id import-TZqNQvDRnW
输出:
{ "UserImportJob": { "JobName": "import-Test1", "JobId": "import-TZqNQvDRnW", "UserPoolId": "us-west-2_aaaaaaaaa", "PreSignedUrl": "PRE_SIGNED URL", "CreationDate": 1548271708.512, "Status": "Created", "CloudWatchLogsRoleArn": "arn:aws:iam::111111111111:role/CognitoCloudWatchLogsRole", "ImportedUsers": 0, "SkippedUsers": 0, "FailedUsers": 0 } }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DescribeUserImportJob
中的。
-
以下代码示例演示如何使用 describe-user-pool-client
。
- Amazon CLI
-
描述用户池客户端
此示例描述了用户池客户端。
命令:
aws cognito-idp describe-user-pool-client --user-pool-id us-west-2_aaaaaaaaa --client-id 38fjsnc484p94kpqsnet7mpld0
输出:
{ "UserPoolClient": { "UserPoolId": "us-west-2_aaaaaaaaa", "ClientName": "MyApp", "ClientId": "38fjsnc484p94kpqsnet7mpld0", "ClientSecret": "CLIENT_SECRET", "LastModifiedDate": 1548108676.163, "CreationDate": 1548108676.163, "RefreshTokenValidity": 30, "ReadAttributes": [ "address", "birthdate", "custom:CustomAttr1", "custom:CustomAttr2", "email", "email_verified", "family_name", "gender", "given_name", "locale", "middle_name", "name", "nickname", "phone_number", "phone_number_verified", "picture", "preferred_username", "profile", "updated_at", "website", "zoneinfo" ], "WriteAttributes": [ "address", "birthdate", "custom:CustomAttr1", "custom:CustomAttr2", "email", "family_name", "gender", "given_name", "locale", "middle_name", "name", "nickname", "phone_number", "picture", "preferred_username", "profile", "updated_at", "website", "zoneinfo" ], "ExplicitAuthFlows": [ "ADMIN_NO_SRP_AUTH", "USER_PASSWORD_AUTH" ], "AllowedOAuthFlowsUserPoolClient": false } }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DescribeUserPoolClient
中的。
-
以下代码示例演示如何使用 describe-user-pool-domain
。
- Amazon CLI
-
描述用户池客户端
此示例描述了一个名为 my-domain 的用户池域。
命令:
aws cognito-idp describe-user-pool-domain --domain my-domain
输出:
{ "DomainDescription": { "UserPoolId": "us-west-2_aaaaaaaaa", "AWSAccountId": "111111111111", "Domain": "my-domain", "S3Bucket": "aws-cognito-prod-pdx-assets", "CloudFrontDistribution": "aaaaaaaaaaaaa.cloudfront.net", "Version": "20190128175402", "Status": "ACTIVE", "CustomDomainConfig": {} } }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DescribeUserPoolDomain
中的。
-
以下代码示例演示如何使用 describe-user-pool
。
- Amazon CLI
-
描述用户池
此示例描述了用户池 ID 为 us-west-2_aaaaaaaaa 的用户池。
命令:
aws cognito-idp describe-user-pool --user-pool-id us-west-2_aaaaaaaaa
输出:
{ "UserPool": { "SmsVerificationMessage": "Your verification code is {####}. ", "SchemaAttributes": [ { "Name": "sub", "StringAttributeConstraints": { "MinLength": "1", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": true, "AttributeDataType": "String", "Mutable": false }, { "Name": "name", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "given_name", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "family_name", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "middle_name", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "nickname", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "preferred_username", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "profile", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "picture", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "website", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "email", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": true, "AttributeDataType": "String", "Mutable": true }, { "AttributeDataType": "Boolean", "DeveloperOnlyAttribute": false, "Required": false, "Name": "email_verified", "Mutable": true }, { "Name": "gender", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "birthdate", "StringAttributeConstraints": { "MinLength": "10", "MaxLength": "10" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "zoneinfo", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "locale", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "phone_number", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "AttributeDataType": "Boolean", "DeveloperOnlyAttribute": false, "Required": false, "Name": "phone_number_verified", "Mutable": true }, { "Name": "address", "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "String", "Mutable": true }, { "Name": "updated_at", "NumberAttributeConstraints": { "MinValue": "0" }, "DeveloperOnlyAttribute": false, "Required": false, "AttributeDataType": "Number", "Mutable": true } ], "EmailVerificationSubject": "Your verification code", "MfaConfiguration": "OFF", "Name": "MyUserPool", "EmailVerificationMessage": "Your verification code is {####}. ", "SmsAuthenticationMessage": "Your authentication code is {####}. ", "LastModifiedDate": 1547763720.822, "AdminCreateUserConfig": { "InviteMessageTemplate": { "EmailMessage": "Your username is {username} and temporary password is {####}. ", "EmailSubject": "Your temporary password", "SMSMessage": "Your username is {username} and temporary password is {####}. " }, "UnusedAccountValidityDays": 7, "AllowAdminCreateUserOnly": false }, "EmailConfiguration": { "ReplyToEmailAddress": "myemail@mydomain.com" "SourceArn": "arn:aws:ses:us-east-1:000000000000:identity/myemail@mydomain.com" }, "AutoVerifiedAttributes": [ "email" ], "Policies": { "PasswordPolicy": { "RequireLowercase": true, "RequireSymbols": true, "RequireNumbers": true, "MinimumLength": 8, "RequireUppercase": true } }, "UserPoolTags": {}, "UsernameAttributes": [ "email" ], "CreationDate": 1547763720.822, "EstimatedNumberOfUsers": 1, "Id": "us-west-2_aaaaaaaaa", "LambdaConfig": {} } }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DescribeUserPool
中的。
-
以下代码示例演示如何使用 forget-device
。
- Amazon CLI
-
忘记设备
此示例忘记了设备和设备。
命令:
aws cognito-idp forget-device --device-key us-west-2_abcd_1234-5678
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考ForgetDevice
中的。
-
以下代码示例演示如何使用 forgot-password
。
- Amazon CLI
-
强制更改密码
以下
forgot-password
示例向 jane@example.com 发送了一条消息,要求他们更改密码。aws cognito-idp forgot-password --client-id 38fjsnc484p94kpqsnet7mpld0 --username jane@example.com
输出:
{ "CodeDeliveryDetails": { "Destination": "j***@e***.com", "DeliveryMedium": "EMAIL", "AttributeName": "email" } }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考ForgotPassword
中的。
-
以下代码示例演示如何使用 get-csv-header
。
- Amazon CLI
-
创建 csv 标题
此示例创建了一个 csv 标头。
有关导入用户的更多信息,请参阅从 CSV 文件将用户导入用户池。
命令:
aws cognito-idp get-csv-header --user-pool-id us-west-2_aaaaaaaaa
输出:
{ "UserPoolId": "us-west-2_aaaaaaaaa", "CSVHeader": [ "name", "given_name", "family_name", "middle_name", "nickname", "preferred_username", "profile", "picture", "website", "email", "email_verified", "gender", "birthdate", "zoneinfo", "locale", "phone_number", "phone_number_verified", "address", "updated_at", "cognito:mfa_enabled", "cognito:username" ] }
... 从 CSV 文件将用户导入用户池:https://docs.aws.amazon.com/cognito/latest/developerguide/ cognito-user-pools-using-import-tool.html
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetCsvHeader
中的。
-
以下代码示例演示如何使用 get-group
。
- Amazon CLI
-
获取有关群组的信息
此示例获取有关名为的群组的信息 MyGroup。
命令:
aws cognito-idp get-group --user-pool-id us-west-2_aaaaaaaaa --group-name MyGroup
输出:
{ "Group": { "GroupName": "MyGroup", "UserPoolId": "us-west-2_aaaaaaaaa", "Description": "A sample group.", "LastModifiedDate": 1548270073.795, "CreationDate": 1548270073.795 } }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetGroup
中的。
-
以下代码示例演示如何使用 get-signing-certificate
。
- Amazon CLI
-
获取签名证书
此示例获取用户池的签名证书。
命令:
aws cognito-idp get-signing-certificate --user-pool-id us-west-2_aaaaaaaaa
输出:
{ "Certificate": "CERTIFICATE_DATA" }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetSigningCertificate
中的。
-
以下代码示例演示如何使用 get-ui-customization
。
- Amazon CLI
-
获取用户界面自定义信息
此示例获取用户池的用户界面自定义信息。
命令:
aws cognito-idp get-ui-customization --user-pool-id us-west-2_aaaaaaaaa
输出:
{ "UICustomization": { "UserPoolId": "us-west-2_aaaaaaaaa", "ClientId": "ALL", "ImageUrl": "https://aaaaaaaaaaaaa.cloudfront.net/us-west-2_aaaaaaaaa/ALL/20190128231240/assets/images/image.jpg", "CSS": ".logo-customizable {\n\tmax-width: 60%;\n\tmax-height: 30%;\n}\n.banner-customizable {\n\tpadding: 25px 0px 25px 10px;\n\tbackground-color: lightgray;\n}\n.label-customizable {\n\tfont-weight: 300;\n}\n.textDescription-customizable {\n\tpadding-top: 10px;\n\tpadding-bottom: 10px;\n\tdisplay: block;\n\tfont-size: 16px;\n}\n.idpDescription-customizable {\n\tpadding-top: 10px;\n\tpadding-bottom: 10px;\n\tdisplay: block;\n\tfont-size: 16px;\n}\n.legalText-customizable {\n\tcolor: #747474;\n\tfont-size: 11px;\n}\n.submitButton-customizable {\n\tfont-size: 14px;\n\tfont-weight: bold;\n\tmargin: 20px 0px 10px 0px;\n\theight: 40px;\n\twidth: 100%;\n\tcolor: #fff;\n\tbackground-color: #337ab7;\n}\n.submitButton-customizable:hover {\n\tcolor: #fff;\n\tbackground-color: #286090;\n}\n.errorMessage-customizable {\n\tpadding: 5px;\n\tfont-size: 14px;\n\twidth: 100%;\n\tbackground: #F5F5F5;\n\tborder: 2px solid #D64958;\n\tcolor: #D64958;\n}\n.inputField-customizable {\n\twidth: 100%;\n\theight: 34px;\n\tcolor: #555;\n\tbackground-color: #fff;\n\tborder: 1px solid #ccc;\n}\n.inputField-customizable:focus {\n\tborder-color: #66afe9;\n\toutline: 0;\n}\n.idpButton-customizable {\n\theight: 40px;\n\twidth: 100%;\n\ttext-align: center;\n\tmargin-bottom: 15px;\n\tcolor: #fff;\n\tbackground-color: #5bc0de;\n\tborder-color: #46b8da;\n}\n.idpButton-customizable:hover {\n\tcolor: #fff;\n\tbackground-color: #31b0d5;\n}\n.socialButton-customizable {\n\theight: 40px;\n\ttext-align: left;\n\twidth: 100%;\n\tmargin-bottom: 15px;\n}\n.redirect-customizable {\n\ttext-align: center;\n}\n.passwordCheck-notValid-customizable {\n\tcolor: #DF3312;\n}\n.passwordCheck-valid-customizable {\n\tcolor: #19BF00;\n}\n.background-customizable {\n\tbackground-color: #faf;\n}\n", "CSSVersion": "20190128231240" } }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetUiCustomization
中的。
-
以下代码示例演示如何使用 list-user-import-jobs
。
- Amazon CLI
-
列出用户导入任务
此示例列出了用户导入任务。
有关导入用户的更多信息,请参阅从 CSV 文件将用户导入用户池。
命令:
aws cognito-idp list-user-import-jobs --user-pool-id us-west-2_aaaaaaaaa --max-results 20
输出:
{ "UserImportJobs": [ { "JobName": "Test2", "JobId": "import-d0OnwGA3mV", "UserPoolId": "us-west-2_aaaaaaaaa", "PreSignedUrl": "PRE_SIGNED_URL", "CreationDate": 1548272793.069, "Status": "Created", "CloudWatchLogsRoleArn": "arn:aws:iam::111111111111:role/CognitoCloudWatchLogsRole", "ImportedUsers": 0, "SkippedUsers": 0, "FailedUsers": 0 }, { "JobName": "Test1", "JobId": "import-qQ0DCt2fRh", "UserPoolId": "us-west-2_aaaaaaaaa", "PreSignedUrl": "PRE_SIGNED_URL", "CreationDate": 1548271795.471, "Status": "Created", "CloudWatchLogsRoleArn": "arn:aws:iam::111111111111:role/CognitoCloudWatchLogsRole", "ImportedUsers": 0, "SkippedUsers": 0, "FailedUsers": 0 }, { "JobName": "import-Test1", "JobId": "import-TZqNQvDRnW", "UserPoolId": "us-west-2_aaaaaaaaa", "PreSignedUrl": "PRE_SIGNED_URL", "CreationDate": 1548271708.512, "StartDate": 1548277247.962, "CompletionDate": 1548277248.912, "Status": "Failed", "CloudWatchLogsRoleArn": "arn:aws:iam::111111111111:role/CognitoCloudWatchLogsRole", "ImportedUsers": 0, "SkippedUsers": 0, "FailedUsers": 1, "CompletionMessage": "Too many users have failed or been skipped during the import." } ] }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考ListUserImportJobs
中的。
-
以下代码示例演示如何使用 list-user-pools
。
- Amazon CLI
-
列出用户池
此示例最多列出 20 个用户池。
命令:
aws cognito-idp list-user-pools --max-results 20
输出:
{ "UserPools": [ { "CreationDate": 1547763720.822, "LastModifiedDate": 1547763720.822, "LambdaConfig": {}, "Id": "us-west-2_aaaaaaaaa", "Name": "MyUserPool" } ] }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考ListUserPools
中的。
-
以下代码示例演示如何使用 list-users-in-group
。
- Amazon CLI
-
列出群组中的用户
此示例列出了群组中的用户 MyGroup。
命令:
aws cognito-idp list-users-in-group --user-pool-id us-west-2_aaaaaaaaa --group-name MyGroup
输出:
{ "Users": [ { "Username": "acf10624-80bb-401a-ac61-607bee2110ec", "Attributes": [ { "Name": "sub", "Value": "acf10624-80bb-401a-ac61-607bee2110ec" }, { "Name": "custom:CustomAttr1", "Value": "New Value!" }, { "Name": "email", "Value": "jane@example.com" } ], "UserCreateDate": 1548102770.284, "UserLastModifiedDate": 1548103204.893, "Enabled": true, "UserStatus": "CONFIRMED" }, { "Username": "22704aa3-fc10-479a-97eb-2af5806bd327", "Attributes": [ { "Name": "sub", "Value": "22704aa3-fc10-479a-97eb-2af5806bd327" }, { "Name": "email_verified", "Value": "true" }, { "Name": "email", "Value": "diego@example.com" } ], "UserCreateDate": 1548089817.683, "UserLastModifiedDate": 1548089817.683, "Enabled": true, "UserStatus": "FORCE_CHANGE_PASSWORD" } ] }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考ListUsersInGroup
中的。
-
以下代码示例演示如何使用 list-users
。
- Amazon CLI
-
列出用户
此示例最多列出 20 个用户。
命令:
aws cognito-idp list-users --user-pool-id us-west-2_aaaaaaaaa --limit 20
输出:
{ "Users": [ { "Username": "22704aa3-fc10-479a-97eb-2af5806bd327", "Enabled": true, "UserStatus": "FORCE_CHANGE_PASSWORD", "UserCreateDate": 1548089817.683, "UserLastModifiedDate": 1548089817.683, "Attributes": [ { "Name": "sub", "Value": "22704aa3-fc10-479a-97eb-2af5806bd327" }, { "Name": "email_verified", "Value": "true" }, { "Name": "email", "Value": "mary@example.com" } ] } ] }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考ListUsers
中的。
-
以下代码示例演示如何使用 resend-confirmation-code
。
- Amazon CLI
-
重新发送确认码
以下
resend-confirmation-code
示例向用户jane
发送确认码。aws cognito-idp resend-confirmation-code \ --client-id 12a3b456c7de890f11g123hijk \ --username jane
输出:
{ "CodeDeliveryDetails": { "Destination": "j***@e***.com", "DeliveryMedium": "EMAIL", "AttributeName": "email" } }
有关更多信息,请参阅《Amazon Cognito 开发人员指南》中的注册并确认用户账户。
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考ResendConfirmationCode
中的。
-
以下代码示例演示如何使用 respond-to-auth-challenge
。
- Amazon CLI
-
响应身份验证质询
此示例响应使用 initiate-auth 发起的身份验证质询。这是对 NEW_PASSWORD_REQUIRED 质询的响应。它为用户 jane@example.com 设置了密码。
命令:
aws cognito-idp respond-to-auth-challenge --client-id 3n4b5urk1ft4fl3mg5e62d9ado --challenge-name NEW_PASSWORD_REQUIRED --challenge-responses USERNAME=jane@example.com,NEW_PASSWORD="password" --session "SESSION_TOKEN"
输出:
{ "ChallengeParameters": {}, "AuthenticationResult": { "AccessToken": "ACCESS_TOKEN", "ExpiresIn": 3600, "TokenType": "Bearer", "RefreshToken": "REFRESH_TOKEN", "IdToken": "ID_TOKEN", "NewDeviceMetadata": { "DeviceKey": "us-west-2_fec070d2-fa88-424a-8ec8-b26d7198eb23", "DeviceGroupKey": "-wt2ha1Zd" } } }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考RespondToAuthChallenge
中的。
-
以下代码示例演示如何使用 set-risk-configuration
。
- Amazon CLI
-
设置风险配置
此示例为用户池设置风险配置。它将注册事件操作设置为 NO_ACTION。
命令:
aws cognito-idp set-risk-configuration --user-pool-id us-west-2_aaaaaaaaa --compromised-credentials-risk-configuration EventFilter=SIGN_UP,Actions={EventAction=NO_ACTION}
输出:
{ "RiskConfiguration": { "UserPoolId": "us-west-2_aaaaaaaaa", "CompromisedCredentialsRiskConfiguration": { "EventFilter": [ "SIGN_UP" ], "Actions": { "EventAction": "NO_ACTION" } } } }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考SetRiskConfiguration
中的。
-
以下代码示例演示如何使用 set-ui-customization
。
- Amazon CLI
-
设置用户界面自定义
此示例自定义用户池的 CSS 设置。
命令:
aws cognito-idp set-ui-customization --user-pool-id us-west-2_aaaaaaaaa --css ".logo-customizable {\n\tmax-width: 60%;\n\tmax-height: 30%;\n}\n.banner-customizable {\n\tpadding: 25px 0px 25px 10px;\n\tbackground-color: lightgray;\n}\n.label-customizable {\n\tfont-weight: 300;\n}\n.textDescription-customizable {\n\tpadding-top: 10px;\n\tpadding-bottom: 10px;\n\tdisplay: block;\n\tfont-size: 16px;\n}\n.idpDescription-customizable {\n\tpadding-top: 10px;\n\tpadding-bottom: 10px;\n\tdisplay: block;\n\tfont-size: 16px;\n}\n.legalText-customizable {\n\tcolor: #747474;\n\tfont-size: 11px;\n}\n.submitButton-customizable {\n\tfont-size: 14px;\n\tfont-weight: bold;\n\tmargin: 20px 0px 10px 0px;\n\theight: 40px;\n\twidth: 100%;\n\tcolor: #fff;\n\tbackground-color: #337ab7;\n}\n.submitButton-customizable:hover {\n\tcolor: #fff;\n\tbackground-color: #286090;\n}\n.errorMessage-customizable {\n\tpadding: 5px;\n\tfont-size: 14px;\n\twidth: 100%;\n\tbackground: #F5F5F5;\n\tborder: 2px solid #D64958;\n\tcolor: #D64958;\n}\n.inputField-customizable {\n\twidth: 100%;\n\theight: 34px;\n\tcolor: #555;\n\tbackground-color: #fff;\n\tborder: 1px solid #ccc;\n}\n.inputField-customizable:focus {\n\tborder-color: #66afe9;\n\toutline: 0;\n}\n.idpButton-customizable {\n\theight: 40px;\n\twidth: 100%;\n\ttext-align: center;\n\tmargin-bottom: 15px;\n\tcolor: #fff;\n\tbackground-color: #5bc0de;\n\tborder-color: #46b8da;\n}\n.idpButton-customizable:hover {\n\tcolor: #fff;\n\tbackground-color: #31b0d5;\n}\n.socialButton-customizable {\n\theight: 40px;\n\ttext-align: left;\n\twidth: 100%;\n\tmargin-bottom: 15px;\n}\n.redirect-customizable {\n\ttext-align: center;\n}\n.passwordCheck-notValid-customizable {\n\tcolor: #DF3312;\n}\n.passwordCheck-valid-customizable {\n\tcolor: #19BF00;\n}\n.background-customizable {\n\tbackground-color: #faf;\n}\n"
输出:
{ "UICustomization": { "UserPoolId": "us-west-2_aaaaaaaaa", "ClientId": "ALL", "CSS": ".logo-customizable {\n\tmax-width: 60%;\n\tmax-height: 30%;\n}\n.banner-customizable {\n\tpadding: 25px 0px 25px 10px;\n\tbackground-color: lightgray;\n}\n.label-customizable {\n\tfont-weight: 300;\n}\n.textDescription-customizable {\n\tpadding-top: 10px;\n\tpadding-bottom: 10px;\n\tdisplay: block;\n\tfont-size: 16px;\n}\n.idpDescription-customizable {\n\tpadding-top: 10px;\n\tpadding-bottom: 10px;\n\tdisplay: block;\n\tfont-size: 16px;\n}\n.legalText-customizable {\n\tcolor: #747474;\n\tfont-size: 11px;\n}\n.submitButton-customizable {\n\tfont-size: 14px;\n\tfont-weight: bold;\n\tmargin: 20px 0px 10px 0px;\n\theight: 40px;\n\twidth: 100%;\n\tcolor: #fff;\n\tbackground-color: #337ab7;\n}\n.submitButton-customizable:hover {\n\tcolor: #fff;\n\tbackground-color: #286090;\n}\n.errorMessage-customizable {\n\tpadding: 5px;\n\tfont-size: 14px;\n\twidth: 100%;\n\tbackground: #F5F5F5;\n\tborder: 2px solid #D64958;\n\tcolor: #D64958;\n}\n.inputField-customizable {\n\twidth: 100%;\n\theight: 34px;\n\tcolor: #555;\n\tbackground-color: #fff;\n\tborder: 1px solid #ccc;\n}\n.inputField-customizable:focus {\n\tborder-color: #66afe9;\n\toutline: 0;\n}\n.idpButton-customizable {\n\theight: 40px;\n\twidth: 100%;\n\ttext-align: center;\n\tmargin-bottom: 15px;\n\tcolor: #fff;\n\tbackground-color: #5bc0de;\n\tborder-color: #46b8da;\n}\n.idpButton-customizable:hover {\n\tcolor: #fff;\n\tbackground-color: #31b0d5;\n}\n.socialButton-customizable {\n\theight: 40px;\n\ttext-align: left;\n\twidth: 100%;\n\tmargin-bottom: 15px;\n}\n.redirect-customizable {\n\ttext-align: center;\n}\n.passwordCheck-notValid-customizable {\n\tcolor: #DF3312;\n}\n.passwordCheck-valid-customizable {\n\tcolor: #19BF00;\n}\n.background-customizable {\n\tbackground-color: #faf;\n}\n", "CSSVersion": "20190129172214" } }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考SetUiCustomization
中的。
-
以下代码示例演示如何使用 set-user-mfa-preference
。
- Amazon CLI
-
设置用户 MFA 设置
以下
set-user-mfa-preference
示例修改了 MFA 交付选项。它将 MFA 传送媒体更改为短信。aws cognito-idp set-user-mfa-preference \ --access-token "eyJra12345EXAMPLE" \ --software-token-mfa-settings Enabled=true,PreferredMfa=true \ --sms-mfa-settings Enabled=false,PreferredMfa=false
此命令不生成任何输出。
有关更多信息,请参阅 A mazon Cognito 开发者指南中的向用户池添加 MFA。
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考SetUserMfaPreference
中的。
-
以下代码示例演示如何使用 set-user-settings
。
- Amazon CLI
-
设置用户设置
此示例将 MFA 交付首选项设置为电子邮件。
命令:
aws cognito-idp set-user-settings --access-token ACCESS_TOKEN --mfa-options DeliveryMedium=EMAIL
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考SetUserSettings
中的。
-
以下代码示例演示如何使用 sign-up
。
- Amazon CLI
-
注册用户
此示例注册 jane@example.com。
命令:
aws cognito-idp sign-up --client-id 3n4b5urk1ft4fl3mg5e62d9ado --username jane@example.com --password PASSWORD --user-attributes Name="email",Value="jane@example.com" Name="name",Value="Jane"
输出:
{ "UserConfirmed": false, "UserSub": "e04d60a6-45dc-441c-a40b-e25a787d4862" }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考SignUp
中的。
-
以下代码示例演示如何使用 start-user-import-job
。
- Amazon CLI
-
启动用户导入任务
此示例启动用户输入作业。
有关导入用户的更多信息,请参阅从 CSV 文件将用户导入用户池。
命令:
aws cognito-idp start-user-import-job --user-pool-id us-west-2_aaaaaaaaa --job-id import-TZqNQvDRnW
输出:
{ "UserImportJob": { "JobName": "import-Test10", "JobId": "import-lmpxSOuIzH", "UserPoolId": "us-west-2_aaaaaaaaa", "PreSignedUrl": "PRE_SIGNED_URL", "CreationDate": 1548278378.928, "StartDate": 1548278397.334, "Status": "Pending", "CloudWatchLogsRoleArn": "arn:aws:iam::111111111111:role/CognitoCloudWatchLogsRole", "ImportedUsers": 0, "SkippedUsers": 0, "FailedUsers": 0 } }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考StartUserImportJob
中的。
-
以下代码示例演示如何使用 stop-user-import-job
。
- Amazon CLI
-
停止用户导入任务
此示例停止用户输入作业。
有关导入用户的更多信息,请参阅从 CSV 文件将用户导入用户池。
命令:
aws cognito-idp stop-user-import-job --user-pool-id us-west-2_aaaaaaaaa --job-id import-TZqNQvDRnW
输出:
{ "UserImportJob": { "JobName": "import-Test5", "JobId": "import-Fx0kARISFL", "UserPoolId": "us-west-2_aaaaaaaaa", "PreSignedUrl": "PRE_SIGNED_URL", "CreationDate": 1548278576.259, "StartDate": 1548278623.366, "CompletionDate": 1548278626.741, "Status": "Stopped", "CloudWatchLogsRoleArn": "arn:aws:iam::111111111111:role/CognitoCloudWatchLogsRole", "ImportedUsers": 0, "SkippedUsers": 0, "FailedUsers": 0, "CompletionMessage": "The Import Job was stopped by the developer." } }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考StopUserImportJob
中的。
-
以下代码示例演示如何使用 update-auth-event-feedback
。
- Amazon CLI
-
更新身份验证事件反馈
此示例更新了授权事件反馈。它将事件标记为 “有效”。
命令:
aws cognito-idp update-auth-event-feedback --user-pool-id us-west-2_aaaaaaaaa --username diego@example.com --event-id EVENT_ID --feedback-token FEEDBACK_TOKEN --feedback-value "Valid"
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateAuthEventFeedback
中的。
-
以下代码示例演示如何使用 update-device-status
。
- Amazon CLI
-
更新设备状态
此示例将设备的状态更新为 “未记住”。
命令:
aws cognito-idp update-device-status --access-token ACCESS_TOKEN --device-key DEVICE_KEY --device-remembered-status "not_remembered"
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateDeviceStatus
中的。
-
以下代码示例演示如何使用 update-group
。
- Amazon CLI
-
更新群组
此示例更新了的描述和优先级 MyGroup。
命令:
aws cognito-idp update-group --user-pool-id us-west-2_aaaaaaaaa --group-name MyGroup --description "New description" --precedence 2
输出:
{ "Group": { "GroupName": "MyGroup", "UserPoolId": "us-west-2_aaaaaaaaa", "Description": "New description", "RoleArn": "arn:aws:iam::111111111111:role/MyRole", "Precedence": 2, "LastModifiedDate": 1548800862.812, "CreationDate": 1548097827.125 } }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateGroup
中的。
-
以下代码示例演示如何使用 update-resource-server
。
- Amazon CLI
-
更新资源服务器
此示例更新资源服务器 Weather。它添加了一个新的作用域。
命令:
aws cognito-idp update-resource-server --user-pool-id us-west-2_aaaaaaaaa --identifier weather.example.com --name Weather --scopes ScopeName=NewScope,ScopeDescription="New scope description"
输出:
{ "ResourceServer": { "UserPoolId": "us-west-2_aaaaaaaaa", "Identifier": "weather.example.com", "Name": "Happy", "Scopes": [ { "ScopeName": "NewScope", "ScopeDescription": "New scope description" } ] } }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateResourceServer
中的。
-
以下代码示例演示如何使用 update-user-attributes
。
- Amazon CLI
-
更新用户属性
此示例更新了用户属性 “昵称”。
命令:
aws cognito-idp update-user-attributes --access-token ACCESS_TOKEN --user-attributes Name="nickname",Value="Dan"
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateUserAttributes
中的。
-
以下代码示例演示如何使用 update-user-pool-client
。
- Amazon CLI
-
更新用户池客户端
此示例更新了用户池客户端的名称。它还添加了一个可写的属性 “昵称”。
命令:
aws cognito-idp update-user-pool-client --user-pool-id us-west-2_aaaaaaaaa --client-id 3n4b5urk1ft4fl3mg5e62d9ado --client-name "NewClientName" --write-attributes "nickname"
输出:
{ "UserPoolClient": { "UserPoolId": "us-west-2_aaaaaaaaa", "ClientName": "NewClientName", "ClientId": "3n4b5urk1ft4fl3mg5e62d9ado", "LastModifiedDate": 1548802761.334, "CreationDate": 1548178931.258, "RefreshTokenValidity": 30, "WriteAttributes": [ "nickname" ], "AllowedOAuthFlowsUserPoolClient": false } }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateUserPoolClient
中的。
-
以下代码示例演示如何使用 update-user-pool
。
- Amazon CLI
-
更新用户池
此示例向用户池添加标签。
命令:
aws cognito-idp update-user-pool --user-pool-id us-west-2_aaaaaaaaa --user-pool-tags Team=Blue,Area=West
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateUserPool
中的。
-