Take Your Search Game to the Next Level with Dropbox Dash 🚀✨ Curious how it works? Ask us here!
Forum Discussion
knight2601
9 years agoExplorer | Level 3
Switching users in app
Hi All
is it possible (in a test app) to login as user 1, view files etc, then log out and log in as user 2, view their files etc?
My app is using an OAuth2 flow in .net, its a windows forms app.
during the authentication routine, it opens a browser window and presents the login page. the access token is then kept to validate operations.
when logging out, i remove the access token (set to string.empty), in addition - ive also sent a TokenRevokeAsync request. after awaiting that event it loads up the login browser and immediately restores the previous access token.
Im using the Developer API for .net (official)
the method on the login form(browser) that is called, is:
Public Sub Start(ByVal appKey As String) Me.oauth2State = Guid.NewGuid().ToString("N") Dim authorizeUri = DropboxOAuth2Helper.GetAuthorizeUri(OAuthResponseType.Token, appKey, New Uri(RedirectUri), oauth2State, False, False) Me.Browser.Navigate(authorizeUri) End Sub
then:
Private Sub BrowserNavigating(ByVal sender As Object, ByVal e As NavigatingCancelEventArgs) If (Not e.Uri.ToString().StartsWith(RedirectUri, StringComparison.OrdinalIgnoreCase)) Then ' we need to ignore all navigation that isn't to the redirect uri. Return End If Try Dim Result As OAuth2Response = DropboxOAuth2Helper.ParseTokenFragment(e.Uri) If (Result.State <> Me.oauth2State) Then Return End If Me.AccessToken = Result.AccessToken Me.Uid = Result.Uid Me.Result = True Catch eww As ArgumentException ' There was an error in the URI passed to ParseTokenFragment Finally e.Cancel = True newAttempt = False Me.Browser.Navigate("about:blank") ' nav away Me.Hide() End Try End Sub
Could anyone suggest anything to make this work?
BTW: on first run, there is no credential stored so i know this is something to do with cached credentials.
10 Replies
Sort By
- Greg-DB
Dropbox Staff
You can certainly switch users by switching access tokens, as you're attempting to do. It sounds like the issue is that when you direct the user to authorize the app a second time, they're being automatically redirected back to your app, along with a (new) access token for that same account.
This can happen if the user is still logged in to the Dropbox web site and has already authorized the API app.
If instead you want to avoid this behavior and make sure the user has a chance to switch accounts, you can set the forceReapprove parameter to true on DropboxOAuth2Helper.GetAuthorizeUri:
- knight2601Explorer | Level 3
Hi, I've tried that, it just auths them in to that same account but asks for permission to connect to their dropbox.
i've tried deleting local cookies, creating new browser controls (incase it was an IE caching issue) to no avail.
It's being cached in the app/api somewhere, if i close the app and reload it, its clean and prompts for login with no token, does the API cache the last key and return it instead of a new auth run?
Andy
- Greg-DB
Dropbox Staff
You didn't mention where/when you actually switched accounts. Did you do so? When using forceReapprove=true, you would need to manually (as the user on the Web site) switch the account you're logged in to by logging out and then logging in as the other account, before authorizing the app again.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,997 PostsLatest Activity: 11 minutes ago
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!