cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Share your feedback on the Document Scanning Experience in the Dropbox App 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: 

Switching users in app

Switching users in app

knight2601
Explorer | Level 3

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 10

xtremebytes
Explorer | Level 3

@Grek K. thanks, I see your point about inconvenience. I am probably looking at it from a use-case where the user wants to disable the Dropbox integration and be presented with a user login screen when re-enabled again because it is likely to be disabled with the intent to switch users. There is a slight chance that the user may accidentally overlook the small sign-out link on the re-approval page, and still re-approve as the previously signed-in user. So, perhaps, it does make more sense in my app to set 'forceReauthentication'.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    xtremebytes Explorer | Level 3
  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    nairababayan Explorer | Level 3
What do Dropbox user levels mean?