Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to logout user with v2 API? #92

Closed
kkontus opened this issue Feb 14, 2017 · 10 comments
Closed

How to logout user with v2 API? #92

kkontus opened this issue Feb 14, 2017 · 10 comments

Comments

@kkontus
Copy link

kkontus commented Feb 14, 2017

Is it possible to logout current user so new user can login through v2 API?

@cakoose
Copy link
Contributor

cakoose commented Feb 14, 2017

What do you mean by "log out"? Are you writing a mobile/web app and you want to connect to a different Dropbox account? Or are you talking about logging someone out of the Dropbox website?

@kkontus
Copy link
Author

kkontus commented Feb 14, 2017

I'm writing an Android app from which user can upload some photos and stuff. So user log in through Java Dropbox APIv2 and everything works great. But let's say he wants to login with another Dropbox account, how can he log out/sign out (whatever you prefer) so he can use another user account. For now I'm just removing AccessToken from the SharedPrefs and run Auth.startOAuth2Authentication(..., ...) again, but I'm not sure if that is a correct way because that doesn't really log out user from the server. So how can I get the same behavior that I have when I click Sign out from browser on www.dropbox.com?

@cakoose
Copy link
Contributor

cakoose commented Feb 14, 2017

What you are doing is correct.

If you also want the Dropbox API server to delete its copy of the access token, call /disable_access_token. In the Java SDK, this is DbxUserAuthRequest.tokenRevoke().

@kkontus
Copy link
Author

kkontus commented Feb 15, 2017

Works like a charm, thanks a mill. I'm closing this since it's solved now.

@kkontus kkontus closed this as completed Feb 15, 2017
@kkontus
Copy link
Author

kkontus commented Feb 15, 2017

@cakoose there is one more thing that has to be done in order for user to be Sign out on Android. We need to set DbxClientV2 sDbxClient = null; and set AuthActivity.result = null; otherwise old client will be reused and calling accessToken = Auth.getOAuth2Token(); in onResume() will return old token. So here is what I did, maybe it can help someone:

Called:

  1. DbxUserAuthRequests.tokenRevoke(); - to revoke token on the server
  2. cleared SharedPrefs locally (the ones that are checked in hasToken() method)
  3. set DropboxFactory client to null since new GetCurrentAccountTask(DropboxClientFactory.getClient(), new GetCurrentAccountTask.Callback() { ... } would reuse old client that is initialized with a token that is now revoked, and onError() callback method would be called.
    since DbxClientV2 sDbxClient is private I created a new method inside DropboxClientFactory as
public static void clearClient() {
    sDbxClient = null;
}
  1. AuthActivity.result = null; which prevents restoring accessToken from DropboxApi internal SharedPrefs using accessToken = Auth.getOAuth2Token(); in onResume()

I hope it helps someone.
Cheers

@androidovshchik
Copy link

@kkontus
DbxUserAuthRequests.tokenRevoke(); is not a static method today. So the only way is something like this:
new DbxUserAuthRequests(/* here is needed a DbxRawClientV2 client */).tokenRevoke();
So on android i cannot find the way to receive an instance of DbxRawClientV2 class
Can you help?

@greg-db
Copy link
Contributor

greg-db commented May 29, 2017

@mr-cpp You should be able to call that with a DbxClientV2, like this, where client is a DbxClientV2:

client.auth().tokenRevoke();

If that's not working for you though, feel free to open a new issue with details so we can help.

@androidovshchik
Copy link

androidovshchik commented May 31, 2017

@greg-db
Thank you
It works. But it requires async execution, so i wrote a simple class RevokeToken for execution Dropbox API
https://gist.github.com/androidovshchik/3a5d39430f1f1506abe0257f352e70b7

@panovvitalik
Copy link

@greg-db
I called client.auth().tokenRevoke(); - It's not working: current user is not logged out
Version: com.dropbox.core:dropbox-core-sdk:3.1.5

How I can resolve this issue?

@greg-db
Copy link
Contributor

greg-db commented Sep 14, 2020

@panovvitalik I see you also opened a new issue for this, so I'll follow up with you there: #290

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants