diff --git a/Source/SwiftyDropbox/Shared/Handwritten/OAuth/OAuth.swift b/Source/SwiftyDropbox/Shared/Handwritten/OAuth/OAuth.swift index 30dc3ba5..f5c3a5e1 100644 --- a/Source/SwiftyDropbox/Shared/Handwritten/OAuth/OAuth.swift +++ b/Source/SwiftyDropbox/Shared/Handwritten/OAuth/OAuth.swift @@ -140,6 +140,9 @@ public enum OAuth2Error: String, Error { /// The state param received from the authorization server does not match the state param stored by the SDK. case inconsistentState = "inconsistent_state" + + /// Failed to save the token. + case tokenStorageError = "token_storage_error" /// Some other error (outside of the OAuth2 specification) case unknown diff --git a/Source/SwiftyDropbox/Shared/Handwritten/OAuth/OAuthImpl.swift b/Source/SwiftyDropbox/Shared/Handwritten/OAuth/OAuthImpl.swift index b53aa732..cf4244c1 100644 --- a/Source/SwiftyDropbox/Shared/Handwritten/OAuth/OAuthImpl.swift +++ b/Source/SwiftyDropbox/Shared/Handwritten/OAuth/OAuthImpl.swift @@ -86,8 +86,11 @@ public class DropboxOAuthManager: AccessTokenRefreshing { } if canHandleURL(url) { extractFromUrl(url) { result in + var result = result if case let .success(token) = result { - self.storeAccessToken(token) + if !self.storeAccessToken(token) { + result = .error(.tokenStorageError, nil) + } } completion(result) } @@ -425,8 +428,12 @@ public class DropboxOAuthManager: AccessTokenRefreshing { uid: uid, refreshToken: refreshToken, scopes: scopes, appKey: appKey, locale: localeIdentifier ) refreshRequest.start(queue: DispatchQueue.main) { [weak self] result in + var result = result if case let .success(token) = result { - self?.storeAccessToken(token) + guard let self else { return } + if !self.storeAccessToken(token) { + result = .error(.tokenStorageError, nil) + } } (queue ?? DispatchQueue.main).async { completion(result) } }