openid / AppAuth-iOS

iOS and macOS SDK for communicating with OAuth 2.0 and OpenID Connect providers.
https://openid.github.io/AppAuth-iOS
Apache License 2.0
1.72k stars 744 forks source link

SwiftUI problem with Apple response #817

Closed luesp15 closed 5 months ago

luesp15 commented 5 months ago

Hi everyone, I'm trying to implement SSO (Facebook, Google and Apple) on my app. I followed the example in the Example-iOS_Swift-Carthage folder and with the Google and Facebook providers everything works correctly.

With Apple, however, I don't receive any response once the request is made, even if I actually see from keycloak that the login was successful.

let addParamsDict: [String: String] = ["kc_idp_hint" : socialType, "prompt": "login"]
let request = OIDAuthorizationRequest(
                            configuration: configuration, 
                            clientId: clientID, 
                            clientSecret: clientSecret, 
                            scopes: [OIDScopeOpenID, OIDScopeProfile], 
                            redirectURL: redirectURI, 
                            responseType: OIDResponseTypeCode, 
                            additionalParameters: addParamsDict
)

appDelegate.currentAuthorizationFlow = OIDAuthState.authState(byPresenting: request, presenting: getHostingViewController(), prefersEphemeralSession: true) { (authState, error) in
            if let authState = authState {
                let accessToken = authState.lastTokenResponse?.accessToken
                let refreshToken = authState.lastTokenResponse?.refreshToken
                print("--> accessToken \(accessToken)")
                print("--> refreshToken \(refreshToken)")

            } else {
                print("--> Authorization error: \(error?.localizedDescription ?? "DEFAULT_ERROR")")
            }
        }

I forgot something?

I also tried apple with the Example-iOS_Swift-Carthage and everything works fine.

I want to point out that my project uses SwiftUI, I thought this might be the problem, although I don't understand why it works with Google and Facebook.

Thanks in advance!