Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useAuthenticationSession = true not launching an ASWebAuthenticationSession #360

Open
dnsco opened this issue Feb 6, 2021 · 2 comments
Open

Comments

@dnsco
Copy link

dnsco commented Feb 6, 2021

I've got the following code, but it's launching a safari window instead of an ASWebAuthenticationSession.

I'm not sure if this is because I'm using SwiftUI?

This could be user error, but it wasn't clear from the docs.

let oauth2 = OAuth2CodeGrant(settings: [
  //...
] as OAuth2JSON)

oauth2.logger = OAuth2DebugLogger(.trace)
oauth2.authConfig.ui.useAuthenticationSession = true

oauth2.authorize() {(json, err) in
 //...
}

If I set:

oauth2.authConfig.authorizeEmbedded = true

I get:

2021-02-06 04:02:47.060157-0700 better[2680:60843] Fatal error: Invalid authConfig.authorizeContext, must be a UIViewController but is nil: file iOS/OAuth2Authorizer+iOS.swift, line 328
@longinius
Copy link
Contributor

If authorizeEmbedded is not set, it will open Safari and doesn't recognize the useAuthenticationSession Setting. So to use you must set

oauth2.authConfig.authorizeEmbedded = true

The Fatal Error is there because of the missing context. But the current version (5.3.1) doesn't work with SwiftUI, because the type of the presentation context was changed.
So for a quick fix use version 5.3.0. With this version the ASWebAuthenticationSession opens as expected.

Create an ASPresentationAnchor:

let presentationAnchor = ASPresentationAnchor()

Then set it as context for for the OAuth library:

let oauth2 = OAuth2CodeGrant(settings: [
  //...
] as OAuth2JSON)

oauth2.logger = OAuth2DebugLogger(.trace)
oauth2.authConfig.authorizeContext = presentationAnchor
oauth2.authConfig.authorizeEmbedded = true
oauth2.authConfig.ui.useAuthenticationSession = true

oauth2.authorize() {(json, err) in
 //...
}

@svencorell
Copy link

svencorell commented Jun 17, 2021

For me, it's working with 5.3.1.
I'm using:

oauth2.logger = OAuth2DebugLogger(.trace)
oauth2.authConfig.ui.useAuthenticationSession = true
oauth2.authConfig.authorizeEmbedded = true
oauth2.authConfig.authorizeContext = UIApplication.shared.windows.first!.rootViewController!`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants