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 } }