gpt4 book ai didi

ios - OAuth 错误一般代码 4 Swift - AppAuth for iOS

转载 作者:行者123 更新时间:2023-11-30 12:16:32 25 4
gpt4 key购买 nike

我正在尝试在 iOS 中实现 AppAuth。已基本落实。似乎一切正常。但我没有按预期收到 token 。我收到错误 Error Domain=org.openid.appauth.general Code=-4

   let authorizationEndpoint : NSURL = NSURL(string: "https://accounts.google.com/o/oauth2/v2/auth")!
let tokenEndpoint : NSURL = NSURL(string: "https://www.googleapis.com/oauth2/v4/token")!

let configuration = OIDServiceConfiguration(authorizationEndpoint: authorizationEndpoint as URL, tokenEndpoint: tokenEndpoint as URL)

let request = OIDAuthorizationRequest.init(configuration: configuration, clientId: "<MyTOKEN>", scopes: [OIDScopeOpenID], redirectURL: URL(string: "http://127.0.0.1:9004")!, responseType: OIDResponseTypeCode, additionalParameters: nil)

let appDelegate = UIApplication.shared.delegate as! AppDelegate
// appDelegate.currentAuthorizationFlow
appDelegate.currentAuthorizationFlow = OIDAuthState.authState(byPresenting: request, presenting: self, callback: { (authState, error) in
if((authState) != nil){
print("Got authorization tokens. Access token: \(authState?.lastTokenResponse?.accessToken)")
}else{
print("Authorization error \(error?.localizedDescription)")
}
})

最佳答案

处理错误和更改后,我在处理redirectUri和Token后发现了问题。redirectUri - 一旦您通过谷歌授权,它就会生成 token ,之后您应该打开应用程序。 redirectUri 会对此有所帮助。您可以这样设置 redirectUri

iOS URL 方案的值将是您的重定向 URI 的方案。这是反向域名表示法中的客户端 ID,例如com.googleusercontent.apps.IDENTIFIER。要构造重定向 URI,请添加您自己的路径组件。例如。 com.googleusercontent.apps.IDENTIFIER:/oauth2redirect/google。请注意,方案后面只有一个斜杠 (/)。

关于ios - OAuth 错误一般代码 4 Swift - AppAuth for iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45367361/

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