【发布时间】:2019-12-24 00:23:59
【问题描述】:
我正在实现一个函数来检索自定义身份提供商的 IdentityID 和令牌,作为我在 Amazon Cognito 中设置身份验证工作的一部分。我需要将令牌添加为我的 return 语句的一部分,但在我的 return 语句中,我收到了一个错误。
“无法转换 'String 类型的值?'到预期的参数类型 '_?'"。
我不明白什么_?论据是准确的以及如何符合它。
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)
}
resultFromAbove.token 是 String?。所以当我使用它时,我得到了错误。但是,如果我只是输入一个字符串,例如
return AWSTask(result: "abcd")
这似乎很好。我在这里错过了什么?
【问题讨论】:
标签: swift arguments amazon-cognito