<?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: ASP.NET MVC refresh token for DropBox have an error invalid_grant in Discuss Dropbox Developer &amp; API</title>
    <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/ASP-NET-MVC-refresh-token-for-DropBox-have-an-error-invalid/m-p/659389#M3195</link>
    <description>&lt;P&gt;[Cross-linking for reference: &lt;A href="https://stackoverflow.com/questions/75426433/asp-net-mvc-refresh-token-for-dropbox-have-error-invalid-grant" target="_blank"&gt;https://stackoverflow.com/questions/75426433/asp-net-mvc-refresh-token-for-dropbox-have-error-invalid-grant&lt;/A&gt; ]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An 'invalid_grant' error can indicate that the values you're supplying to &lt;A href="https://dropbox.github.io/dropbox-sdk-dotnet/gh-pages/obj/api/Dropbox.Api.DropboxOAuth2Helper.html#Dropbox_Api_DropboxOAuth2Helper_ProcessCodeFlowAsync_System_String_System_String_System_String_System_String_HttpClient_System_String_" target="_blank"&gt;ProcessCodeFlowAsync&lt;/A&gt; are incorrect/invalid, or that they don't match the configuration used with &lt;A href="https://dropbox.github.io/dropbox-sdk-dotnet/gh-pages/obj/api/Dropbox.Api.DropboxOAuth2Helper.html#Dropbox_Api_DropboxOAuth2Helper_GetAuthorizeUri_Dropbox_Api_OAuthResponseType_System_String_System_String_System_String_System_Boolean_System_Boolean_System_String_System_Boolean_Dropbox_Api_TokenAccessType_System_String___Dropbox_Api_IncludeGrantedScopes_System_String_" target="_blank"&gt;GetAuthorizeUri&lt;/A&gt; to get that particular authorization.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, in the version of the code you shared here, you're setting the first parameter to "&lt;A href="http://127.0.0.1:52475/" target="_blank"&gt;http://127.0.0.1:52475/&lt;/A&gt;", which would be incorrect as that's neither an authorization code nor a redirect URI containing an authorization code, i.e., "responseUri". I see that the code in your StackOverflow post is different though, and does seem to contain the resulting redirect URI for the responseUri parameter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or, for instance, if you set a "redirectUri" when calling GetAuthorizeUri, you need to supply that same redirectUri to ProcessCodeFlowAsync to validate that request. That is, in addition to setting the responseUri parameter on ProcessCodeFlowAsync, you should set redirectUri as well (matching the redirectUri value you gave to GetAuthorizeUri). Or, if you didn't set a redirectUri when calling GetAuthorizeUri, you shouldn't set redirectUri when calling ProcessCodeFlowAsync.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, note that authorizations codes are only valid for a few minutes, and can only be used once each. You can store and re-use the resulting refresh tokens though; refresh tokens can be re-used and don't expire. Once you have a refresh token for an account, you don't need to run the authorization flow (GetAuthorizeUri and ProcessCodeFlowAsync) for that account again. You would just make the DropboxClient with the app key/secret and refresh token.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Refer to the documentation linked above for information on using these methods, and &lt;A href="https://github.com/dropbox/dropbox-sdk-dotnet/tree/main/dropbox-sdk-dotnet/Examples" target="_blank"&gt;the sample apps here&lt;/A&gt; for examples of how to use them. The &lt;A href="https://developers.dropbox.com/oauth-guide" target="_blank"&gt;OAuth Guide&lt;/A&gt; can also be a helpful resources for understanding how this flow works.&lt;/P&gt;</description>
    <pubDate>Mon, 13 Feb 2023 19:17:02 GMT</pubDate>
    <dc:creator>Greg-DB</dc:creator>
    <dc:date>2023-02-13T19:17:02Z</dc:date>
    <item>
      <title>ASP.NET MVC refresh token for DropBox have an error invalid_grant</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/ASP-NET-MVC-refresh-token-for-DropBox-have-an-error-invalid/m-p/658950#M3188</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I'm trying to refresh a Dropbox token in my ASP.NET MVC application. But I get an error:&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-SPOILER&gt;invalid_grant.&lt;/LI-SPOILER&gt;
&lt;P&gt;&lt;SPAN&gt;My code:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt; OAuth2Response tokenResult = await DropboxOAuth2Helper.ProcessCodeFlowAsync("http://127.0.0.1:52475/", ApiKey, ApiSecret);
            accessToken = tokenResult.AccessToken;
            refreshToken = tokenResult.RefreshToken;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2023 11:55:54 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/ASP-NET-MVC-refresh-token-for-DropBox-have-an-error-invalid/m-p/658950#M3188</guid>
      <dc:creator>Tomtit</dc:creator>
      <dc:date>2023-02-13T11:55:54Z</dc:date>
    </item>
    <item>
      <title>Re: ASP.NET MVC refresh token for DropBox have an error invalid_grant</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/ASP-NET-MVC-refresh-token-for-DropBox-have-an-error-invalid/m-p/659389#M3195</link>
      <description>&lt;P&gt;[Cross-linking for reference: &lt;A href="https://stackoverflow.com/questions/75426433/asp-net-mvc-refresh-token-for-dropbox-have-error-invalid-grant" target="_blank"&gt;https://stackoverflow.com/questions/75426433/asp-net-mvc-refresh-token-for-dropbox-have-error-invalid-grant&lt;/A&gt; ]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An 'invalid_grant' error can indicate that the values you're supplying to &lt;A href="https://dropbox.github.io/dropbox-sdk-dotnet/gh-pages/obj/api/Dropbox.Api.DropboxOAuth2Helper.html#Dropbox_Api_DropboxOAuth2Helper_ProcessCodeFlowAsync_System_String_System_String_System_String_System_String_HttpClient_System_String_" target="_blank"&gt;ProcessCodeFlowAsync&lt;/A&gt; are incorrect/invalid, or that they don't match the configuration used with &lt;A href="https://dropbox.github.io/dropbox-sdk-dotnet/gh-pages/obj/api/Dropbox.Api.DropboxOAuth2Helper.html#Dropbox_Api_DropboxOAuth2Helper_GetAuthorizeUri_Dropbox_Api_OAuthResponseType_System_String_System_String_System_String_System_Boolean_System_Boolean_System_String_System_Boolean_Dropbox_Api_TokenAccessType_System_String___Dropbox_Api_IncludeGrantedScopes_System_String_" target="_blank"&gt;GetAuthorizeUri&lt;/A&gt; to get that particular authorization.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, in the version of the code you shared here, you're setting the first parameter to "&lt;A href="http://127.0.0.1:52475/" target="_blank"&gt;http://127.0.0.1:52475/&lt;/A&gt;", which would be incorrect as that's neither an authorization code nor a redirect URI containing an authorization code, i.e., "responseUri". I see that the code in your StackOverflow post is different though, and does seem to contain the resulting redirect URI for the responseUri parameter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or, for instance, if you set a "redirectUri" when calling GetAuthorizeUri, you need to supply that same redirectUri to ProcessCodeFlowAsync to validate that request. That is, in addition to setting the responseUri parameter on ProcessCodeFlowAsync, you should set redirectUri as well (matching the redirectUri value you gave to GetAuthorizeUri). Or, if you didn't set a redirectUri when calling GetAuthorizeUri, you shouldn't set redirectUri when calling ProcessCodeFlowAsync.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, note that authorizations codes are only valid for a few minutes, and can only be used once each. You can store and re-use the resulting refresh tokens though; refresh tokens can be re-used and don't expire. Once you have a refresh token for an account, you don't need to run the authorization flow (GetAuthorizeUri and ProcessCodeFlowAsync) for that account again. You would just make the DropboxClient with the app key/secret and refresh token.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Refer to the documentation linked above for information on using these methods, and &lt;A href="https://github.com/dropbox/dropbox-sdk-dotnet/tree/main/dropbox-sdk-dotnet/Examples" target="_blank"&gt;the sample apps here&lt;/A&gt; for examples of how to use them. The &lt;A href="https://developers.dropbox.com/oauth-guide" target="_blank"&gt;OAuth Guide&lt;/A&gt; can also be a helpful resources for understanding how this flow works.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2023 19:17:02 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/ASP-NET-MVC-refresh-token-for-DropBox-have-an-error-invalid/m-p/659389#M3195</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2023-02-13T19:17:02Z</dc:date>
    </item>
  </channel>
</rss>

