3

In the V1 iOS SDK it was possible to logout the current user as follows:

 [Box logoutWithCallbacks:^(id <BoxOperationCallbacks> on)
 {
     on.after(^(BoxCallbackResponse response)
              {
              });
 }];

How is it done using the V2 SDK?

Undo
  • 25,519
  • 37
  • 106
  • 129
pstoppani
  • 2,531
  • 1
  • 20
  • 20

4 Answers4

3

Here's what I do:

BoxSDK *sdk = ... // a reference to the BoxSDK for the user
sdk.OAuth2Session.accessToken = @"INVALID_TOKEN";
sdk.OAuth2Session.refreshToken = @"INVALID_TOKEN";

That's it. The next time you try to do anything with the user's session you will be forced to log in again.

Update - you can see this in action in the Box sample app at https://github.com/box/box-ios-sdk-sample-app. Look at the BoxFolderViewController.m file.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • Note that this does NOT revoke the OAuth2 tokens on the server, it only removes your app's reference to them. Adding a logout+revoke to BoxOAuth2Session is something we'd like to add to the SDK. We're tracking it here: https://github.com/box/box-ios-sdk-v2/issues/65 – Ryan Lopopolo Jan 13 '14 at 05:28
  • I'm having a problem with this. I want to be able to distinguish when a user's account is not logged in, and when a file download fails for another reason (e.g. file was deleted). I use sdk.OAuth2Session.isAuthorized for the former check, and the failure block in downloadFileWithId for the latter. However, after I "log out" as shown above, isAuthorized continues to return true, so now, my code thinks the file download failed because something else was wrong. – Rob Mar 27 '14 at 21:09
  • To work around the issue I describe above, I now use the following check (sdk.OAuth2Session.isAuthorized && ![sdk.OAuth2Session.accessToken isEqualToString:@"INVALID_TOKEN"]). I'm not sure if this is the best approach but it seems works so far. @RyanLopopolo, is there a better way to check for this? Also, thank your for your work with this SDK! – Rob Mar 27 '14 at 21:10
  • sdk.OAuth2Session.isAuthorized compares the current time stamp to the expiration timestamp of the OAuth2 tokens returned during the last token refresh. If you are mucking around with OAuth2Session state, you should not expect this call to be accurate. The isAuthorized call is *already* inaccurate because OAuth2 tokens can be revoked externally by users and admins via the API and web application. – Ryan Lopopolo Mar 29 '14 at 00:58
1

This is how to logout correctly

[BoxSDK sharedSDK].OAuth2Session.accessToken = nil;
[BoxSDK sharedSDK].OAuth2Session.refreshToken = nil;
Will
  • 1,697
  • 17
  • 34
1

This is how it's done with the latest SDK from https://github.com/box/box-ios-sdk

[BOXContentClient logOutAll];
gregyoung14
  • 347
  • 3
  • 8
0

swift version answer for logout box sdk session *

   boxClient.destroy { (res) in
                
   }
   boxClient = nil
Jagveer Singh
  • 2,258
  • 19
  • 34