Skip to content

Commit d8d7b22

Browse files
author
Guilherme Souza
committed
Add default implementation of ASWebAuthenticationPresentationContextProviding
1 parent 9b22fd2 commit d8d7b22

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

Sources/Auth/AuthClient.swift

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ public final class AuthClient: @unchecked Sendable {
672672
redirectTo: URL? = nil,
673673
scopes: String? = nil,
674674
queryParams: [(name: String, value: String?)] = [],
675-
configure: @Sendable (_ session: ASWebAuthenticationSession) -> Void
675+
configure: @Sendable (_ session: ASWebAuthenticationSession) -> Void = { _ in }
676676
) async throws -> Session {
677677
try await signInWithOAuth(
678678
provider: provider,
@@ -686,6 +686,8 @@ public final class AuthClient: @unchecked Sendable {
686686
return
687687
}
688688

689+
var presentationContextProvider: DefaultPresentationContextProvider?
690+
689691
let session = ASWebAuthenticationSession(
690692
url: url,
691693
callbackURLScheme: callbackScheme
@@ -697,10 +699,18 @@ public final class AuthClient: @unchecked Sendable {
697699
} else {
698700
continuation.resume(throwing: AuthError.missingURL)
699701
}
702+
703+
// Keep a strong reference to presentationContextProvider until the flow completes.
704+
_ = presentationContextProvider
700705
}
701706

702707
configure(session)
703708

709+
if session.presentationContextProvider == nil {
710+
presentationContextProvider = DefaultPresentationContextProvider()
711+
session.presentationContextProvider = presentationContextProvider
712+
}
713+
704714
session.start()
705715
}
706716
}
@@ -1244,3 +1254,12 @@ extension AuthClient {
12441254
/// ``AuthClient/didChangeAuthStateNotification`` notification.
12451255
public static let authChangeSessionInfoKey = "AuthClient.authChangeSession"
12461256
}
1257+
1258+
@MainActor
1259+
final class DefaultPresentationContextProvider: NSObject,
1260+
ASWebAuthenticationPresentationContextProviding
1261+
{
1262+
func presentationAnchor(for _: ASWebAuthenticationSession) -> ASPresentationAnchor {
1263+
ASPresentationAnchor()
1264+
}
1265+
}

0 commit comments

Comments
 (0)