Skip to content

Universal Link won't close SFSafariViewController #328

Description

@mab5vot9us9a

Describe the bug
On your Readme page you state that Universal Links are supported. Unfortunately the SFSafariViewController that gets presented using the OIDAuthState.authState(byPresenting: request, presenting: presentingVC) does not close once the redirect URL is reached.
However, copying the URL from the SFSafariViewController and pasting it into Safari manually triggers the App redirect and continues the auth flow in the func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool method resulting in getting a valid authToken, refreshToken, idToken.

My redirect URL looks like this: https://appSubdomain.domain.com/ios/oauth2/callback

I have added applinks:appSubdomain.domain.com under the Associated Domains group in the Target Capabilities. As mentioned before, manually entering https://appSubdomain.domain.com/ios/ in Safari opens the app correctly.

I don't get any feedback from the Library what might be wrong. Any help would be appreciated.

To Reproduce

/// Login ViewController
let configuration = OIDServiceConfiguration(authorizationEndpoint: authURL,
                                            tokenEndpoint: tokenURL,
                                            issuer: issuerURL)

let request = OIDAuthorizationRequest(configuration: configuration,
                                      clientId: "clientID",
                                      clientSecret: "clientSecret",
                                      scopes: [OIDScopeOpenID, OIDScopeProfile],
                                      redirectURL: URL(string: "https://appSubdomain.domain.com/ios/oauth2/callback")!,
                                      responseType: OIDResponseTypeCode,
                                      additionalParameters: nil)

self.currentAuthorizationFlow = OIDAuthState.authState(byPresenting: request, presenting: presentingVC) { authState, error in
    
    if let authState = authState {
        os_log("Got authorization tokens. Access token: %@\nRefresh Token: %@\nIDToken: %@", log: self.logger, type: .debug, authState.lastTokenResponse?.accessToken ?? "DEFAULT_TOKEN", authState.lastTokenResponse?.refreshToken ?? "NONE", authState.lastTokenResponse?.idToken ?? "NONE")
        
    } else {
        os_log("Authorization error: %@", log: self.logger, type: .error, error?.localizedDescription ?? "DEFAULT_ERROR")
    }
}
/// AppDelegate
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
    
    guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
        let url = userActivity.webpageURL else {
            return false
    }
    
    if let authorizationFlow = self.currentAuthorizationFlow, authorizationFlow.resumeExternalUserAgentFlow(with: url) {
        self.currentAuthorizationFlow = nil
        return true
    }
    
    return false
}

Expected behavior
I would expect the Safari ViewController to close and continue with the authorization flow.

Smartphone (please complete the following information):

  • Device: iPhone XS Simulator
  • OS: iOS 12
  • Browser: SFSafariViewController
  • Version: AppAuth (0.95.0) via Cocoapods

Additional context
Using Swift.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions