cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to re-link a user in API 2 (Handling Revoked Access Etc)

How to re-link a user in API 2 (Handling Revoked Access Etc)

Keith B.7
Helpful | Level 7
Go to solution

In API 1, I could offer the user an option to re-link (re-authorise) Dropbox if they run into issues because their access token had expired or been revoked. I could do this as follows:

 

First, I listened for the DBSession delegate method:

 

- (void)sessionDidReceiveAuthorizationFailure:(DBSession * )session userId:(NSString * )userId

 

Then, if I received this notification, I did two things:

 

1. Offer the user the chance to re-link Dropbox then and there (given that re-linking should be all that is required, as described in Core API Best Practises: <https://www.dropbox.com/developers-v1/core/bestpractices>).

 

2. Make note in a flag that there had been a session authorisation failure. Then, in a sync options menu, if this flag was YES, I would offer a "Re-Link Dropbox" option. In both cases, I could just call:

 

NSArray *userIds = [[DBSession sharedSession] userIds];
if (userIDs.count > 0)
    [[DBSession sharedSession] linkUserId:userIds[0] fromController:self];

Or, when calling this directly from the DBSession delegate method, I could pass in the userId directly because it was a parameter in the delegate method:

 

[[DBSession sharedSession] linkUserId:userId fromController:self];

 

What is the equivalent for re-linking following an authorisation failure owing to a revoked or expired access token in API 2?

 

At first I thought it was DropboxClientManager's -reauthorizeClient:, but that relies on grabbing the access token from [[DropboxClientsManager authorizedClient] transportClient].accessToken], and that won't be available (I believe) if authorisation has failed. And anyway, I believe this uses the very access token which has expired or been revoked in this situation. (In which case, what is -reauthorizeClient: for?)

 

Do I just call -authorizeFromController:controller:openURL:browserAuth: again to re-link in API 2, the same as for linking in the first place? Or is there a dedicated method like there was in API 1?

 

Thanks!

Keith

 

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

That's right. There's a simple example here, but you may want to handle the more specific cases (e.g., invalid access token versus suspended user) in the DBAUTHAuthError.

View solution in original post

4 Replies 4

Greg-DB
Dropbox Staff
Go to solution

That's right, reauthorizeClient isn't for this case. That's meant for when you want to retrieve an authorized client for a user account for which you already have an access token.

 

For the revoked access token case, you can just catch the authorization failure (the InvalidAccessToken DBAUTHAuthError from DBRequestAuthError) and then call authorizeFromController again to have the user re-link and get a new access token.

Keith B.7
Helpful | Level 7
Go to solution

Great, thanks for the clarification. So, instead of an equivalent of DBSession's -sessionDidReceiveAuthorizationFailure: delegate method, I check for DBError's -isAuthFailure in the response of any of the Dropbox requests? That makes sense, thanks!

Greg-DB
Dropbox Staff
Go to solution

That's right. There's a simple example here, but you may want to handle the more specific cases (e.g., invalid access token versus suspended user) in the DBAUTHAuthError.

Keith B.7
Helpful | Level 7
Go to solution

Great, thanks. Following your advice, I've got checking for revoked access and re-linking all working - much appreciated!

 

All the best,
Keith

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Keith B.7 Helpful | Level 7
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?