BoxSDK
public class BoxSDK
Provides methods for creating BoxSDKClient
-
Box-specific constants
See moreDeclaration
Swift
public enum Constants
-
SDK configuration
Declaration
Swift
public private(set) var configuration: BoxSDKConfiguration { get }
-
Default configuration
Declaration
Swift
public static let defaultConfiguration: BoxSDKConfiguration
-
Auth module providing authorization and token related requests. Is set upon BoxSDK initialisation
Declaration
Swift
public private(set) var auth: AuthModule { get }
-
Initializer
Declaration
Swift
public init(clientId: String, clientSecret: String, callbackURL: String? = nil)
Parameters
clientId
The client ID of the application requesting authentication. To get the client ID for your application, log in to your Box developer console click the Edit Application link for the application you’re working with. In the OAuth 2 Parameters section of the configuration page, find the item labeled “client_id”. The text of that item is your application’s client ID.
clientSecret
The client secret of the application requesting authentication. To get the client secret for your application, log in to your Box developer console and click the Edit Application link for the application you’re working with. In the OAuth 2 Parameters section of the configuration page, find the item labeled “client_secret”. The text of that item is your application’s client secret.
callbackURL
An optional custom callback URL string. The URL to which Box redirects the browser when authentication completes. The user’s actual interaction with your application begins when Box redirects to this URL. If not specified, the default URL is used, in the format of
boxsdk-CLIENTID://boxsdkoauth2redirect
, where CLIENTID is replaced with the value of theclientId
parameter.
-
Creates BoxClient object based on developer token
Declaration
Swift
public static func getClient(token: String) -> BoxClient
Parameters
token
Developer token
Return Value
New BoxClient object
-
Creates BoxClient with developer token
Declaration
Swift
public func getClient(token: String) -> BoxClient
Parameters
token
Developer token
Return Value
New BoxClient object
-
Creates BoxClient using JWT token.
Declaration
Swift
public func getDelegatedAuthClient( authClosure: @escaping DelegatedAuthClosure, uniqueID: String, tokenInfo: TokenInfo? = nil, tokenStore: TokenStore? = nil, completion: @escaping Callback<BoxClient> )
Parameters
tokenInfo
Information about token
tokenStore
Custom token store. To use custom store, implement TokenStore protocol.
authClosure
Requests new JWT token value when needed. Provide the token value from your token provider.
uniqueID
Unique identifier provided for jwt token.
completion
Returns standard BoxClient object or error.
-
Creates BoxClient using Server Authentication with Client Credentials Grant for account service
Declaration
Swift
public func getCCGClientForAccountService( enterpriseId: String, tokenInfo: TokenInfo? = nil, tokenStore: TokenStore? = nil, completion: @escaping Callback<BoxClient> )
Parameters
enterpriseId
The enterprise ID to use when getting the access token.
tokenInfo
Information about token
tokenStore
Custom token store. To use custom store, implement TokenStore protocol.
completion
Returns standard BoxClient object or error.
-
Creates BoxClient using Server Authentication with Client Credentials Grant for user account
Declaration
Swift
public func getCCGClientForUser( userId: String, tokenInfo: TokenInfo? = nil, tokenStore: TokenStore? = nil, completion: @escaping Callback<BoxClient> )
Parameters
userId
The user ID to use when getting the access token.
tokenInfo
Information about token
tokenStore
Custom token store. To use custom store, implement TokenStore protocol.
completion
Returns standard BoxClient object or error.
-
Creates BoxClient in a completion with OAuth 2.0 type of authentication
Declaration
Swift
@available(iOS 13.0, *) public func getOAuth2Client( tokenInfo: TokenInfo? = nil, tokenStore: TokenStore? = nil, context: ASWebAuthenticationPresentationContextProviding, completion: @escaping Callback<BoxClient> )
Parameters
tokenInfo
Information about token
tokenStore
Custom token store. To use custom store, implement TokenStore protocol.
context
The ViewController that is presenting the OAuth request
completion
Returns created standard BoxClient object or error
-
Creates BoxClient in a completion with OAuth 2.0 type of authentication
Declaration
Swift
@available(iOS 11.0, *) public func getOAuth2Client( tokenInfo: TokenInfo? = nil, tokenStore: TokenStore? = nil, completion: @escaping Callback<BoxClient> )
Parameters
tokenInfo
Information about token
tokenStore
Custom token store. To use custom store, implement TokenStore protocol.
completion
Returns created standard BoxClient object or error
-
Creates BoxClient using JWT token.
Throws
BoxSDKErrorDeclaration
Swift
func getDelegatedAuthClient( authClosure: @escaping DelegatedAuthClosure, uniqueID: String, tokenInfo: TokenInfo? = nil, tokenStore: TokenStore? = nil ) async throws -> BoxClient
Parameters
tokenInfo
Information about token
tokenStore
Custom token store. To use custom store, implement TokenStore protocol.
authClosure
Requests new JWT token value when needed. Provide the token value from your token provider.
uniqueID
Unique identifier provided for jwt token.
Return Value
The BoxClient object
-
Creates BoxClient using Server Authentication with Client Credentials Grant for account service
Throws
BoxSDKErrorDeclaration
Swift
func getCCGClientForAccountService( enterpriseId: String, tokenInfo: TokenInfo? = nil, tokenStore: TokenStore? = nil ) async throws -> BoxClient
Parameters
enterpriseId
The enterprise ID to use when getting the access token.
tokenInfo
Information about token
tokenStore
Custom token store. To use custom store, implement TokenStore protocol.
Return Value
The BoxClient object
-
getCCGClientForUser(userId:
AsynchronoustokenInfo: tokenStore: ) Creates BoxClient using Server Authentication with Client Credentials Grant for user account
Throws
BoxSDKErrorDeclaration
Swift
func getCCGClientForUser( userId: String, tokenInfo: TokenInfo? = nil, tokenStore: TokenStore? = nil ) async throws -> BoxClient
Parameters
userId
The user ID to use when getting the access token.
tokenInfo
Information about token
tokenStore
Custom token store. To use custom store, implement TokenStore protocol.
Return Value
The BoxClient object
-
getOAuth2Client(tokenInfo:
AsynchronoustokenStore: context: ) Creates BoxClient in a completion with OAuth 2.0 type of authentication
Throws
BoxSDKErrorDeclaration
Swift
func getOAuth2Client( tokenInfo: TokenInfo? = nil, tokenStore: TokenStore? = nil, context: ASWebAuthenticationPresentationContextProviding ) async throws -> BoxClient
Parameters
tokenInfo
Information about token
tokenStore
Custom token store. To use custom store, implement TokenStore protocol.
context
The ViewController that is presenting the OAuth request
Return Value
The BoxClient object
-
updateConfiguration(apiBaseURL:
uploadApiBaseURL: oauth2AuthorizeURL: maxRetryAttempts: tokenRefreshThreshold: consoleLogDestination: fileLogDestination: clientAnalyticsInfo: ) Updates current SDK configuration
Declaration
Swift
func updateConfiguration( apiBaseURL: URL? = nil, uploadApiBaseURL: URL? = nil, oauth2AuthorizeURL: URL? = nil, maxRetryAttempts: Int? = nil, tokenRefreshThreshold: TimeInterval? = nil, consoleLogDestination: ConsoleLogDestination? = nil, fileLogDestination: FileLogDestination? = nil, clientAnalyticsInfo: ClientAnalyticsInfo? = nil ) throws
Parameters
apiBaseURL
Base URL for majority of the requests.
uploadApiBaseURL
Base URL for upload requests. If not specified, default URL is used.
oauth2AuthorizeURL
URL for the OAuth2 authorization page, where users are redirected to enter their credentials
maxRetryAttempts
Maximum number of request retries in case of error result. If not specified, default value 5 is used.
tokenRefreshThreshold
Specifies how many seconds before token expires it shuld be refreshed. If not specified, default value 60 seconds is used.
consoleLogDestination
Custom destination of console log.
fileLogDestination
Custom destination of file log.
clientAnalyticsInfo
Custom analytics info that will be set to request header.
-
Creates OAuth2 authorization URL you can use in browser to authorize.
Declaration
Swift
public func makeAuthorizeURL(state: String? = nil) -> URL
Parameters
state
A text string that you choose. Box sends the same string to your redirect URL when authentication is complete. This parameter is provided for your use in protecting against hijacked sessions and other attacks.
Return Value
Standard URL object to be used for authorization in external browser.