示例:利用 Lambda 触发器迁移 iOS 用户
可使用用户迁移 Lambda 触发器轻松地将用户从现有用户管理系统迁移到您的用户池,而无需重置密码。
设置用户迁移 Lambda 触发器
在对您的 iOS 应用程序进行改动之前,请首先为用户池设置用户迁移 Lambda。
要了解有关 Lambda 触发器的更多信息,请参阅 使用 Lambda 触发器自定义用户池工作流。
有关使用 Lambda 触发器迁移用户的更多信息,请参阅 利用用户迁移 Lambda 触发器将用户导入用户池。
iOS 应用程序改动
-
更新您的 SDK
将 AWSCognitoIdentityProvider iOS 开发工具包更新为版本 2.6.12 或更高版本。
-
启用迁移
如果使用 Info.plist 配置您的用户池:
添加布尔
MigrationEnabled
键,值为YES
。如果您针对 Info.plist 选择 Open As->Source Code,应与以下内容类似:
<key>AWS</key> <dict> <key>CognitoUserPool</key> <dict> <key>Default</key> <dict> <key>AppClientId</key> <string>YOUR_APP_CLIENT_ID</string> <key>PoolId</key> <string>region_YOUR_USER_POOL_ID </string> <key>Region</key> <string>us-west-2</string> <key>MigrationEnabled</key> <true/> </dict> </dict> </dict>
用户迁移身份验证流程
您可以对用户进行身份验证,比照旧系统验证其密码,并将他们的配置文件无缝迁移到您的用户池。但是,此服务需要旧密码,以避免密码重置。因此,如果在身份验证流程中显式启用,开发工具包通过加密 SSL 连接将文本形式的用户密码发送至服务。
如果使用 AWSCognitoIdentityUserPoolConfiguration 配置您的用户池,请更改为支持 migrationEnabled
标志的初始化程序。
- Objective-C
AWSCognitoIdentityUserPoolConfiguration * poolConfiguration = [[AWSCognitoIdentityUserPoolConfiguration alloc] initWithClientId:@"YOUR_APP_CLIENT_ID" clientSecret:@"YOUR_OPTIONAL_APP_CLIENT_SECRET" poolId:@"YOUR_USER_POOL_ID" shouldProvideCognitoValidationData:YES pinpointAppId:@"YOUR_OPTIONAL_PINPOINT_APP_ID" migrationEnabled:YES];
- Swift
let poolConfiguration = AWSCognitoIdentityUserPoolConfiguration(clientId: "YOUR_APP_CLIENT_ID", clientSecret: "YOUR_OPTIONAL_APP_CLIENT_SECRET", poolId: "YOUR_USER_POOL_ID", shouldProviderCognitoValidationData: YES, pinpointAppId: "YOUR_OPTIONAL_PINPOINT_APP_ID", migrationEnabled: YES)