From cb72af73f09fb36c2889d9aef94263f0cd5e9bf1 Mon Sep 17 00:00:00 2001 From: Tobias Hagemann Date: Tue, 20 Aug 2024 15:06:14 +0200 Subject: [PATCH] Cleaned up BoxAuthenticator --- .../Box/BoxAuthenticator.swift | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/Sources/CryptomatorCloudAccess/Box/BoxAuthenticator.swift b/Sources/CryptomatorCloudAccess/Box/BoxAuthenticator.swift index cd8ce74..c09bc6e 100644 --- a/Sources/CryptomatorCloudAccess/Box/BoxAuthenticator.swift +++ b/Sources/CryptomatorCloudAccess/Box/BoxAuthenticator.swift @@ -17,39 +17,31 @@ import UIKit public enum BoxAuthenticatorError: Error { case authenticationFailed case invalidContext - case loginCancelled + case userCanceled } public enum BoxAuthenticator { public static func authenticate(from viewController: UIViewController, tokenStorage: TokenStorage) -> Promise { let pendingPromise = Promise.pending() - _Concurrency.Task { do { guard let context = viewController as? ASWebAuthenticationPresentationContextProviding else { throw BoxAuthenticatorError.invalidContext } - let config = OAuthConfig(clientId: BoxSetup.constants.clientId, clientSecret: BoxSetup.constants.clientSecret, tokenStorage: tokenStorage) let oauth = BoxOAuth(config: config) - - // Run the login flow and store the access token using tokenStorage - try await oauth.runLoginFlow(options: .init(), context: context) - + try await oauth.runLoginFlow(options: .init(), context: context) // access token is implictly saved in token storage pendingPromise.fulfill(BoxCredential(tokenStorage: tokenStorage)) } catch let error as ASWebAuthenticationSessionError { if error.code == .canceledLogin { - // Handle the login cancellation - CloudAccessDDLogDebug("BoxAuthenticator: Login flow cancelled by the user.") - pendingPromise.reject(BoxAuthenticatorError.loginCancelled) + CloudAccessDDLogDebug("BoxAuthenticator: Login flow canceled by the user.") + pendingPromise.reject(BoxAuthenticatorError.userCanceled) } else { - // Handle other authentication errors CloudAccessDDLogDebug("BoxAuthenticator: Authentication failed with error: \(error.localizedDescription).") pendingPromise.reject(BoxAuthenticatorError.authenticationFailed) } } } - return pendingPromise } }