<?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: responseUri C# problem in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/responseUri-C-problem/m-p/618120#M28460</link>
    <description>&lt;P&gt;The "redirect_uri mismatch" error indicates that this call failed because the redirect_uri used on &lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#oauth2-authorize" target="_self" rel="noopener noreferrer"&gt;/oauth2/authorize&lt;/A&gt;, which is the redirectUri parameter on &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; in the .NET SDK, to get that authorization code does not match the redirect_uri used when calling &lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#oauth2-token" target="_self" rel="noopener noreferrer"&gt;/oauth2/token&lt;/A&gt;, which is the redirectUri parameter on &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; in the .NET SDK. These two values need to match exactly. Or, if you didn't set&amp;nbsp;the redirectUri parameter on&amp;nbsp;GetAuthorizeUri you should likewise omit it when calling&amp;nbsp;ProcessCodeFlowAsync as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You didn't show your GetAuthorizeUri, but for your ProcessCodeFlowAsync call you seem to be manually constructing your responseUri from your redirectUri value, which isn't the intended way to do this. The responseUri value should be the redirected URI, containing the code, as triggered on your app by Dropbox redirecting the user back to your app after they authorized it. Dropbox would do so if you set the redirectUri parameter on GetAuthorizeUri.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, if you are not actually using a redirect URI by setting the redirectUri parameter on&amp;nbsp;GetAuthorizeUri to have the user automatically redirected, you should also not set the redirectUri parameter on ProcessCodeFlowAsync. In that case, you can instead use the form of ProcessCodeFlowAsync that takes the "code" parameter directly instead of the "responseUri" parameter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively, if you do want to use a redirect URI, make sure you set it using the redirectUri parameter on&amp;nbsp;GetAuthorizeUri and then pass the same redirectUri parameter to ProcessCodeFlowAsync.&lt;/P&gt;</description>
    <pubDate>Wed, 24 Aug 2022 20:01:47 GMT</pubDate>
    <dc:creator>Greg-DB</dc:creator>
    <dc:date>2022-08-24T20:01:47Z</dc:date>
    <item>
      <title>responseUri C# problem</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/responseUri-C-problem/m-p/618091#M28459</link>
      <description>&lt;P&gt;I am trying to set my dropbox configuration to TokenAccessType Offline on my page, but I am getting erros on the "DropboxOAuth2Helper.ProcessCodeFlowAsync"&lt;/P&gt;
&lt;P&gt;I get:&amp;nbsp;Dropbox.Api.OAuth2Exception: 'invalid_grant'&lt;/P&gt;
&lt;P&gt;for error description I got: redirect_uri mismatch&lt;/P&gt;
&lt;P&gt;after I got the page to enter my credentials I call this method:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;public async Task&amp;lt;ActionResult&amp;gt; DropboxRedirect(string code, string state)
        {
            try
            {
                var connectState = PantherCache.Get(_identityService.User.Guid + "_dropBoxConnectionState").Replace("\"", "");


                if (connectState != state)
                {
                    SessionVars.AddNotification(User.Identity.Name, new Notification
                    {
                        Type = NotificationType.error,
                        Text = "There was an error connecting to Dropbox."
                    });
                    return this.RedirectToAction("BoxSync");
                }

                var appKey = ConfigurationManager.AppSettings["dropbox.clientId"].ToString();
                var appSecret = ConfigurationManager.AppSettings["dropbox.clientSecret"].ToString();
                string redirectUri = Url.Action("DropboxRedirect", "Settings", new { code = code, state = state }, this.Request.Url.Scheme);
                Uri responseUri = new Uri(redirectUri);
                var response = await  DropboxOAuth2Helper.ProcessCodeFlowAsync(responseUri, appKey, appSecret, redirectUri.ToString(), state: connectState);
               // OAuth2Response response = await DropboxOAuth2Helper.ProcessCodeFlowAsync(responseUri, appKey, appSecret, state: connectState);

                var tenant = await _unitOfWork.TenantRepository.GetTenantByTenantGuid(_identityService.Tenant.Guid).FirstAsync();
                var isDropboxIntegrationEnabled = tenant.IsDropboxIntegrationEnabled;
                tenant.DropboxAuthToken = Encryptor.Encrypt(response.AccessToken);
                tenant.IsDropboxIntegrationEnabled = true;
                var res = await _unitOfWork.TenantRepository.InsertOrUpdateAndSaveAsync(tenant);

                //if the tenant was not integrated to drop box prior to the update
                if (!isDropboxIntegrationEnabled)
                {
                    QueueService.SendDropboxSyncQueueMessage(tenant.Id, null, null, Model.QueueModels.BoxSyncMessageType.InitSync, _identityService.User.Guid);
                }

                _identityService.ResetSessionVariablesFromCurrentContext(_identityService.User.Name, true, true);



                SessionVars.AddNotification(User.Identity.Name, new Notification
                {
                    Type = NotificationType.success,
                    Text = "This account is now connected to Dropbox!"
                });
                return this.RedirectToAction("BoxSync");
            }
            catch (Exception e)
            {
                SessionVars.AddNotification(User.Identity.Name, new Notification
                {
                    Type = NotificationType.error,
                    Text = "DropBox Authentication Error. Please try again later or contact support."
                });
                ErrorHelper.LogErrorManually(e);
                return this.RedirectToAction("BoxSync");
            }

        }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I got the error on this line:&lt;BR /&gt;var response = await DropboxOAuth2Helper.ProcessCodeFlowAsync(responseUri, appKey, appSecret, redirectUri.ToString(), state: connectState);&lt;/P&gt;
&lt;P&gt;currently my ResponseUri values are:&amp;nbsp; "&lt;A href="https://localhost:44383/Settings/DropboxRedirect?code=qX6NI6vbQh4AAAAAAAAAbCeVf-D8ZK916ZSKjp7oc64&amp;amp;state=afeb873a8cb7437dac1da70a59690dab&amp;quot;" target="_blank" rel="noopener"&gt;https://localhost:44383/Settings/DropboxRedirect?code=qX6NI6vbQh4AAAAAAAAAbCeVf-D8ZK916ZSKjp7oc64&amp;amp;state=afeb873a8cb7437dac1da70a59690dab"&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;I am creating my responseUri wrong? how should I create it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Aug 2022 19:34:52 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/responseUri-C-problem/m-p/618091#M28459</guid>
      <dc:creator>CTO1</dc:creator>
      <dc:date>2022-08-24T19:34:52Z</dc:date>
    </item>
    <item>
      <title>Re: responseUri C# problem</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/responseUri-C-problem/m-p/618120#M28460</link>
      <description>&lt;P&gt;The "redirect_uri mismatch" error indicates that this call failed because the redirect_uri used on &lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#oauth2-authorize" target="_self" rel="noopener noreferrer"&gt;/oauth2/authorize&lt;/A&gt;, which is the redirectUri parameter on &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; in the .NET SDK, to get that authorization code does not match the redirect_uri used when calling &lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#oauth2-token" target="_self" rel="noopener noreferrer"&gt;/oauth2/token&lt;/A&gt;, which is the redirectUri parameter on &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; in the .NET SDK. These two values need to match exactly. Or, if you didn't set&amp;nbsp;the redirectUri parameter on&amp;nbsp;GetAuthorizeUri you should likewise omit it when calling&amp;nbsp;ProcessCodeFlowAsync as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You didn't show your GetAuthorizeUri, but for your ProcessCodeFlowAsync call you seem to be manually constructing your responseUri from your redirectUri value, which isn't the intended way to do this. The responseUri value should be the redirected URI, containing the code, as triggered on your app by Dropbox redirecting the user back to your app after they authorized it. Dropbox would do so if you set the redirectUri parameter on GetAuthorizeUri.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, if you are not actually using a redirect URI by setting the redirectUri parameter on&amp;nbsp;GetAuthorizeUri to have the user automatically redirected, you should also not set the redirectUri parameter on ProcessCodeFlowAsync. In that case, you can instead use the form of ProcessCodeFlowAsync that takes the "code" parameter directly instead of the "responseUri" parameter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively, if you do want to use a redirect URI, make sure you set it using the redirectUri parameter on&amp;nbsp;GetAuthorizeUri and then pass the same redirectUri parameter to ProcessCodeFlowAsync.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Aug 2022 20:01:47 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/responseUri-C-problem/m-p/618120#M28460</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2022-08-24T20:01:47Z</dc:date>
    </item>
  </channel>
</rss>

