<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Facing problems getting the Access Token from a user on Windows Form in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Facing-problems-getting-the-Access-Token-from-a-user-on-Windows/m-p/205711#M9953</link>
    <description>(By the way, you should switch back to the original authorizeUri line to test the desired redirect flow.)</description>
    <pubDate>Tue, 07 Feb 2017 23:19:28 GMT</pubDate>
    <dc:creator>Greg-DB</dc:creator>
    <dc:date>2017-02-07T23:19:28Z</dc:date>
    <item>
      <title>Facing problems getting the Access Token from a user on Windows Form</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Facing-problems-getting-the-Access-Token-from-a-user-on-Windows/m-p/205702#M9950</link>
      <description>&lt;P&gt;Hi there:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I actually &lt;A href="http://stackoverflow.com/questions/42091844/grabbing-dropbox-access-token-on-windows-form-using-dropbox-api" target="_blank"&gt;asked this on StackOverflow&lt;/A&gt; but I got no answer yet. The thing is that I'm trying to generate the access token from the user but I can't "capture" the generated token and I'm afraid that asking for permission generates a new access token everytime, so the previous one remains invalid.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The point is that my code is not even entering on the try catch part. I'm still guessing what am I doing wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;private void Start(string appKey, WebBrowser w)&lt;BR /&gt;{&lt;BR /&gt;    this.oauth2State = Guid.NewGuid().ToString("N");&lt;BR /&gt;    //This one finally sha token on the WebClient&lt;BR /&gt;    Uri authorizeUri2 = DropboxOAuth2Helper.GetAuthorizeUri(appKey);&lt;BR /&gt;    //This one just shown a blank screen (I guess it stucks on the redirect)&lt;BR /&gt;    //Uri authorizeUri = DropboxOAuth2Helper.GetAuthorizeUri(OauthResponseType.Token, appKey, redirectUrl, state: oauth2State);&lt;BR /&gt;    w.Navigate(authorizeUri2);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;private void Browser_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
    if (!e.Url.ToString().StartsWith(redirectUrl, StringComparison.InvariantCultureIgnoreCase))
    {          
        // we need to ignore all navigation that isn't to the redirect uri.
        return;
    }

    try
    {
        OAuth2Response result = DropboxOAuth2Helper.ParseTokenFragment(e.Url);
        if (result.State != this.oauth2State)
        {
            // The state in the response doesn't match the state in the request.
            return;
        }

        this.AccessToken = result.AccessToken;
        this.Result = true;
    }
    catch (ArgumentException)
    {
        // There was an error in the URI passed to ParseTokenFragment
    }
    finally
    {
        e.Cancel = true;
        this.Close();
    }&lt;BR /&gt;}&lt;/PRE&gt;
&lt;P&gt;The complete code is on StackOverflow. Sorry for disturbing, but I would really appreciate some help here understanding what's happening. I'm getting too much headaches with this problems related with OAuth2&amp;nbsp;&lt;img class="lia-deferred-image lia-image-emoji" src="https://www.dropboxforum.com/html/@441FE98CC6341A8F74FE470957BBC453/images/emoticons/1f625.png" alt=":disappointed_relieved:" title=":disappointed_relieved:" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance,&lt;/P&gt;
&lt;P&gt;Gonzo345.&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2019 09:26:07 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Facing-problems-getting-the-Access-Token-from-a-user-on-Windows/m-p/205702#M9950</guid>
      <dc:creator>Gonzo345</dc:creator>
      <dc:date>2019-05-29T09:26:07Z</dc:date>
    </item>
    <item>
      <title>Re: Facing problems getting the Access Token from a user on Windows Form</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Facing-problems-getting-the-Access-Token-from-a-user-on-Windows/m-p/205710#M9952</link>
      <description>Where does it fail exactly? You mentioned it doesn't get to the try/catch, so a good next step in debugging that would be to check if the Browser_Navigating method gets called at all. If it does, check what's happening with that if condition at the beginning of it.</description>
      <pubDate>Tue, 07 Feb 2017 23:18:13 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Facing-problems-getting-the-Access-Token-from-a-user-on-Windows/m-p/205710#M9952</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2017-02-07T23:18:13Z</dc:date>
    </item>
    <item>
      <title>Re: Facing problems getting the Access Token from a user on Windows Form</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Facing-problems-getting-the-Access-Token-from-a-user-on-Windows/m-p/205711#M9953</link>
      <description>(By the way, you should switch back to the original authorizeUri line to test the desired redirect flow.)</description>
      <pubDate>Tue, 07 Feb 2017 23:19:28 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Facing-problems-getting-the-Access-Token-from-a-user-on-Windows/m-p/205711#M9953</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2017-02-07T23:19:28Z</dc:date>
    </item>
    <item>
      <title>Re: Facing problems getting the Access Token from a user on Windows Form</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Facing-problems-getting-the-Access-Token-from-a-user-on-Windows/m-p/205760#M9962</link>
      <description>&lt;P&gt;Hi Greg:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used the overloaded DropboxOAuth2Helper.GetAuthorizeUri(appKey)&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Uri authorizeUri2 = DropboxOAuth2Helper.GetAuthorizeUri(appKey);&lt;/PRE&gt;
&lt;P&gt;and I got a token which I manually copied but the DropboxClient constructor says there is an AuthException.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At this point&amp;nbsp;I'm manually going to the&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;https://www.dropbox.com/1/oauth2/authorize?response_type=code&amp;amp;client_id=appKey&lt;/PRE&gt;
&lt;P&gt;on the main browser and granting the access, copying and pasting the showing token as well, with same ending: AuthException. At the Applications section on the user's account I can see it says "pending".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I guess is here&lt;/P&gt;
&lt;PRE&gt;OAuth2Response resultTest = DropboxOAuth2Helper.ParseTokenFragment(webBrowser1.Url);
this.AccessToken = resultTest.AccessToken;&lt;/PRE&gt;
&lt;P&gt;where magic happens, but then... what is that token which is being shown on screen used for?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's not a problem for me asking the user for manually copying and pasting the token, but I hope I can get a working one lol&lt;img class="lia-deferred-image lia-image-emoji" src="https://www.dropboxforum.com/html/@BB156BE64F7B6DF6C334DBEE4A42A0C3/images/emoticons/1f62d.png" alt=":sob:" title=":sob:" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for all in advance. There must be something stupid that I'm doing wrong...&lt;/P&gt;
&lt;P&gt;Gonzo345.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;P.S: the appKey is "&lt;SPAN&gt;2ehnws5uxtu4unm" so I use the&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;https://www.dropbox.com/1/oauth2/authorize?response_type=code&amp;amp;client_id=2ehnws5uxtu4unm &lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;link, grant access and get a useless token&lt;img class="lia-deferred-image lia-image-emoji" src="https://www.dropboxforum.com/html/@441FE98CC6341A8F74FE470957BBC453/images/emoticons/1f625.png" alt=":disappointed_relieved:" title=":disappointed_relieved:" /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;EDIT&lt;/STRONG&gt;: Switching back to the original AuthorizeUri as you stated, I've noted that if I access to that link I posted with the&amp;nbsp;appKey, it doesn't get registered as a development user... and one more thing: the Enum "OauthResponseType.Token" on the&amp;nbsp;GetAuthorizeUri method... is it probablly misspeled? Since I needed to change it to&amp;nbsp;OAuthResponseType.Token&amp;nbsp;&lt;img class="lia-deferred-image lia-image-emoji" src="https://www.dropboxforum.com/html/@86FF27E33EE6AE58E01795BD66324A7F/images/emoticons/1f914.png" alt=":thinking:" title=":thinking:" /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Debugging the conditional on Browser_Navigating after logging in:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if (!webBrowser1.Url.ToString().StartsWith(redirectUrl, StringComparison.InvariantCultureIgnoreCase))
{
        // we need to ignore all navigation that isn't to the redirect uri.
        return;
}&lt;/PRE&gt;
&lt;PRE&gt;e.Url =&amp;nbsp;{https://www.dropbox.com/1/oauth2/authorize?client_id=2ehnws5uxtu4unm&amp;amp;redirect_uri=https:%2F%2Fwww.dropbox.com%2F1%2Foauth2%2Fredirect_receiver&amp;amp;response_type=token&amp;amp;state=b58e5da520cc481e879900c1d6ffdeb6}
webBrowser1.Url = {https://www.dropbox.com/1/oauth2/authorize?response_type=token&amp;amp;client_id=2ehnws5uxtu4unm&amp;amp;redirect_uri=https:%2F%2Fwww.dropbox.com%2F1%2Foauth2%2Fredirect_receiver&amp;amp;state=b58e5da520cc481e879900c1d6ffdeb6}&lt;/PRE&gt;
&lt;P&gt;So of course none of them StartsWith(redirectUrl), which is&amp;nbsp;&lt;A href="https://www.dropbox.com/1/oauth2/redirect_receiver" target="_blank"&gt;https://www.dropbox.com/1/oauth2/redirect_receiver&lt;/A&gt; and all I get is a blank screen and no way to apply the&amp;nbsp;DropboxOAuth2Helper.ParseTokenFragment method. If I manually try to apply the ParseTokenFragment debugging it, of course throws an ArgumentException.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, debugging looks like the authorizeUri is correctly formed:&lt;/P&gt;
&lt;PRE&gt;authorizeUri = https://www.dropbox.com/1/oauth2/authorize?response_type=token&amp;amp;client_id=2ehnws5uxtu4unm&amp;amp;redirect_uri=https:%2F%2Fwww.dropbox.com%2F1%2Foauth2%2Fredirect_receiver&amp;amp;state=155fb42d3bef4908b5ae6cff14b5cc0f&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;EDIT 2:&lt;/STRONG&gt; This is getting totally mindblowing... I've tried the previous token that it was invalid (this one)&lt;/P&gt;
&lt;PRE&gt;https://www.dropbox.com/1/oauth2/authorize?response_type=code&amp;amp;client_id=2ehnws5uxtu4unm&lt;/PRE&gt;
&lt;P&gt;and IT'S WORKING &lt;A href="https://github.com/nicoco007/DotNetBox.Samples" target="_self"&gt;on this project&lt;/A&gt;, which uses DotNetBox but not with the official Dropbox API, which basically says "invalid_access_token" . Somebody please throw some light here because I'm getting kinda' crazy with all this Token things.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've already tried the WPF "Simple_test" and it's working, but is there any Windows Forms example working? I can see that my redirect_uri is not working, basically. It gets stuck and says "page not found 404". Could it be something related with the WebBrowser? I've tried modifying some options with no luck...&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 18:35:40 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Facing-problems-getting-the-Access-Token-from-a-user-on-Windows/m-p/205760#M9962</guid>
      <dc:creator>Gonzo345</dc:creator>
      <dc:date>2017-02-08T18:35:40Z</dc:date>
    </item>
    <item>
      <title>Re: Facing problems getting the Access Token from a user on Windows Form</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Facing-problems-getting-the-Access-Token-from-a-user-on-Windows/m-p/205878#M9974</link>
      <description>&lt;P&gt;You can retrieve an access token from the OAuth flow either using or not using a redirect URL, as you saw, but we&amp;nbsp;recommend using a redirect URL when you can, as it streamlines the process.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(For reference, if you do copy/paste the code, note that that's an "authorization code" and not an "access token". You need to exchange it for an access token.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, for the redirect version, it looks like you're seeing the event for the load of the /authorize page itself. That one should be ignored, as you're actually looking for the load after the user clicks to authorize the app, and is sent to the redirect URI. Is that event not firing at all for you?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, I notice you're using the "Navigating" event. You may want to try the "Navigated" event instead to see if that works better in your case. (We had a blog post about this &lt;A href="https://blogs.dropbox.com/developers/2014/04/dropbox-authorization-in-a-windows-forms-app/" target="_self"&gt;here&lt;/A&gt;, although it&amp;nbsp;wasn't written for use with the newer .NET SDK itself.)&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 19:36:26 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Facing-problems-getting-the-Access-Token-from-a-user-on-Windows/m-p/205878#M9974</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2017-02-08T19:36:26Z</dc:date>
    </item>
    <item>
      <title>Re: Facing problems getting the Access Token from a user on Windows Form</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Facing-problems-getting-the-Access-Token-from-a-user-on-Windows/m-p/205936#M9981</link>
      <description>&lt;P&gt;Holy s***, that was it. I changed the Navigated event and it was like magic...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I feel like a dumb, but it's finally working. It feels really weird, but it was worthy. I guess I wasn't thinking clear due to working all the time on this glitchy thing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks Greg!&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 23:30:53 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Facing-problems-getting-the-Access-Token-from-a-user-on-Windows/m-p/205936#M9981</guid>
      <dc:creator>Gonzo345</dc:creator>
      <dc:date>2017-02-08T23:30:53Z</dc:date>
    </item>
  </channel>
</rss>

