DropboxOAuthManager
public class DropboxOAuthManager : AccessTokenRefreshing
Manages access token storage and authentication
Use the DropboxOAuthManager to authenticate users through OAuth2, save access tokens, and retrieve access tokens.
@note OAuth flow webviews localize to enviroment locale.
-
A shared instance of a
DropboxOAuthManagerfor convenienceDeclaration
Swift
public static var sharedOAuthManager: DropboxOAuthManager!
-
Create an instance parameter appKey: The app key from the developer console that identifies this app.
Declaration
Swift
public convenience init(appKey: String, secureStorageAccess: SecureStorageAccess) -
Try to handle a redirect back into the application
Declaration
Swift
public func handleRedirectURL(_ url: URL, completion: @escaping DropboxOAuthCompletion) -> BoolParameters
urlThe URL to attempt to handle.
completionThe callback closure to receive auth result.
Return Value
Whether the redirect URL can be handled.
-
Present the OAuth2 authorization request page by presenting a web view controller modally.
Declaration
Swift
public func authorizeFromSharedApplication( _ sharedApplication: SharedApplication, usePKCE: Bool = false, scopeRequest: ScopeRequest? = nil )Parameters
controllerThe controller to present from.
usePKCEWhether to use OAuth2 code flow with PKCE. Default is false, i.e. use the legacy token flow.
scopeRequestThe ScopeRequest, only used in code flow with PKCE.
-
Retrieve all stored access tokens
Declaration
Swift
public func getAllAccessTokens() -> [String : DropboxAccessToken]Return Value
a dictionary mapping users to their access tokens
-
Check if there are any stored access tokens
Declaration
Swift
public func hasStoredAccessTokens() -> BoolReturn Value
Whether there are stored access tokens
-
Retrieve the access token for a particular user
Declaration
Swift
public func getAccessToken(_ user: String?) -> DropboxAccessToken?Parameters
userThe user whose token to retrieve
Return Value
An access token if present, otherwise
nil. -
Delete a specific access token
Declaration
Swift
public func clearStoredAccessToken(_ token: DropboxAccessToken) -> BoolParameters
tokenThe access token to delete
Return Value
whether the operation succeeded
-
Delete all stored access tokens
Declaration
Swift
public func clearStoredAccessTokens() -> BoolReturn Value
whether the operation succeeded
-
Save an access token
Declaration
Swift
@discardableResult public func storeAccessToken(_ token: DropboxAccessToken) -> BoolParameters
tokenThe access token to save
Return Value
whether the operation succeeded
-
Utility function to return an arbitrary access token
Declaration
Swift
public func getFirstAccessToken() -> DropboxAccessToken?Return Value
the “first” access token found, if any (otherwise
nil)
-
Refreshes a (short-lived) access token for a given DropboxAccessToken.
Note
Completion block will be called on main queue if a callback queue is not provided.
Declaration
Swift
public func refreshAccessToken( _ accessToken: DropboxAccessToken, scopes: [String], queue: DispatchQueue?, completion: @escaping DropboxOAuthCompletion )Parameters
accessTokenA
DropboxAccessTokenobject.scopesAn array of scopes to be granted for the refreshed access token. The requested scope MUST NOT include any scope not originally granted. Useful if users want to reduce the granted scopes for the new access token. Pass in an empty array if you don’t want to change scopes of the access token.
queueThe queue where completion block will be called from.
completionA
DropboxOAuthCompletionblock to notify caller the result. -
Creates an
AccessTokenProviderthat wraps short-lived for token refresh or a static provider for long-live token.Declaration
Swift
public func accessTokenProviderForToken(_ token: DropboxAccessToken) -> AccessTokenProviderParameters
tokenThe
DropboxAccessTokenobject.
View on GitHub
DropboxOAuthManager Class Reference