gpt4 book ai didi

ios - 刷新 token AWS Cognito 用户池,代码块甚至不运行

转载 作者:可可西里 更新时间:2023-11-01 01:16:24 24 4
gpt4 key购买 nike

我正在尝试刷新用户 token ,我是在一个“子”应用程序中执行此操作的,该应用程序只能访问 idToken、accessToken、refreshToken 以及除密码之外的用​​户信息。它是沙盒化的,无法与主应用程序通信。

我已尝试使用以下代码来运行 initiateAuth

let authParams = [
"REFRESH_TOKEN": user.refreshToken,
"SECRET_HASH": config.getClientSecret()
]

let provider = AWSCognitoIdentityProvider(forKey: config.getClientSecret())

let req = AWSCognitoIdentityProviderInitiateAuthRequest()
req?.authFlow = AWSCognitoIdentityProviderAuthFlowType.refreshToken
req?.clientId = config.getClientId()
req?.authParameters = authParams

provider.initiateAuth(req!).continueWith() {
resp in
print("I'm not running")
if (resp != nil) {
print(resp.error.debugDescription)
} else {
print(resp.result.debugDescription)
}
return nil
}

令人震惊的是,continueWith 代码块甚至根本没有运行,也没有调用打印语句“我没有运行”。我不知所措,因为这似乎是在做他们在 SDK 中做的事情:https://github.com/aws/aws-sdk-ios/blob/master/AWSCognitoIdentityProvider/AWSCognitoIdentityUser.m#L173

最佳答案

@behrooziAWS 的评论为我解决了同样的问题。

具体来说,即使 AWSCognitoIdentityProvider(forKey:) 的初始化程序在 XCode 的快速帮助中记录为:

+ (nonnull instancetype)CognitoIdentityProviderForKey:(nonnull NSString *)key;

如果未找到提供的 keyCognitoIdentityProvider,它可以(并且将会)返回 nil。发生这种情况的一种情况是,从未为提供的 key 调用 AWSCognitoIdentityProvider.register(with:forKey:)

if(provider != nil) 产生一个编译器警告它永远为 true 时,它会更加令人困惑。我必须使用以下代码片段才能在没有警告的情况下正常工作:

    let provider: AWSCognitoIdentityProvider? = AWSCognitoIdentityProvider(
forKey: config.getClientSecret())
guard provider != nil else {
fatalError("AWSCognitoIdentityProvider not registered!")
}

附言我希望有更多 Swift+ObjC 经验的人可以评论为什么初始化程序出现或被翻译为 nonnull instancetype,即使 Objective C 源代码只有 instancetype编辑:此初始化程序(以及 AWSCognitoIdentityProvider/AWSCognitoIdentityUser.h 文件中的几乎所有其他内容)自动用 nonnull 注释的原因是 NS_ASSUME_NONNULL_BEGINNS_ASSUME_NONNULL_END 宏。在 CognitoIdentityProviderForKey 的情况下,此非空假设不应该有效。

关于ios - 刷新 token AWS Cognito 用户池,代码块甚至不运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46209640/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com