<?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 get access token &amp;amp; refresh token in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/get-access-token-amp-refresh-token/m-p/660488#M30001</link>
    <description>&lt;P&gt;Hi, so I have a few issues,&lt;BR /&gt;I need to get the access token and the refresh token, Im using Dropbox bussiness account and I used this url to get the access code:&lt;BR /&gt;&lt;SPAN&gt;(*) - "&lt;A href="https://www.dropbox.com/oauth2/authorize?client_id=" target="_blank" rel="noopener"&gt;https://www.dropbox.com/oauth2/authorize?client_id=&lt;/A&gt;&amp;lt;AppKey&amp;gt;&amp;amp;token_access_type=offline&amp;amp;response_type=code"&lt;/SPAN&gt;&lt;BR /&gt;later I tried to get the access token via Postman using this POST curl request from the documanitaition:&lt;/P&gt;
&lt;PRE&gt;curl https://api.dropbox.com/oauth2/token \
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-d code=&amp;lt;AUTHORIZATION_CODE&amp;gt; \
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-d grant_type=authorization_code \
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-d redirect_uri=&amp;lt;REDIRECT_URI&amp;gt; \
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-d client_id=&amp;lt;APP_KEY&amp;gt; \
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-d client_secret=&amp;lt;APP_SECRET&amp;gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;but I get an "mismatch redirect uri" even though I double-checked that the App_Key&amp;amp;App_Secret&amp;amp;Redirect_Uri are well difined within the app I created in Dropbox console.&lt;BR /&gt;So the first question will be, What is missing for me here?&lt;BR /&gt;Staying on the same subject, Im trying to make a Post request in javaScript to get the accessToken and the refreshToken, I couldn't find an example how to do that(no PKCE), so I tried to do that:&lt;/P&gt;
&lt;PRE&gt;&lt;SPAN&gt;const &lt;/SPAN&gt;respone = &lt;SPAN&gt;await &lt;/SPAN&gt;axios.&lt;SPAN&gt;post&lt;/SPAN&gt;(&lt;SPAN&gt;'https://api.dropboxapi.com/oauth2/token'&lt;/SPAN&gt;&lt;SPAN&gt;, null, &lt;/SPAN&gt;{&lt;BR /&gt;  &lt;SPAN&gt;headers&lt;/SPAN&gt;: {&lt;BR /&gt;    &lt;SPAN&gt;'Content-Type'&lt;/SPAN&gt;: &lt;SPAN&gt;'application/x-www-form-urlencoded'&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;  }&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;  &lt;SPAN&gt;data&lt;/SPAN&gt;: {&lt;BR /&gt;    code: &amp;lt;Access Code&amp;gt; - access code from above see (*)&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;    &lt;SPAN&gt;grant_type&lt;/SPAN&gt;: &lt;SPAN&gt;'authorization_code'&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;    &lt;SPAN&gt;redirect_uri&lt;/SPAN&gt;: &amp;lt;Redirect-Uri&amp;gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;    client_id:&amp;lt;App-Key&amp;gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;    &lt;SPAN&gt;client_secret&lt;/SPAN&gt;: &amp;lt;App-Secret&amp;gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;  }&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;})&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;console&lt;/SPAN&gt;.&lt;SPAN&gt;log&lt;/SPAN&gt;(respone)&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;and then as I understand I would have the access Token and the refresh Token in the response parameter, but I get a bad request.&lt;BR /&gt;Second question - what is missing for me, please refer to specific example how to do it(no PKCE)?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;I manage to do this flow successfully using Java but unfortunatly it is not good enough for me as it has to be in javascript.&lt;BR /&gt;this is how I did it in Java:&lt;/P&gt;
&lt;PRE&gt;            DbxAppInfo appInfo = &lt;SPAN&gt;new &lt;/SPAN&gt;DbxAppInfo(&lt;SPAN&gt;this&lt;/SPAN&gt;.&lt;SPAN&gt;appKey&lt;/SPAN&gt;&lt;SPAN&gt;, this&lt;/SPAN&gt;.&lt;SPAN&gt;appSecret&lt;/SPAN&gt;)&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;            String accessCode =&amp;lt;Access Code&amp;gt; - access code from above see (*);&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;            DbxRequestConfig config = DbxRequestConfig.&lt;SPAN&gt;newBuilder&lt;/SPAN&gt;(&lt;SPAN&gt;this&lt;/SPAN&gt;.&lt;SPAN&gt;appKey&lt;/SPAN&gt;).build()&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;            DbxWebAuth webAuth = &lt;SPAN&gt;new &lt;/SPAN&gt;DbxWebAuth(config&lt;SPAN&gt;, &lt;/SPAN&gt;appInfo)&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;            DbxAuthFinish authFinish&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;            try &lt;/SPAN&gt;{&lt;BR /&gt;                authFinish = webAuth.finishFromCode(&lt;SPAN&gt;accessCode&lt;/SPAN&gt;)&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;            } &lt;SPAN&gt;catch &lt;/SPAN&gt;(DbxException e) {&lt;BR /&gt;                &lt;SPAN&gt;throw new &lt;/SPAN&gt;Exception(e&lt;SPAN&gt;, new &lt;/SPAN&gt;RuntimeException(&lt;SPAN&gt;"Invalid Access Code, please Generate new Access Code"&lt;/SPAN&gt;))&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;            }&lt;BR /&gt;            String accessTokenOld = authFinish.getAccessToken()&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;            String refreshTokenOld = authFinish.getRefreshToken()&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Third and last question - I need to do exactly the same as this in javascript, please help me to that.&lt;BR /&gt;Sincerely,&lt;BR /&gt;Asif&lt;/P&gt;</description>
    <pubDate>Thu, 16 Feb 2023 16:45:37 GMT</pubDate>
    <dc:creator>env</dc:creator>
    <dc:date>2023-02-16T16:45:37Z</dc:date>
    <item>
      <title>get access token &amp; refresh token</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/get-access-token-amp-refresh-token/m-p/660488#M30001</link>
      <description>&lt;P&gt;Hi, so I have a few issues,&lt;BR /&gt;I need to get the access token and the refresh token, Im using Dropbox bussiness account and I used this url to get the access code:&lt;BR /&gt;&lt;SPAN&gt;(*) - "&lt;A href="https://www.dropbox.com/oauth2/authorize?client_id=" target="_blank" rel="noopener"&gt;https://www.dropbox.com/oauth2/authorize?client_id=&lt;/A&gt;&amp;lt;AppKey&amp;gt;&amp;amp;token_access_type=offline&amp;amp;response_type=code"&lt;/SPAN&gt;&lt;BR /&gt;later I tried to get the access token via Postman using this POST curl request from the documanitaition:&lt;/P&gt;
&lt;PRE&gt;curl https://api.dropbox.com/oauth2/token \
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-d code=&amp;lt;AUTHORIZATION_CODE&amp;gt; \
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-d grant_type=authorization_code \
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-d redirect_uri=&amp;lt;REDIRECT_URI&amp;gt; \
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-d client_id=&amp;lt;APP_KEY&amp;gt; \
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-d client_secret=&amp;lt;APP_SECRET&amp;gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;but I get an "mismatch redirect uri" even though I double-checked that the App_Key&amp;amp;App_Secret&amp;amp;Redirect_Uri are well difined within the app I created in Dropbox console.&lt;BR /&gt;So the first question will be, What is missing for me here?&lt;BR /&gt;Staying on the same subject, Im trying to make a Post request in javaScript to get the accessToken and the refreshToken, I couldn't find an example how to do that(no PKCE), so I tried to do that:&lt;/P&gt;
&lt;PRE&gt;&lt;SPAN&gt;const &lt;/SPAN&gt;respone = &lt;SPAN&gt;await &lt;/SPAN&gt;axios.&lt;SPAN&gt;post&lt;/SPAN&gt;(&lt;SPAN&gt;'https://api.dropboxapi.com/oauth2/token'&lt;/SPAN&gt;&lt;SPAN&gt;, null, &lt;/SPAN&gt;{&lt;BR /&gt;  &lt;SPAN&gt;headers&lt;/SPAN&gt;: {&lt;BR /&gt;    &lt;SPAN&gt;'Content-Type'&lt;/SPAN&gt;: &lt;SPAN&gt;'application/x-www-form-urlencoded'&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;  }&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;  &lt;SPAN&gt;data&lt;/SPAN&gt;: {&lt;BR /&gt;    code: &amp;lt;Access Code&amp;gt; - access code from above see (*)&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;    &lt;SPAN&gt;grant_type&lt;/SPAN&gt;: &lt;SPAN&gt;'authorization_code'&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;    &lt;SPAN&gt;redirect_uri&lt;/SPAN&gt;: &amp;lt;Redirect-Uri&amp;gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;    client_id:&amp;lt;App-Key&amp;gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;    &lt;SPAN&gt;client_secret&lt;/SPAN&gt;: &amp;lt;App-Secret&amp;gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;  }&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;})&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;console&lt;/SPAN&gt;.&lt;SPAN&gt;log&lt;/SPAN&gt;(respone)&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;and then as I understand I would have the access Token and the refresh Token in the response parameter, but I get a bad request.&lt;BR /&gt;Second question - what is missing for me, please refer to specific example how to do it(no PKCE)?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;I manage to do this flow successfully using Java but unfortunatly it is not good enough for me as it has to be in javascript.&lt;BR /&gt;this is how I did it in Java:&lt;/P&gt;
&lt;PRE&gt;            DbxAppInfo appInfo = &lt;SPAN&gt;new &lt;/SPAN&gt;DbxAppInfo(&lt;SPAN&gt;this&lt;/SPAN&gt;.&lt;SPAN&gt;appKey&lt;/SPAN&gt;&lt;SPAN&gt;, this&lt;/SPAN&gt;.&lt;SPAN&gt;appSecret&lt;/SPAN&gt;)&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;            String accessCode =&amp;lt;Access Code&amp;gt; - access code from above see (*);&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;            DbxRequestConfig config = DbxRequestConfig.&lt;SPAN&gt;newBuilder&lt;/SPAN&gt;(&lt;SPAN&gt;this&lt;/SPAN&gt;.&lt;SPAN&gt;appKey&lt;/SPAN&gt;).build()&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;            DbxWebAuth webAuth = &lt;SPAN&gt;new &lt;/SPAN&gt;DbxWebAuth(config&lt;SPAN&gt;, &lt;/SPAN&gt;appInfo)&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;            DbxAuthFinish authFinish&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;            try &lt;/SPAN&gt;{&lt;BR /&gt;                authFinish = webAuth.finishFromCode(&lt;SPAN&gt;accessCode&lt;/SPAN&gt;)&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;            } &lt;SPAN&gt;catch &lt;/SPAN&gt;(DbxException e) {&lt;BR /&gt;                &lt;SPAN&gt;throw new &lt;/SPAN&gt;Exception(e&lt;SPAN&gt;, new &lt;/SPAN&gt;RuntimeException(&lt;SPAN&gt;"Invalid Access Code, please Generate new Access Code"&lt;/SPAN&gt;))&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;            }&lt;BR /&gt;            String accessTokenOld = authFinish.getAccessToken()&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;            String refreshTokenOld = authFinish.getRefreshToken()&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Third and last question - I need to do exactly the same as this in javascript, please help me to that.&lt;BR /&gt;Sincerely,&lt;BR /&gt;Asif&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 16:45:37 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/get-access-token-amp-refresh-token/m-p/660488#M30001</guid>
      <dc:creator>env</dc:creator>
      <dc:date>2023-02-16T16:45:37Z</dc:date>
    </item>
    <item>
      <title>Re: get access token &amp; refresh token</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/get-access-token-amp-refresh-token/m-p/660497#M30003</link>
      <description>&lt;P&gt;The mismatched redirect URI error indicates that the redirect_uri you're using on /oauth2/token doesn't match the redirect_uri used to retrieve that authorization code from /oauth2/authorize. Since you're not setting redirect_uri on /oauth2/authorize, you should also omit it when calling /oauth2/token.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When performing a call like this, be sure to print out the response body, as it will generally contain a more specific error message. It sounds like the error in the JavaScript case is likely the same as above though, or check the response body for the error message.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For JavaScript, we highly recommend using &lt;A href="https://github.com/dropbox/dropbox-sdk-js" rel="noopener noreferrer" target="_blank"&gt;the official Dropbox JavaScript SDK&lt;/A&gt;, as it will do much of the work for you automatically. Refer to the examples included in &lt;A href="https://github.com/dropbox/dropbox-sdk-js/tree/main/examples/javascript" rel="noopener noreferrer" target="_blank"&gt;the "examples" folder in the SDK&lt;/A&gt;. It implements the authorization flow steps and as long as you set the necessary credentials, like shown in &lt;A href="https://github.com/dropbox/dropbox-sdk-js/blob/b5631e4b5b0e9eb6d3297e1ee57ad29a63d49898/examples/javascript/PKCE-backend/code_flow_example.js#L38" rel="noopener noreferrer" target="_blank"&gt;this example for the JavaScript SDK&lt;/A&gt;, the SDK will actually handle refresh process for you automatically. The SDK will automatically catch expired access token errors and call the API to get a new short-lived access token when needed.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 16:49:56 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/get-access-token-amp-refresh-token/m-p/660497#M30003</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2023-02-16T16:49:56Z</dc:date>
    </item>
  </channel>
</rss>

