Skip to content

Latest commit

 

History

History
68 lines (61 loc) · 2.53 KB

Authentication.md

File metadata and controls

68 lines (61 loc) · 2.53 KB

Authentication

Single User Mode

The SDK can take care of all UI interaction for authenticating a user. If necessary, a View Controller will be presented from your app's window to collect credentials from the user.

BOXContentClient *contentClient = [BOXContentClient defaultClient];
[contentClient authenticateWithCompletionBlock:^(BOXUser *user, NSError *error) {
	// BOXUser is returned if authentication was successful.
	// Otherwise, error will contain the reason for failure (e.g. network connection)
} cancelBlock:^{
	// User canceled the authentication process.
}

Alternatively, if you prefer to present View Controllers on your own:

BOXContentClient *contentClient = [BOXContentClient defaultClient];
BoxAuthorizationViewController *boxAuthViewController = [[BoxAuthorizationViewController alloc] 
	initWithinitWithSDKClient:contentClient 
	completionBlock:^(BoxAuthorizationViewController *authorizationViewController, BOXUser *user, NSError *error) {
	// BOXUser is returned if authentication was successful.
	// Otherwise, error will contain the reason for failure (e.g. network connection)
	// You should dismiss authorizationViewController here.
} cancelBlock:^(BoxAuthorizationViewController *authorizationViewController){
	// User has canceled the login process.
	// You should dismiss authorizationViewController here.
}];
[self presentViewController:boxAuthViewController animated:YES completion:nil];

When you no longer need the session, it is a good practice to logout.

BOXContentClient *contentClient = [BOXContentClient defaultClient];
[contentClient logOut]

Multi-Account Mode

Check for existing Box Users that the SDK has authenticated.

NSArray *boxUsers = [BOXContentClient users];

Get a BOXContentClient for an existing Box User that the SDK has authenticated

for (BOXUser *boxUser in boxUsers) {
	BOXContentClient *contentClient = [BOXContentClient clientForUser:boxUser];
	// You can now do something with the contentClient...
}

Authenticate a new account:

BOXContentClient *contentClient = [BOXContentClient clientForNewSession];
[contentClient authenticateWithCompletionBlock:^(BOXUser *user, NSError *error) {
	// BOXUser is returned if authentication was successful.
	// Otherwise, error will contain the reason for failure (e.g. network connection)	
} cancelBlock:^{
	// User canceled the authentication process.
}

Log all users out.

[BOXContentClient logOutAll];