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

Add support for HTTPS callbacks [SDK-4749] #832

Merged
merged 3 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Gate changes for older Xcode versions
  • Loading branch information
Widcket committed Feb 22, 2024
commit 479e6c83601cb6e96d5ec809b24b050ae3e05b60
6 changes: 6 additions & 0 deletions Auth0/ASProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
return { url, callback in
let session: ASWebAuthenticationSession

#if compiler(>=5.10)
if #available(iOS 17.4, macOS 14.4, *) {
if redirectURL.scheme == "https" {
session = ASWebAuthenticationSession(url: url,
Expand All @@ -25,6 +26,11 @@
callbackURLScheme: redirectURL.scheme,
completionHandler: completionHandler(callback))
}
#else
session = ASWebAuthenticationSession(url: url,
callbackURLScheme: redirectURL.scheme,
completionHandler: completionHandler(callback))
#endif

session.prefersEphemeralWebBrowserSession = ephemeralSession

Expand All @@ -40,13 +46,13 @@
case ASWebAuthenticationSessionError.canceledLogin = error {
return callback(.failure(WebAuthError(code: .userCancelled)))
} else if let error = $1 {
return callback(.failure(WebAuthError(code: .other, cause: error)))

Check warning on line 49 in Auth0/ASProvider.swift

View check run for this annotation

Codecov / codecov/patch

Auth0/ASProvider.swift#L49

Added line #L49 was not covered by tests
}

Check warning on line 51 in Auth0/ASProvider.swift

View check run for this annotation

Codecov / codecov/patch

Auth0/ASProvider.swift#L51

Added line #L51 was not covered by tests

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these bogus code coverage problems? It seems to be complaining about a blank line not being covered.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is due to partial coverage in this line:

Screenshot 2024-02-29 at 11 06 46

Which isn't even relevant anymore, as with Xcode 15 URLComponents and URL now have the same parsing behavior: https://forums.swift.org/t/url-string-behavior-changed-with-xcode-15-0-beta-5/66570

return callback(.failure(WebAuthError(code: .unknown("ASWebAuthenticationSession failed"))))
}

_ = TransactionStore.shared.resume(callbackURL)

Check warning on line 55 in Auth0/ASProvider.swift

View check run for this annotation

Codecov / codecov/patch

Auth0/ASProvider.swift#L54-L55

Added lines #L54 - L55 were not covered by tests
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions Auth0/Auth0WebAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,15 @@ final class Auth0WebAuth: WebAuth {
guard let bundleID = Bundle.main.bundleIdentifier, let domain = self.url.host else { return nil }
let scheme: String

#if compiler(>=5.10)
if #available(iOS 17.4, macOS 14.4, *) {
scheme = https ? "https" : bundleID
} else {
scheme = bundleID
}
#else
scheme = bundleID
#endif

guard let baseURL = URL(string: "\(scheme)://\(domain)") else { return nil }
var components = URLComponents(url: baseURL, resolvingAgainstBaseURL: true)
Expand Down
2 changes: 2 additions & 0 deletions Auth0Tests/WebAuthSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ class WebAuthSpec: QuickSpec {
platform = "macos"
#endif

#if compiler(>=5.10)
if #available(iOS 17.4, macOS 14.4, *) {
context("https") {
it("should build with the domain") {
Expand All @@ -327,6 +328,7 @@ class WebAuthSpec: QuickSpec {
}
}
}
#endif

context("custom scheme") {

Expand Down
Loading