Need to see if your shared folder is taking up space on your dropbox 👨‍💻? Find out how to check here.

Forum Discussion

Nenciu D.'s avatar
Nenciu D.
New member | Level 1
11 years ago

How to get access token from browser?

Hi,

I'm using your new .net sdk v2 Dropbox.Api . I want to open the browser with authorize uri , then login and then get all the uri and parse it with your function called ParseTokenFragment(). It is possible?

Or maybe is another solution . All I want is to avoid creating a WebBrowser control in my application and then calling Navigating event for it.

Thank you

7 Replies

Replies have been turned off for this discussion
  • What we usually suggest is to use the WebBrowser control. Why are you trying to avoid that?

  • Nenciu D.'s avatar
    Nenciu D.
    New member | Level 1
    11 years ago

    Thanks for answering Steve. I just want to use a button connect and then a browser tab to open for log in ( in Internet Explorer for example ) and after the login to store the access token in my app. Is this possible ? Same thing is done by this function of Google Drive : 
    GoogleWebAuthorizationBroker.AuthorizeAsync(ClientSecret, scopes, Environment.UserName, CancellationToken.None, new SavedDataStore(GoogleTokenStoredResponse)).Result

     

  • We don't have anything like that built in. We encourage people to use an embedded web browser in their app.

  • Nenciu D.'s avatar
    Nenciu D.
    New member | Level 1
    11 years ago

    Hi Steve,

    I tried to do something like this to get the uri ,but in my response I don't get the new uri, which contains the access token .

    Uri uri = new Uri("https://api.dropboxapi.com/1/oauth2/authorize?response_type=token&client_id=my_client_id");
    System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri);
    request.Method = System.Net.WebRequestMethods.Http.Post;

    System.Net.WebResponse response = request.GetResponse();

    Am I missing something or this is not correct?

    PS: If i create a uri like https://www.dropbox.com/1/oauth2/authorize?response_type=token&client_id=my_client_id&redirect_uri=my_uri , I get a new uri like this my_redirect_uri/#access_token=dhGV8R5SRjIDDDDDDa8xOY5JXtDiTahVAg4I9eP3gsvtJqxuyc_OKfM7iTYfd&token_type=bearer&uid=2623212259 . This is the uri which I want to get with my request.

    Thank you

  • Nenciu D.'s avatar
    Nenciu D.
    New member | Level 1
    11 years ago

    Yes . I tried this one(my first try). Currently I'm using this method:

     Uri authorizeUri = DropboxOAuth2Helper.GetAuthorizeUri(OauthResponseType.Token, appKey, RedirectUri, state: oauth2State);

    And then I called  System.Diagnostics.Process.Start(authorizeUri.ToString()) to open the browser with authorizeUri. Next step is that the user copies the responseUri to a textbox and then I have another button GetTokenBtn which calls ParseTokenFragment(responseUri) to obtain the token. 

    Simply said , what I  wanted was to open a the browser,which contains the authentification(email and password of dropbox user to skip authentification) with authorize uri , then the resulting uri(responseUri) from the browser to be sent back to my application and then to call from my application ParseTokenFragment(responseUri) to obtain my token.

    If that is not possible without searching into opened processes that will remain my solution.

    Thanks for your support 

  • You can theoretically do this by registering for a custom URL scheme and using that as your redirect URI, but what we recommend is to embed a web browser control in your app, as per the example I linked to.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

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, Facebook or Instagram.

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!