gpt4 book ai didi

ios - 使用 AppAuth 和 Okta 时 iOS 上的身份验证问题

转载 作者:行者123 更新时间:2023-11-28 15:19:44 25 4
gpt4 key购买 nike

我有一个简单的 iOS Swift 应用程序,大致基于 AppAuth-iOS 示例 (https://github.com/openid/AppAuth-iOS) 以及 Okta OAuth 示例 (https://github.com/oktadeveloper/okta-openidconnect-appauth-ios)。我既不使用服务发现也不使用自动 token 获取(即不使用 authStateByPresentingAuthorizationRequest)。

我的示例适用于 Azure AD,但不适用于 Okta。我能够登录并通过身份验证并重定向回我的移动应用程序 (AppDelegate.application()),但随后流程不会返回到我的 OIDAuthorizationService.present() 完成 block 。

这是一些代码:

@IBAction func signInButton(_ sender: Any) {

// select idp
switch selectedIdentityProvider! {
case "Azure AD":
selectedAuthConfig = AzureAdAuthConfig()
case "Okta":
selectedAuthConfig = OktaAuthConfig();
default:
return
}

appAuthAuthorize(authConfig: selectedAuthConfig!)
}

func appAuthAuthorize(authConfig: AuthConfig) {
let serviceConfiguration = OIDServiceConfiguration(
authorizationEndpoint: NSURL(string: authConfig.authEndPoint)! as URL,
tokenEndpoint: NSURL(string: authConfig.tokenEndPoint)! as URL)

let request = OIDAuthorizationRequest(configuration: serviceConfiguration, clientId: authConfig.clientId, scopes: authConfig.scope, redirectURL: NSURL(string: authConfig.redirectUri)! as URL, responseType: OIDResponseTypeCode, additionalParameters: nil)

doAppAuthAuthorization(authRequest: request)
}


func doAppAuthAuthorization(authRequest: OIDAuthorizationRequest) {
let appDelegate = UIApplication.shared.delegate as! AppDelegate

appDelegate.currentAuthorizationFlow = OIDAuthorizationService.present(authRequest, presenting: self, callback: {
(authorizationResponse, error) in
if (authorizationResponse != nil) {
self.authState = OIDAuthState(authorizationResponse: authorizationResponse!)
self.logMessage(message: "Got authorization tokens. Access token: \(String(describing: self.authState?.lastAuthorizationResponse.authorizationCode))")
self.doTokenRequest()
} else {
self.authState = nil
self.logMessage(message: "Authorization error: \(String(describing: error?.localizedDescription))")
}
})
}

我可以重写代码以使用 authStateByPresentingAuthorizationRequest() 来查看它是否有效,但我有点怀疑,因为此代码适用于 Azure AD。有什么建议吗?

更新 1我忘了提到我有一个运行的 Android/Java 示例与相同的 Okta 定义相反并且运行起来非常棒。

更新 2我确实重写了代码以对 Okta 使用 authStateByPresentingAuthorizationRequest() 并得到相同的结果(即在重定向回我的应用程序后卡住)。我针对 Azure AD 对此进行了测试,它运行正常。

最佳答案

已解决。我猜问题是 Okta 中定义的重定向 URL 是大小写混合的。 Android AppAuth 实现不介意,但 iOS AppAuth 实现不介意。将 Okta 中的重定向 URL 更改为仅小写,将传入的重定向 Uri 参数更改为仅小写和 bing,一切都很好。感谢 @jmelberg 向我指出了这个方向 - 通过调试 resumeAuthorizationFlow(with: url) 我能够看到确切的行为以及调用返回 False 的原因。

关于ios - 使用 AppAuth 和 Okta 时 iOS 上的身份验证问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46228069/

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