我一直在使用AWS Cognito用户池在iOS应用中登录用户,效果很好。我要添加Developer Authenticated Identities。
根据指南
要使用开发人员认证的身份,请实现您自己的身份提供程序类,该类扩展了AWSCognitoCredentialsProviderHelper。您的身份提供者类应返回一个包含令牌作为属性的响应对象。
import AWSCore
/*
* Use the token method to communicate with your backend to get an
* identityId and token.
*/
class DeveloperAuthenticatedIdentityProvider : AWSCognitoCredentialsProviderHelper {
override func token() -> AWSTask<NSString> {
//Write code to call your backend:
//pass username/password to backend or some sort of token to authenticate user, if successful,
//from backend call getOpenIdTokenForDeveloperIdentity with logins map containing "your.provider.name":"enduser.username"
//return the identity id and token to client
//You can use AWSTaskCompletionSource to do this asynchronously
// Set the identity id and return the token
self.identityId = resultFromAbove.identityId
return AWSTask(result: resultFromAbove.token)
}
要使用此身份提供程序,请将其传递到AWSCognitoCredentialsProvider中,如以下示例所示:
let devAuth = DeveloperAuthenticatedIdentityProvider(regionType: .YOUR_IDENTITY_POOL_REGION, identityPoolId: "YOUR_IDENTITY_POOL_ID", useEnhancedFlow: true, identityProviderManager:nil)
let credentialsProvider = AWSCognitoCredentialsProvider(regionType: .YOUR_IDENTITY_POOL_REGION, identityProvider:devAuth)
let configuration = AWSServiceConfiguration(region: .YOUR_IDENTITY_POOL_REGION, credentialsProvider:credentialsProvider)
AWSServiceManager.default().defaultServiceConfiguration = configuration
我希望在实现AWSCognitoCredentialsProviderHelper
并在当前工作的Cognito用户池代码中交换新的credentialsProvider
之后,一切都将与开发人员身份验证身份一起正常工作。问题是我在token()
函数中从哪里获取用户名/密码?
在使用Cognito用户池的情况下,我仅呼叫AWSCognitoIdentityUser.getDetails()
,signInViewController
将由AWSCognitoIdentityInteractiveAuthenticationDelegate
呈现,而用户名和密码则由passwordAuthenticationCompletionSource?.set(result: authDetails)
在{{1 }}。然后,Cognito用户池完成其余的工作。
要实现开发者身份验证身份,我应该如何提交用户名和密码,以便登录继续进行,并且最终将按教程预期的那样在signInViewController
函数中出现?