Skip to content

Commit 6de7e95

Browse files
committed
[Auth] Implement the handle(_:) method
1 parent 4445492 commit 6de7e95

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

FirebaseAuth/Sources/Swift/Auth/Auth.swift

+19-1
Original file line numberDiff line numberDiff line change
@@ -1605,7 +1605,6 @@ extension Auth: AuthInterop {
16051605
/// so the caller should ignore the URL from further processing, and `false` means the
16061606
/// the URL is for the app (or another library) so the caller should continue handling
16071607
/// this URL as usual.
1608-
@discardableResult
16091608
@objc(canHandleURL:) open func canHandle(_ url: URL) -> Bool {
16101609
kAuthGlobalWorkQueue.sync {
16111610
guard let authURLPresenter = self.authURLPresenter as? AuthURLPresenter else {
@@ -1614,6 +1613,25 @@ extension Auth: AuthInterop {
16141613
return authURLPresenter.canHandle(url: url)
16151614
}
16161615
}
1616+
1617+
/// Handles the given URL if it is recognized by `Auth`.
1618+
///
1619+
/// This method should be called when a URL is received by the scene delegate, ensuring that
1620+
/// authentication-related URLs are properly processed. It ensures that URLs passed from
1621+
/// `openURLContexts` are handled by the authentication system.
1622+
///
1623+
/// - Note: This method is available on iOS only.
1624+
///
1625+
/// - Parameter url: The URL received by the application delegate from any of the `openURL`
1626+
/// methods.
1627+
@objc open func handle(_ url: URL) throws {
1628+
guard canHandle(url) else {
1629+
throw AuthErrorUtils.error(
1630+
code: AuthErrorCode.internalError,
1631+
userInfo: [NSLocalizedDescriptionKey: "The URL can't be handled"]
1632+
)
1633+
}
1634+
}
16171635
#endif
16181636

16191637
/// The name of the `NSNotificationCenter` notification which is posted when the auth state

FirebaseAuth/Tests/Unit/AuthTests.swift

+16
Original file line numberDiff line numberDiff line change
@@ -2364,6 +2364,22 @@ class AuthTests: RPCBaseTests {
23642364
XCTAssertTrue(auth.application(UIApplication.shared, open: url, options: [:]))
23652365
XCTAssertTrue(fakeURLPresenter.canHandled)
23662366
}
2367+
2368+
func testAppHandleURL_AuthPresenterHandleURL() throws {
2369+
class FakeURLPresenter: AuthURLPresenter {
2370+
var canHandled = false
2371+
override func canHandle(url: URL) -> Bool {
2372+
canHandled = true
2373+
return true
2374+
}
2375+
}
2376+
let url = try XCTUnwrap(URL(string: "https://localhost"))
2377+
let fakeURLPresenter = FakeURLPresenter()
2378+
auth.authURLPresenter = fakeURLPresenter
2379+
XCTAssertFalse(fakeURLPresenter.canHandled)
2380+
try auth.handle(url)
2381+
XCTAssertTrue(fakeURLPresenter.canHandled)
2382+
}
23672383
#endif // os(iOS)
23682384

23692385
// MARK: Interoperability Tests

0 commit comments

Comments
 (0)