cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to know what we learned at IBC? Check out our learnings on media, remote working and more right 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: 

reauthorizeClient

reauthorizeClient

YanivB
Helpful | Level 6

Hi,

i get access token in my ios app using dropbox api.
i want to reauthenticate in the same app on other device using these access token. 

How can it be done (in Swift code lang) ? 

all works in the first device i did the all 
OAuth process, but not working when I try to reauthorizeClient with the access token from the first device...

1 Accepted Solution

Accepted Solutions

YanivB
Helpful | Level 6

You are awesome !

Thanks the guidance.

View solution in original post

12 Replies 12

Greg-DB
Dropbox Staff

The reauthorizeClient method would set the authorizedClient to use an access token that's already been stored. If you haven't stored the relevant access token, then that won't work. (The built-in OAuth functionality would automatically store the access token, but that won't occur automatically if you copied it from another device.)

 

To store an access token, you can use DropboxOAuthManager storeAccessToken, and then use reauthorizeClient.

YanivB
Helpful | Level 6

If I have the token (as string) can you share example how to use the DropboxOAuthManager storeAccessToken func ?

Greg-DB
Dropbox Staff

I don't believe we have example code for using that. Perhaps you could share the relevant piece of code you have so far and show what you're stuck on (e.g., any unexpected error/output)? Be sure to redact any actual access/refresh tokens though.

YanivB
Helpful | Level 6

1. This is the func for the dropboxOAuth process:

YanivB_0-1704405297514.png

2. after a success, i get the Token from here:

YanivB_1-1704405385842.png


3. Than when the app init, I use this reauthorizeClient : 

YanivB_2-1704405750818.png


From this point all works well.
The problem is only on the device that the dropboxOAuth process made, when trying on other device non works....

* You suggested to use the DropboxOAuthManager storeAccessToken.
But i dont see the storeAccessToken func gets as parameter a String for the Token value....

So I asked clarification from you please, how to use that func when I have the Token (As String) saved in my app.

thanks in advance!!!




 



Здравко
Legendary | Level 20

@YanivB wrote:

...
3. Than when the app init, I use this reauthorizeClient : 

YanivB_2-1704405750818.png

...


Hi @YanivB,

Why you decide that reauthorizeClient accepts access token? Take a closer look on method declaration and you'll see it accepts user ID (behind which there should be stored already some access token). In other words, you cannot pass access token in such a way.

By the way, passing access token with string (alone) will limit the time your application will be usable with a single token assignment. All access tokens at present are short lived! Just a reminding that for long term access you will need to deal with refresh token (eventually included within AccessToken object).

YanivB
Helpful | Level 6

Hi,

Regarding the "Why you decide that reauthorizeClient accepts access token?" question, because that is the only parameter (As String) i see from SDK that present:

YanivB_0-1704432515577.png

 

Здравко
Legendary | Level 20

@YanivB wrote:

..., because that is the only parameter (As String) i see from SDK that present:


Owo...🤦 You're killing the fish... 😁 Ok, 🤷 ...

@YanivB, Let's see what you have up to now: There is an only method that accepts string and that method doesn't work for you. 🤔

Doesn't it sound logical to move the focus from string to object? 🧐 There are methods to get AccessToken object (you have already used such a way; there are others too) and to set it back (as Greg useful proposed DropboxOAuthManager storeAccessToken) instead of using just string. Right? In mean time you can stringify such an object and store it in this form in the source place and after that build it back before use on the corresponding device as well as you can keep it in any other form (matter of choice and design decision, but the object state MUST be complete, not just some part). What would you say? 😉

YanivB
Helpful | Level 6

First , thank you all for trying to help!!

Sorry I am new to the swiftyDropbox and not all straight forward to me...

That is why I ask for code examples 🙏

 

Здравко
Legendary | Level 20

Ok, let see what you have already done. When your authentication succeeds, you're receiving DropboxAccessToken object and print it out. This object contains the actual access token, user id, refresh token, and token expiration timestamp. Unfortunately, when just printed (as you have done) it outputs only the access token string and skips everything else (incomplete data, so cannot restore it). Here you should take care to get access to everything as print everything out field by field. Once this got done you're gonna have everything needed (not just a part). I hope you don't need example for printing out of the data.

On the other side (other device), you can use available already data as something like:

let token = DropboxAccessToken(accessToken: accessToken, uid: userId,
      refreshToken: refreshToken, tokenExpirationTimestamp: expirationTimestamp)
DropboxOAuthManager.sharedOAuthManager.storeAccessToken(token)

 Again, you should already have accessToken, userId, refreshToken, and expirationTimestamp. 😉

Hope this helps.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    YanivB Helpful | Level 6
  • User avatar
    Здравко Legendary | Level 20
What do Dropbox user levels mean?