<?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: Mismatched redirect URI in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Mismatched-redirect-URI/m-p/661217#M30025</link>
    <description>&lt;P&gt;The oauth2 guide does not make that clear, but you're right. I added redirect_uri to the parameters as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;if(isset($code)) {
  $data[] = "grant_type=authorization_code";
  $data[] = "code={$code}";
  $data[] = "redirect_uri={$this-&amp;gt;cfg-&amp;gt;get("siteUrl")}/api/v1/Dropbox/Oauth2";
} else {
  $data[] = "grant_type=refresh_token";
  $data[] = "refresh_token={$this-&amp;gt;cfg-&amp;gt;get("dropboxRefreshToken")}";
}&lt;/LI-CODE&gt;&lt;P&gt;It works. Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For anyone else who gets stuck on this, here is the relevant documentation:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="FrustratedUser3_0-1676826888781.png" style="width: 400px;"&gt;&lt;img src="https://www.dropboxforum.com/t5/image/serverpage/image-id/35448i9159378CA7F89E0D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="FrustratedUser3_0-1676826888781.png" alt="FrustratedUser3_0-1676826888781.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 19 Feb 2023 17:14:50 GMT</pubDate>
    <dc:creator>FrustratedUser3</dc:creator>
    <dc:date>2023-02-19T17:14:50Z</dc:date>
    <item>
      <title>Mismatched redirect URI</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Mismatched-redirect-URI/m-p/661210#M30022</link>
      <description>&lt;P&gt;I am using the following link to generate an authorization code for the code flow process:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;https://www.dropbox.com/oauth2/authorize?client_id=CLIENT_ID&amp;amp;response_type=code&amp;amp;token_access_type=offline&amp;amp;redirect_uri=https://dev.crm.DOMAIN.com/api/v1/Dropbox/Oauth2&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I replaced the client ID and domain due to privacy. The process works as expected without the redirect URI. In addition, I can successfully generate an access token using Postman by connecting to my API through the redirect URI with the code as one of the parameters, which validates my API's behavior.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After granting access to the app, here is what is shown in the browser's address bar:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;https://dev.crm.DOMAIN.com/api/v1/Dropbox/Oauth2?code=EIk...vr0&lt;/LI-CODE&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;Here is what my API receives:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;[2023-02-19 16:32:44] DEBUG:  [{"code":"EIk...vr0"}] []&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using the code, I create a request as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="php"&gt;  private function generateAccessToken($code) {
    $data = array(
      "client_id=&amp;lt;CLIENT_ID&amp;gt;",
      "client_secret=&amp;lt;CLIENT_SECRET&amp;gt;",
      "grant_type=authorization_code",
      "code={$code}",
    );

    $data = implode("&amp;amp;", $data);
    $headers = array('Content-Type: application/x-www-form-urlencoded');
    $url = "https://api.dropboxapi.com/oauth2/token";

    $response = $this-&amp;gt;curl-&amp;gt;post($url, $headers, $data);
    if($response["code"] != 200) {
      $GLOBALS["log"]-&amp;gt;error("access token error", $response);
      throw new Error("Error while retrieving access token");
    }

    return $response["data"];
  }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the response:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;[2023-02-19 16:30:13] ERROR: access token error {400, "error":"invalid_grant", "error_description":"redirect_uri mismatch"}&lt;/LI-CODE&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;Here is what is registered in the Dropbox app console:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="FrustratedUser3_2-1676825015874.png" style="width: 400px;"&gt;&lt;img src="https://www.dropboxforum.com/t5/image/serverpage/image-id/35447i37B3DEA730530A1F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="FrustratedUser3_2-1676825015874.png" alt="FrustratedUser3_2-1676825015874.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can't figure out what the problem is.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2023 21:24:25 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Mismatched-redirect-URI/m-p/661210#M30022</guid>
      <dc:creator>FrustratedUser3</dc:creator>
      <dc:date>2023-03-07T21:24:25Z</dc:date>
    </item>
    <item>
      <title>Re: Mismatched redirect URI</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Mismatched-redirect-URI/m-p/661213#M30023</link>
      <description>&lt;P&gt;&lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1083169"&gt;@FrustratedUser3&lt;/a&gt;, When you use redirect URI to receive a code, you have to use the same URI as a parameter in the call to /oauth2/token (the 'redirect_uri' parameter). &lt;img class="lia-deferred-image lia-image-emoji" src="https://www.dropboxforum.com/html/@FBF7D2AB59A0D6E861EBF6A36F93B7E2/emoticons/1f642.png" alt=":slightly_smiling_face:" title=":slightly_smiling_face:" /&gt; In spite this parameter is optional in general, it becomes mandatory with code received through redirect URI and the value should match this URI. As can be seen, it's skipped in your code. &lt;img class="lia-deferred-image lia-image-emoji" src="https://www.dropboxforum.com/html/@41457EF40051AFF130FDBFE21B496926/emoticons/1f609.png" alt=":winking_face:" title=":winking_face:" /&gt; That's where your issue comes from. Here "mismatch" probably means empty/missing doesn't match to the actual.&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;</description>
      <pubDate>Sun, 19 Feb 2023 17:07:43 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Mismatched-redirect-URI/m-p/661213#M30023</guid>
      <dc:creator>Здравко</dc:creator>
      <dc:date>2023-02-19T17:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: Mismatched redirect URI</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Mismatched-redirect-URI/m-p/661217#M30025</link>
      <description>&lt;P&gt;The oauth2 guide does not make that clear, but you're right. I added redirect_uri to the parameters as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;if(isset($code)) {
  $data[] = "grant_type=authorization_code";
  $data[] = "code={$code}";
  $data[] = "redirect_uri={$this-&amp;gt;cfg-&amp;gt;get("siteUrl")}/api/v1/Dropbox/Oauth2";
} else {
  $data[] = "grant_type=refresh_token";
  $data[] = "refresh_token={$this-&amp;gt;cfg-&amp;gt;get("dropboxRefreshToken")}";
}&lt;/LI-CODE&gt;&lt;P&gt;It works. Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For anyone else who gets stuck on this, here is the relevant documentation:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="FrustratedUser3_0-1676826888781.png" style="width: 400px;"&gt;&lt;img src="https://www.dropboxforum.com/t5/image/serverpage/image-id/35448i9159378CA7F89E0D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="FrustratedUser3_0-1676826888781.png" alt="FrustratedUser3_0-1676826888781.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Feb 2023 17:14:50 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Mismatched-redirect-URI/m-p/661217#M30025</guid>
      <dc:creator>FrustratedUser3</dc:creator>
      <dc:date>2023-02-19T17:14:50Z</dc:date>
    </item>
  </channel>
</rss>

