DropboxOAuthManager
open 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
DropboxOAuthManager
for 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
convenience public init(appKey: String)
-
Try to handle a redirect back into the application
Declaration
Swift
open func handleRedirectURL(_ url: URL, completion: @escaping DropboxOAuthCompletion) -> Bool
Parameters
url
The URL to attempt to handle.
completion
The 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
open func authorizeFromSharedApplication( _ sharedApplication: SharedApplication, usePKCE: Bool = false, scopeRequest: ScopeRequest? = nil)
Parameters
controller
The controller to present from.
usePKCE
Whether to use OAuth2 code flow with PKCE. Default is false, i.e. use the legacy token flow.
scopeRequest
The ScopeRequest, only used in code flow with PKCE.
-
Retrieve all stored access tokens
Declaration
Swift
open func getAllAccessTokens() -> [String : DropboxAccessToken]
Return Value
a dictionary mapping users to their access tokens
-
Check if there are any stored access tokens
Declaration
Swift
open func hasStoredAccessTokens() -> Bool
Return Value
Whether there are stored access tokens
-
Retrieve the access token for a particular user
Declaration
Swift
open func getAccessToken(_ user: String?) -> DropboxAccessToken?
Parameters
user
The user whose token to retrieve
Return Value
An access token if present, otherwise
nil
. -
Delete a specific access token
Declaration
Swift
open func clearStoredAccessToken(_ token: DropboxAccessToken) -> Bool
Parameters
token
The access token to delete
Return Value
whether the operation succeeded
-
Delete all stored access tokens
Declaration
Swift
open func clearStoredAccessTokens() -> Bool
Return Value
whether the operation succeeded
-
Save an access token
Declaration
Swift
@discardableResult open func storeAccessToken(_ token: DropboxAccessToken) -> Bool
Parameters
token
The access token to save
Return Value
whether the operation succeeded
-
Utility function to return an arbitrary access token
Declaration
Swift
open 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
accessToken
A
DropboxAccessToken
object.scopes
An 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.
queue
The queue where completion block will be called from.
completion
A
DropboxOAuthCompletion
block to notify caller the result.