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.

Discuss Dropbox Developer & API

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

[ObjC] Having trouble init'ing a UserClient with the new refresh token?

[ObjC] Having trouble init'ing a UserClient with the new refresh token?

Samikay
Explorer | Level 4
Go to solution

Quite likely missing something obvious, trying to migrate to the short-lived access tokens, so first change the authorize:

 

 

authorizeFromControllerV2

 

 

 save the refresh token:

 

 

_dropbox.accessToken = authResult.accessToken.accessToken;
_dropbox.refreshToken = authResult.accessToken.refreshToken;

 

 

at a later date, init the UserClient  

 

 

DBUserClient *dropboxClient = [[DBUserClient alloc] initWithAccessToken:_dropbox.accessToken];

 

 

 
But we can't supply a refresh token with this init method, so we should use 

 

 

initWithAccessTokenProvider:

 

 

 and implement id<DBAccessTokenProvider> 

 

 

/// Protocol for objects that provide an access token and offer a way to refresh (short-lived) token.
@protocol DBAccessTokenProvider <NSObject>

/// Returns an access token for making user auth API calls.
@property (nonatomic, readonly) NSString *accessToken;

/// This refreshes the access token if it's expired or about to expire.
/// The refresh result will be passed back via the completion block.
- (void)refreshAccessTokenIfNecessary:(DBOAuthCompletion)completion;

@end

 

 

 

I notice this is already implemented within the SDK in "DBAccessTokenProvider+Internal.h" but this isn't exposed, are we not expected to use this init? Or is the play to just init with a normal accessToken and capture an error then refresh manually ourselves? Seems odd seeing as it's already in the SDK. What am I missing?

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

We've added the ability to supply a DBAccessToken (which can contain a refresh token) directly which is available as of v6.2.0. Please give that a try and let us know if that doesn't work for you. Thanks!

View solution in original post

6 Replies 6

Greg-DB
Dropbox Staff
Go to solution

You shouldn't actually have to do most of this work in your own code. As long as you use the authorizeFromControllerV2 method to start the authorization flow as shown here, and then receive the result as shown here, the SDK would then handle the token storage and refresh process for you automatically. You would use the supplied authorizedClient as shown here to perform whatever calls you need.

 

Please give that flow a try and let me know if it's not working. Thanks!

Samikay
Explorer | Level 4
Go to solution

Hmm, unfortunately for our use case we have the user able to auth once on web/Android/iOS and be able to upload on any of those devices by sharing the Dropbox access token when they log into their (our app's) account (so we handle the storage of the tokens instead of the SDK and then init DBUserClients [or equivalent] on each platform), with long-lived tokens this was easy and worked nicely, short-lived makes it a tad more interesting. Based on your reply I'll yoink the internal code out and play around 😛

Samikay
Explorer | Level 4
Go to solution

Ah, I should mention when I implemented it in Android it was quite simple because DbxCredential takes a refresh token as an init parameter:

new DbxCredential(accessToken, 0L, refreshToken, DROPBOX_APP_KEY)
return new DbxClientV2(dropboxRequestConfig(), credential);

Hence why I was looking for the iOS equivalent 😄

Greg-DB
Dropbox Staff
Go to solution

I see, thanks for clarifying! I'll send this along as a request to the team to see if we can publicly expose something to do that in the Objective-C SK.

Samikay
Explorer | Level 4
Go to solution

Thanks Greg, I imagine it won't be too bad as the code is already there from what I can see although that is the definition of "famous last developer words". Cheers!

Greg-DB
Dropbox Staff
Go to solution

We've added the ability to supply a DBAccessToken (which can contain a refresh token) directly which is available as of v6.2.0. Please give that a try and let us know if that doesn't work for you. Thanks!

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    Samikay Explorer | Level 4
What do Dropbox user levels mean?