Skip to content

Commit

Permalink
style
Browse files Browse the repository at this point in the history
  • Loading branch information
paulb777 committed Jul 9, 2024
1 parent c343c61 commit 87cd7fc
Show file tree
Hide file tree
Showing 6 changed files with 357 additions and 361 deletions.
2 changes: 1 addition & 1 deletion FirebaseAuth/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
- [added] Introduced the Swift enum `AuthProviderID` for the Auth Provider IDs. (#9236)
- [deprecated] Swift APIs using `String`-typed `productID`s have been deprecated in favor
of newly added API that leverages the `AuthProviderID` enum.
- [fixed] Breaking API: The `email` property in `ActionCodeInfo` is not non-optional.
- [fixed] Breaking API: The `email` property in `ActionCodeInfo` is now non-optional.

# 10.21.0
- [fixed] Fixed multifactor resolver to use the correct Auth instance instead of
Expand Down
188 changes: 93 additions & 95 deletions FirebaseAuth/Sources/Swift/Auth/Auth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import FirebaseCoreExtension

open func application(_ application: UIApplication,
didFailToRegisterForRemoteNotificationsWithError error: Error) {
self.tokenManagerGet().cancel(withError: error)
tokenManagerGet().cancel(withError: error)
}

open func application(_ application: UIApplication,
Expand All @@ -76,30 +76,30 @@ import FirebaseCoreExtension
extension Auth: AuthInterop {
func getTokenInternal(forcingRefresh forceRefresh: Bool) {
// Enable token auto-refresh if not already enabled.
if !self.autoRefreshTokens {
if !autoRefreshTokens {
AuthLog.logInfo(code: "I-AUT000002", message: "Token auto-refresh enabled.")
self.autoRefreshTokens = true
self.scheduleAutoTokenRefresh()

#if os(iOS) || os(tvOS) // TODO(ObjC): Is a similar mechanism needed on macOS?
self.applicationDidBecomeActiveObserver =
NotificationCenter.default.addObserver(
forName: UIApplication.didBecomeActiveNotification,
object: nil, queue: nil
) { notification in
self.isAppInBackground = false
if !self.autoRefreshScheduled {
self.scheduleAutoTokenRefresh()
}
}
self.applicationDidEnterBackgroundObserver =
NotificationCenter.default.addObserver(
forName: UIApplication.didEnterBackgroundNotification,
object: nil, queue: nil
) { notification in
self.isAppInBackground = true
}
#endif
autoRefreshTokens = true
scheduleAutoTokenRefresh()

#if os(iOS) || os(tvOS) // TODO(ObjC): Is a similar mechanism needed on macOS?
applicationDidBecomeActiveObserver =
NotificationCenter.default.addObserver(
forName: UIApplication.didBecomeActiveNotification,
object: nil, queue: nil
) { notification in
self.isAppInBackground = false
if !self.autoRefreshScheduled {
self.scheduleAutoTokenRefresh()
}
}
applicationDidEnterBackgroundObserver =
NotificationCenter.default.addObserver(
forName: UIApplication.didEnterBackgroundNotification,
object: nil, queue: nil
) { notification in
self.isAppInBackground = true
}
#endif
}
}

Expand Down Expand Up @@ -172,10 +172,10 @@ extension Auth: AuthInterop {
/// The string used to set this property must be a language code that follows BCP 47.
@objc open var languageCode: String? {
get {
self.getLanguageCode()
getLanguageCode()
}
set(val) {
self.setLanguageCode(val)
setLanguageCode(val)
}
}

Expand Down Expand Up @@ -1160,8 +1160,8 @@ extension Auth: AuthInterop {
if let currentUser {
let idToken = try await currentUser.internalGetTokenAsync()
let request = RevokeTokenRequest(withToken: authorizationCode,
idToken: idToken,
requestConfiguration: self.requestConfiguration)
idToken: idToken,
requestConfiguration: requestConfiguration)
let _ = try await AuthBackend.call(with: request)
}
}
Expand Down Expand Up @@ -1294,33 +1294,33 @@ extension Auth: AuthInterop {
return data
}

func tokenManagerInit(_ manager: AuthAPNSTokenManager) {
let semaphore = DispatchSemaphore(value: 0)
Task {
await authWorker.tokenManagerInit(manager)
semaphore.signal()
func tokenManagerInit(_ manager: AuthAPNSTokenManager) {
let semaphore = DispatchSemaphore(value: 0)
Task {
await authWorker.tokenManagerInit(manager)
semaphore.signal()
}
semaphore.wait()
}
semaphore.wait()
}

func tokenManagerInit(_ manager: AuthAPNSTokenManager) async {
await authWorker.tokenManagerInit(manager)
}

func tokenManagerGet() -> AuthAPNSTokenManager {
var manager: AuthAPNSTokenManager!
let semaphore = DispatchSemaphore(value: 0)
Task {
manager = await tokenManagerGet()
semaphore.signal()
func tokenManagerGet() -> AuthAPNSTokenManager {
var manager: AuthAPNSTokenManager!
let semaphore = DispatchSemaphore(value: 0)
Task {
manager = await tokenManagerGet()
semaphore.signal()
}
semaphore.wait()
return manager
}
semaphore.wait()
return manager
}

func tokenManagerGet() async -> AuthAPNSTokenManager {
return await authWorker.tokenManagerGet()
}
func tokenManagerGet() async -> AuthAPNSTokenManager {
return await authWorker.tokenManagerGet()
}

/// Sets the APNs token along with its type.
///
Expand All @@ -1337,38 +1337,38 @@ extension Auth: AuthInterop {
semaphore.wait()
}

/// Sets the APNs token along with its type.
///
/// This method is available on iOS only.
///
/// If swizzling is disabled, the APNs Token must be set for phone number auth to work,
/// by either setting calling this method or by setting the `APNSToken` property.
open func setAPNSToken(_ token: Data, type: AuthAPNSTokenType) async {
/// Sets the APNs token along with its type.
///
/// This method is available on iOS only.
///
/// If swizzling is disabled, the APNs Token must be set for phone number auth to work,
/// by either setting calling this method or by setting the `APNSToken` property.
open func setAPNSToken(_ token: Data, type: AuthAPNSTokenType) async {
await authWorker.tokenManagerSet(token, type: type)
}
}

/// Whether the specific remote notification is handled by `Auth` .
///
/// This method is available on iOS only.
///
/// If swizzling is disabled, related remote notifications must be forwarded to this method
/// for phone number auth to work.
/// - Parameter userInfo: A dictionary that contains information related to the
/// notification in question.
/// - Returns: Whether or the notification is handled. A return value of `true` means the
/// notification is for Firebase Auth so the caller should ignore the notification from further
/// processing, and `false` means the notification is for the app (or another library) so
/// the caller should continue handling this notification as usual.
@objc open func canHandleNotification(_ userInfo: [AnyHashable: Any]) -> Bool {
var result = false
let semaphore = DispatchSemaphore(value: 0)
Task {
result = await authWorker.canHandleNotification(userInfo)
semaphore.signal()
/// Whether the specific remote notification is handled by `Auth` .
///
/// This method is available on iOS only.
///
/// If swizzling is disabled, related remote notifications must be forwarded to this method
/// for phone number auth to work.
/// - Parameter userInfo: A dictionary that contains information related to the
/// notification in question.
/// - Returns: Whether or the notification is handled. A return value of `true` means the
/// notification is for Firebase Auth so the caller should ignore the notification from further
/// processing, and `false` means the notification is for the app (or another library) so
/// the caller should continue handling this notification as usual.
@objc open func canHandleNotification(_ userInfo: [AnyHashable: Any]) -> Bool {
var result = false
let semaphore = DispatchSemaphore(value: 0)
Task {
result = await authWorker.canHandleNotification(userInfo)
semaphore.signal()
}
semaphore.wait()
return result
}
semaphore.wait()
return result
}

/// Whether the specific remote notification is handled by `Auth` .
///
Expand All @@ -1382,7 +1382,7 @@ extension Auth: AuthInterop {
/// notification is for Firebase Auth so the caller should ignore the notification from further
/// processing, and `false` means the notification is for the app (or another library) so
/// the caller should continue handling this notification as usual.
@objc open func canHandleNotification(_ userInfo: [AnyHashable: Any]) async -> Bool {
@objc open func canHandleNotification(_ userInfo: [AnyHashable: Any]) async -> Bool {
return await authWorker.canHandleNotification(userInfo)
}

Expand All @@ -1409,21 +1409,21 @@ extension Auth: AuthInterop {
return result
}

/// Whether the specific URL is handled by `Auth` .
///
/// This method is available on iOS only.
///
/// If swizzling is disabled, URLs received by the application delegate must be forwarded
/// to this method for phone number auth to work.
/// - Parameter url: The URL received by the application delegate from any of the openURL
/// method.
/// - Returns: Whether or the URL is handled. `true` means the URL is for Firebase Auth
/// so the caller should ignore the URL from further processing, and `false` means the
/// the URL is for the app (or another library) so the caller should continue handling
/// this URL as usual.
open func canHandle(_ url: URL) async -> Bool {
/// Whether the specific URL is handled by `Auth` .
///
/// This method is available on iOS only.
///
/// If swizzling is disabled, URLs received by the application delegate must be forwarded
/// to this method for phone number auth to work.
/// - Parameter url: The URL received by the application delegate from any of the openURL
/// method.
/// - Returns: Whether or the URL is handled. `true` means the URL is for Firebase Auth
/// so the caller should ignore the URL from further processing, and `false` means the
/// the URL is for the app (or another library) so the caller should continue handling
/// this URL as usual.
open func canHandle(_ url: URL) async -> Bool {
return await authWorker.canHandle(url)
}
}
#endif

/// The name of the `NSNotificationCenter` notification which is posted when the auth state
Expand Down Expand Up @@ -1469,7 +1469,7 @@ extension Auth: AuthInterop {
}
}

// TODO delete me
// TODO: delete me

func signInFlowAuthDataResultCallback(byDecorating callback:
((AuthDataResult?, Error?) -> Void)?) -> (AuthDataResult?, Error?) -> Void {
Expand Down Expand Up @@ -1704,7 +1704,7 @@ extension Auth: AuthInterop {
}
autoRefreshScheduled = true
Task {
await authWorker.autoTokenRefresh(accessToken: accessToken,
await authWorker.autoTokenRefresh(accessToken: accessToken,
retry: retry,
delay: fastTokenRefreshForTest ? 0.1 : delay)
}
Expand Down Expand Up @@ -1759,8 +1759,6 @@ extension Auth: AuthInterop {
anonymous: anonymous)
}



private func getQueryItems(_ link: String) -> [String: String] {
var queryItems = AuthWebUtils.parseURL(link)
if queryItems.count == 0 {
Expand Down
Loading

0 comments on commit 87cd7fc

Please sign in to comment.