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: 

Re: SwiftyDropbox: "Client is already authorized"

SwiftyDropbox: "Client is already authorized"

George M.33
New member | Level 1

I am calling setupWithAppKey in application:didFinishLaunching. Seems fine.

Then, I call Dropbox.authorizeFromController from my viewController, and I immediately get this error: 

precondition failed: Client is already authorized: file /Users/gmadrid/Desktop/feedfile/Pods/SwiftyDropbox/Source/DropboxClient.swift, line 58

It I comment out the precondition on line 58, I get bit in handleRedirectURL() at line 64. Same error.

Looking at the code, I see why it breaks. setupWithAppKey sets the "authorizedClient" at line 51, so that precondition is always doomed to fail. 

Any thoughts on how to proceed or what I might be doing wrong?

Thanks,

George

 

6 Replies 6

George M.33
New member | Level 1

Follow up.

Commenting out the preconditions at lines 58 and 64 results in everything seeming to work. I am able to successfully make a call to filesListFolder.

Also, the token that it's finding at line 50 (DropboxAuthManager.sharedAuthManager.getFirstAccessToken()) belongs to uid "engine-state"

Thanks.

-g

 

Steve M.
Dropbox Staff

That class is meant to be used in the case where there's only a single user being authorized.

Are you trying to authorize multiple users? If so, you'll need to use the DropboxAuthManager directly.

If you do just want a single user (but want to forget about the user who's already been authorized), you can use unlinkClient.

George M.33
New member | Level 1

Thanks for the suggestion. I'm only using a single user.

I _think_ this is related to using the simulator for debugging, but I'm not sure. Tracing through the code on a brand-new reset simulator finds two entries already in the keychain. These are what are screwing things up. 

Things seem to work fine on a device.

I have patched in a workaround in my local copy of the SwiftyDropbox code. This workaround is entirely unsuitable for submission, but it's gotten me unblocked.

 

Leah C.1
New member | Level 1

Did you previously try out the Swift SDK in the simulator? That would explain having entries already in the keychain. I'm not sure why they wouldn't be deleted when resetting the simulator though... that's odd.

You can always use `Dropbox.unlinkClient()` in your code to clear the credentials.

This shouldn't affect running the code on a device or with other users.

George M.33
New member | Level 1

Hi Leah,

Thanks for your response. I've tried resetting and unlinkClient(). Neither one helps the situation. I have a sneaky suspicion that it has something to do with the particular machine that I'm on, because it seems to all work on my laptop (but not my desktop). My suspicion is that the data in my desktop's keychain is interfering with the responses in the simulator. Some of the stuff that I've read (in StackOverflow for e.g.) suggests that keychain is broken in the simulator.

I'll play with it a little and see if I can repro on my laptop. Then I'll have some instructions for y'all.

Thanks,

-g

 

Leah C.1
New member | Level 1

Reply if you find out anything new... it would be super helpful!

Need more support?