<?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: What way of authorization to use for a (PHP) open source module in Discuss Dropbox Developer &amp; API</title>
    <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/What-way-of-authorization-to-use-for-a-PHP-open-source-module/m-p/523387#M1908</link>
    <description>&lt;P&gt;I'm not having any joy at all getting authorisation to work. As far as I can tell, I'm following the docs to the letter (though some of them are extremely difficult to read or interpret) and this coincides perfectly with the steps outlined earlier in this thread.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to use the PKCE flow for a Wordpress plugin built in PHP. The docs say this is the best method to use where the code will be viewable by the public so you don't want to have your app secret used.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I construct a url to take the user to oauth2/authorize to authorise the app. The url has the following added in correct url encoded format:&lt;/P&gt;&lt;P&gt;response_type=code&lt;/P&gt;&lt;P&gt;client_id=&amp;lt;MYAPPID&amp;gt;&lt;/P&gt;&lt;P&gt;code_challenge=&amp;lt;CHALLENGE&amp;gt;&lt;/P&gt;&lt;P&gt;code_challenge_method=S256&lt;/P&gt;&lt;P&gt;(with the appropriate values in place of the placeholders above).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The user then returns to my app and types in the &amp;lt;CODE&amp;gt; they're given, and I then save it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I then immediately use that &amp;lt;CODE&amp;gt; to try to get a token using oauth2/token. I'm using CURL for this. The headers I set are:&lt;/P&gt;&lt;PRE&gt;Accept: application/json
Content-Type: application/x-www-form-urlencoded&lt;/PRE&gt;&lt;P&gt;Then for the data (sent in urlencoded format) I have&lt;/P&gt;&lt;PRE&gt;code=&amp;lt;CODE&amp;gt;&lt;BR /&gt;grant_type=authorization_code&lt;BR /&gt;code_verifier=&amp;lt;CHALLENGE&amp;gt;&lt;BR /&gt;client_id=&amp;lt;MYAPPID&amp;gt;&lt;/PRE&gt;&lt;P&gt;What I get back from Dropbox, though, is an error:&lt;/P&gt;&lt;PRE&gt;{"error_description": "invalid code verifier", "error": "invalid_grant"}&lt;/PRE&gt;&lt;P&gt;I keep trying different combinations of things, including with the headers,&amp;nbsp; for about five minutes until the &amp;lt;CODE&amp;gt; expires and the error message changes to that. Then I have to re-authorise the app and circle around again. The encrypted code verifier I'm sending in the token request is exactly the same encrypted code verifier I sent with the authorisation url. So why the error?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is doing my head in. Can anyone please help?&lt;/P&gt;</description>
    <pubDate>Sat, 29 May 2021 06:44:37 GMT</pubDate>
    <dc:creator>delahoc</dc:creator>
    <dc:date>2021-05-29T06:44:37Z</dc:date>
    <item>
      <title>What way of authorization to use for a (PHP) open source module</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/What-way-of-authorization-to-use-for-a-PHP-open-source-module/m-p/501850#M1757</link>
      <description>&lt;P&gt;I am the developer of the Drupal module &lt;A href="https://www.drupal.org/project/backup_migrate_dropbox" target="_self"&gt;Backup &amp;amp; migrate Dropbox&lt;/A&gt;&amp;nbsp;that extends the "&lt;A href="https://www.drupal.org/project/backup_migrate" target="_self"&gt;Backup and migrate&lt;/A&gt;" module to store backups on Dropbox. So this module:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;is open source, so I cannot put the App secret in my code.&lt;/LI&gt;&lt;LI&gt;installed on web servers of which I cannot know the domain names, so I cannot define redirect uri's for all those domains.&lt;/LI&gt;&lt;LI&gt;runs via some admin screens but mainly via cron jobs (unattended), so I need a way to work with long lived tokens/codes.&lt;/LI&gt;&lt;LI&gt;I am not part of an organization that can or wants to provide an intermediate site for the redirect uri (and storage of long lived codes/tokens? Keeper of App secret?) .&lt;/LI&gt;&lt;LI&gt;The current version requires users to each create their own App and generate a long lived token on their App console.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I am developing a new version that should use the newer oauth2 way of obtaining authorization. Given the above, it seems that the PKCE flow is the way to go, but is this possible? I arrive at getting a user copied and pasted (short lived) acces code, use that to get a 1st (short lived) bearer token and (presumably long lived) refresh token, but after the access code and bearer token have expired and I use the refresh token to get a new bearer token I get the error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Request sent:&lt;/P&gt;&lt;PRE&gt; https://api.dropbox.com/oauth2/token&lt;BR /&gt;   body = refresh_token=8p************************************************************eI&lt;BR /&gt;&amp;amp;grant_type=refresh_token&lt;BR /&gt;&amp;amp;code_verifier=wE***************************************pU&lt;BR /&gt;&amp;amp;client_id=2b***********6x&lt;/PRE&gt;&lt;P&gt;Response received (invalid json as all \ were removed to improve readability):&lt;/P&gt;&lt;PRE&gt;body: {"error_description": "unknown field "code_verifier"", "error": "invalid_request"}"&lt;BR /&gt;response code: 400&lt;/PRE&gt;&lt;P&gt;Is what I want possible? If so, how? Or what is the way to go?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for any help on this.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 15:59:51 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/What-way-of-authorization-to-use-for-a-PHP-open-source-module/m-p/501850#M1757</guid>
      <dc:creator>fietserwin</dc:creator>
      <dc:date>2021-03-04T15:59:51Z</dc:date>
    </item>
    <item>
      <title>Re: What way of authorization to use for a (PHP) open source module</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/What-way-of-authorization-to-use-for-a-PHP-open-source-module/m-p/501855#M1758</link>
      <description>&lt;P&gt;While the PKCE flow is generally meant for client-side apps (and server-side apps would generally use the code flow) given the constraints in this case, using the PKCE flow seems reasonable and should work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The issue you're running in to here is that you're calling&amp;nbsp;/oauth2/token to perform 'grant_type=refresh_token' but are supplying the 'code_verifier' parameter. The&amp;nbsp;'code_verifier' parameter should only be provided for the initial 'grant_type=authorization_code'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That is, the flow should look like this:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The user is directed to /oauth2/authorize&lt;/LI&gt;
&lt;LI&gt;The user approves the app&lt;/LI&gt;
&lt;LI&gt;The user copies the authorization code from the&amp;nbsp;Dropbox web site into the app&lt;/LI&gt;
&lt;LI&gt;The app calls&amp;nbsp;/oauth2/token supplying 'code' set to the authorization code,&amp;nbsp;'grant_type=authorization_code', 'code_verifier' set to the code verifier, and 'client_id' set to the app key, just once per authorization flow.&lt;/LI&gt;
&lt;LI&gt;The app uses the short-lived access token to make API calls.&lt;/LI&gt;
&lt;LI&gt;The app calls&amp;nbsp;/oauth2/token supplying 'refresh_token' set to the refresh token, 'grant_type=refresh_token', and&amp;nbsp;'client_id' set to the app key, but not 'code_verifier', repeatedly whenever a new short-lived access token is needed.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Also, to confirm, yes, refresh tokens are long-lived. They don't expire by themselves, but can be revoked on demand.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 16:21:09 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/What-way-of-authorization-to-use-for-a-PHP-open-source-module/m-p/501855#M1758</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2021-03-04T16:21:09Z</dc:date>
    </item>
    <item>
      <title>Re: What way of authorization to use for a (PHP) open source module</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/What-way-of-authorization-to-use-for-a-PHP-open-source-module/m-p/501858#M1759</link>
      <description>&lt;P&gt;Yes, that works, thanks a lot. I thus indeed was close all that time. Could it be an idea to add a step 6 to the PKCE guide (&lt;A href="https://dropbox.tech/developers/pkce--what-and-why-)" target="_blank"&gt;https://dropbox.tech/developers/pkce--what-and-why-)&lt;/A&gt;&amp;nbsp;or add a 4th example to&amp;nbsp;&lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#oauth2-token" target="_blank"&gt;https://www.dropbox.com/developers/documentation/http/documentation#oauth2-token&lt;/A&gt; ?&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 16:47:30 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/What-way-of-authorization-to-use-for-a-PHP-open-source-module/m-p/501858#M1759</guid>
      <dc:creator>fietserwin</dc:creator>
      <dc:date>2021-03-04T16:47:30Z</dc:date>
    </item>
    <item>
      <title>Re: What way of authorization to use for a (PHP) open source module</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/What-way-of-authorization-to-use-for-a-PHP-open-source-module/m-p/523387#M1908</link>
      <description>&lt;P&gt;I'm not having any joy at all getting authorisation to work. As far as I can tell, I'm following the docs to the letter (though some of them are extremely difficult to read or interpret) and this coincides perfectly with the steps outlined earlier in this thread.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to use the PKCE flow for a Wordpress plugin built in PHP. The docs say this is the best method to use where the code will be viewable by the public so you don't want to have your app secret used.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I construct a url to take the user to oauth2/authorize to authorise the app. The url has the following added in correct url encoded format:&lt;/P&gt;&lt;P&gt;response_type=code&lt;/P&gt;&lt;P&gt;client_id=&amp;lt;MYAPPID&amp;gt;&lt;/P&gt;&lt;P&gt;code_challenge=&amp;lt;CHALLENGE&amp;gt;&lt;/P&gt;&lt;P&gt;code_challenge_method=S256&lt;/P&gt;&lt;P&gt;(with the appropriate values in place of the placeholders above).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The user then returns to my app and types in the &amp;lt;CODE&amp;gt; they're given, and I then save it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I then immediately use that &amp;lt;CODE&amp;gt; to try to get a token using oauth2/token. I'm using CURL for this. The headers I set are:&lt;/P&gt;&lt;PRE&gt;Accept: application/json
Content-Type: application/x-www-form-urlencoded&lt;/PRE&gt;&lt;P&gt;Then for the data (sent in urlencoded format) I have&lt;/P&gt;&lt;PRE&gt;code=&amp;lt;CODE&amp;gt;&lt;BR /&gt;grant_type=authorization_code&lt;BR /&gt;code_verifier=&amp;lt;CHALLENGE&amp;gt;&lt;BR /&gt;client_id=&amp;lt;MYAPPID&amp;gt;&lt;/PRE&gt;&lt;P&gt;What I get back from Dropbox, though, is an error:&lt;/P&gt;&lt;PRE&gt;{"error_description": "invalid code verifier", "error": "invalid_grant"}&lt;/PRE&gt;&lt;P&gt;I keep trying different combinations of things, including with the headers,&amp;nbsp; for about five minutes until the &amp;lt;CODE&amp;gt; expires and the error message changes to that. Then I have to re-authorise the app and circle around again. The encrypted code verifier I'm sending in the token request is exactly the same encrypted code verifier I sent with the authorisation url. So why the error?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is doing my head in. Can anyone please help?&lt;/P&gt;</description>
      <pubDate>Sat, 29 May 2021 06:44:37 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/What-way-of-authorization-to-use-for-a-PHP-open-source-module/m-p/523387#M1908</guid>
      <dc:creator>delahoc</dc:creator>
      <dc:date>2021-05-29T06:44:37Z</dc:date>
    </item>
    <item>
      <title>Re: What way of authorization to use for a (PHP) open source module</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/What-way-of-authorization-to-use-for-a-PHP-open-source-module/m-p/523391#M1909</link>
      <description>&lt;P&gt;Delahoc,&lt;/P&gt;&lt;P&gt;I suggest you have a look at my code that you can find at&amp;nbsp;&lt;A href="https://www.drupal.org/project/backup_migrate_dropbox/releases/7.x-3.0," target="_blank"&gt;https://www.drupal.org/project/backup_migrate_dropbox/releases/7.x-3.0,&lt;/A&gt;&amp;nbsp;that should help you to construct the correct flow and requests and process the answers.&lt;/P&gt;</description>
      <pubDate>Sat, 29 May 2021 07:22:48 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/What-way-of-authorization-to-use-for-a-PHP-open-source-module/m-p/523391#M1909</guid>
      <dc:creator>fietserwin</dc:creator>
      <dc:date>2021-05-29T07:22:48Z</dc:date>
    </item>
    <item>
      <title>Re: What way of authorization to use for a (PHP) open source module</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/What-way-of-authorization-to-use-for-a-PHP-open-source-module/m-p/523394#M1910</link>
      <description>&lt;P&gt;Thanks for the reply. I'm pretty sure I have the flow and requests correct. I'd love to check out your code, but that link you've provided gives a 404 Page Not Found error.&lt;/P&gt;</description>
      <pubDate>Sat, 29 May 2021 08:14:27 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/What-way-of-authorization-to-use-for-a-PHP-open-source-module/m-p/523394#M1910</guid>
      <dc:creator>delahoc</dc:creator>
      <dc:date>2021-05-29T08:14:27Z</dc:date>
    </item>
    <item>
      <title>Re: What way of authorization to use for a (PHP) open source module</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/What-way-of-authorization-to-use-for-a-PHP-open-source-module/m-p/523471#M1911</link>
      <description>&lt;P&gt;Remove the comma at the end, the forum software added that to my plain text link.&lt;/P&gt;</description>
      <pubDate>Sat, 29 May 2021 19:37:27 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/What-way-of-authorization-to-use-for-a-PHP-open-source-module/m-p/523471#M1911</guid>
      <dc:creator>fietserwin</dc:creator>
      <dc:date>2021-05-29T19:37:27Z</dc:date>
    </item>
    <item>
      <title>Re: What way of authorization to use for a (PHP) open source module</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/What-way-of-authorization-to-use-for-a-PHP-open-source-module/m-p/523491#M1913</link>
      <description>&lt;P&gt;Thanks. I've taken a look at your code - very neat, btw.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've extracted the code you used to build the unencoded verifier string and the encoded verifier code challenge, and inserted them both into my code. I've compared the verifier code in the authorisation url and in the token request and they are exactly the same. I'm still getting exactly the same error:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;{"error_description": "invalid code verifier", "error": "invalid_grant"}&lt;/PRE&gt;&lt;P&gt;Here are the headers I'm sending with the token request:&lt;/P&gt;&lt;PRE&gt;HEADERS=Array
(
    [0] =&amp;gt; Accept: application/json
    [1] =&amp;gt; Content-Type: application/x-www-form-urlencoded
)&lt;/PRE&gt;&lt;P&gt;Here is the data I'm paramatising onto the endpoint (oauth2/token) for the token request:&lt;/P&gt;&lt;PRE&gt;DATA=Array
(
    [grant_type] =&amp;gt; authorization_code
    [code] =&amp;gt; &amp;lt;AUTHORIZATIONCODE&amp;gt;
    [code_verifier] =&amp;gt; &amp;lt;CODECHALLENGE&amp;gt;
    [client_id] =&amp;gt; &amp;lt;CLIENTID&amp;gt;
)&lt;/PRE&gt;&lt;P&gt;(I'm not using a REDIRECT_URI in either the authorisation URL or the token request as this is for a WordPress plugin that might get used on more than one site. This is apparently perfectly okay with Dropbox, according to their docs.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm at a loss. If the CODECHALLENGE is exactly the same in both the authorisation URL and the token request, why on earth is it failing?&lt;/P&gt;</description>
      <pubDate>Sun, 30 May 2021 00:00:12 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/What-way-of-authorization-to-use-for-a-PHP-open-source-module/m-p/523491#M1913</guid>
      <dc:creator>delahoc</dc:creator>
      <dc:date>2021-05-30T00:00:12Z</dc:date>
    </item>
    <item>
      <title>Re: What way of authorization to use for a (PHP) open source module</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/What-way-of-authorization-to-use-for-a-PHP-open-source-module/m-p/523513#M1914</link>
      <description>&lt;P&gt;With the token request you should pass the code verifier, not the code challenge. Dropbox will hash it itself and compare it with the code challenge that it stored when the user granted access with the authorize request. note that the code verifier should be unique for each install of your plugin and should stay on that install and only be used to obtain a (long lived) refresh token.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps&lt;/P&gt;</description>
      <pubDate>Sun, 30 May 2021 07:08:05 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/What-way-of-authorization-to-use-for-a-PHP-open-source-module/m-p/523513#M1914</guid>
      <dc:creator>fietserwin</dc:creator>
      <dc:date>2021-05-30T07:08:05Z</dc:date>
    </item>
    <item>
      <title>Re: What way of authorization to use for a (PHP) open source module</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/What-way-of-authorization-to-use-for-a-PHP-open-source-module/m-p/523521#M1915</link>
      <description>&lt;P&gt;Thanks. That seems to have done the trick. I'm sure I tried that option once before, but I must have also had something else changed that also wasn't working.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 30 May 2021 09:23:47 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/What-way-of-authorization-to-use-for-a-PHP-open-source-module/m-p/523521#M1915</guid>
      <dc:creator>delahoc</dc:creator>
      <dc:date>2021-05-30T09:23:47Z</dc:date>
    </item>
  </channel>
</rss>

