<?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 Dropbox SDK JS + Refresh token problem in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Dropbox-SDK-JS-Refresh-token-problem/m-p/543149#M25983</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please, do you have any idea how i can manage this ? Each 4 hours i get "expired_access_token" and user must re-log.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just upgrade my old Dropbox SDK JS to the last version&amp;nbsp;10.8.0 + I did the changes to be compatible.&lt;/P&gt;&lt;P&gt;I have one Cordova app (iOS/Android/Win10).&lt;/P&gt;&lt;P&gt;The goal of my app is to : 1. User connect on dropbox (long life), user set "working hours" on my app, then each day/week user save/load data to/from Dropbox.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Connexion code:&lt;/P&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;LI-CODE lang="javascript"&gt;// 1. I init Dropbox connexion
dbx = new Dropbox.Dropbox({
  clientId: dropboxClientId
});



// 2. I get auth url with redirect (custom url scheme)
var dropboxRedirectUri = 'MYAPP://dropbox_callback';

dbx.auth.getAuthenticationUrl(
  dropboxRedirectUri,
  '',
  'code',
  'offline',
  [
    'files.content.write',
    'files.content.read',
  ],
  'user',
  true
)
.then((authUrl) =&amp;gt; {
  dropboxCodeVerifier = dbx.auth.codeVerifier;
  cordova.InAppBrowser.open(authUrl, '_system');
});

// 3. User is redirect to his web browser to logoff, then user is redirected to my app
function handleOpenURL(url) {
  // I read the "code" send by Dropbox
  if (getUrlVars(url).code) {
   dbx.auth.setCodeVerifier(dropboxCodeVerifier);
   dbx.auth.getAccessTokenFromCode(dropboxRedirectUri, getUrlVars(url).code)
   .then((response) =&amp;gt; {
      // I get the "access_token" (starts with sl as short-life)     
      localStorage['dropbox_access_token'] = response.result.access_token;
   })
   .then((response) =&amp;gt; {
     ... User is now connected
   })
   .catch((error) =&amp;gt; {
     alert(error);
    });
}

// At this point, i also get "refresh_token", but I'm sorry i don't know how to use it.
// So, after that, for each user action (save/load) i connect to dropbox + i launch my // actions with this code:

dbx = new Dropbox.Dropbox({
  accessToken: localStorage['dropbox_access_token']
});
dbx.filesUpload({...	



Best regards&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;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 05 Sep 2021 09:42:39 GMT</pubDate>
    <dc:creator>Alex57600</dc:creator>
    <dc:date>2021-09-05T09:42:39Z</dc:date>
    <item>
      <title>Dropbox SDK JS + Refresh token problem</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Dropbox-SDK-JS-Refresh-token-problem/m-p/543149#M25983</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please, do you have any idea how i can manage this ? Each 4 hours i get "expired_access_token" and user must re-log.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just upgrade my old Dropbox SDK JS to the last version&amp;nbsp;10.8.0 + I did the changes to be compatible.&lt;/P&gt;&lt;P&gt;I have one Cordova app (iOS/Android/Win10).&lt;/P&gt;&lt;P&gt;The goal of my app is to : 1. User connect on dropbox (long life), user set "working hours" on my app, then each day/week user save/load data to/from Dropbox.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Connexion code:&lt;/P&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;LI-CODE lang="javascript"&gt;// 1. I init Dropbox connexion
dbx = new Dropbox.Dropbox({
  clientId: dropboxClientId
});



// 2. I get auth url with redirect (custom url scheme)
var dropboxRedirectUri = 'MYAPP://dropbox_callback';

dbx.auth.getAuthenticationUrl(
  dropboxRedirectUri,
  '',
  'code',
  'offline',
  [
    'files.content.write',
    'files.content.read',
  ],
  'user',
  true
)
.then((authUrl) =&amp;gt; {
  dropboxCodeVerifier = dbx.auth.codeVerifier;
  cordova.InAppBrowser.open(authUrl, '_system');
});

// 3. User is redirect to his web browser to logoff, then user is redirected to my app
function handleOpenURL(url) {
  // I read the "code" send by Dropbox
  if (getUrlVars(url).code) {
   dbx.auth.setCodeVerifier(dropboxCodeVerifier);
   dbx.auth.getAccessTokenFromCode(dropboxRedirectUri, getUrlVars(url).code)
   .then((response) =&amp;gt; {
      // I get the "access_token" (starts with sl as short-life)     
      localStorage['dropbox_access_token'] = response.result.access_token;
   })
   .then((response) =&amp;gt; {
     ... User is now connected
   })
   .catch((error) =&amp;gt; {
     alert(error);
    });
}

// At this point, i also get "refresh_token", but I'm sorry i don't know how to use it.
// So, after that, for each user action (save/load) i connect to dropbox + i launch my // actions with this code:

dbx = new Dropbox.Dropbox({
  accessToken: localStorage['dropbox_access_token']
});
dbx.filesUpload({...	



Best regards&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Sep 2021 09:42:39 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Dropbox-SDK-JS-Refresh-token-problem/m-p/543149#M25983</guid>
      <dc:creator>Alex57600</dc:creator>
      <dc:date>2021-09-05T09:42:39Z</dc:date>
    </item>
    <item>
      <title>Re: Dropbox SDK JS + Refresh token problem</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Dropbox-SDK-JS-Refresh-token-problem/m-p/543387#M25986</link>
      <description>&lt;P&gt;To maintain long-term access, you'll need to request "offline" access, as you're doing, and then supply the app key (the app secret isn't needed since you're using PKCE) and refresh token. As long as you do so, the SDK will handle the refresh process for you automatically. You can find &lt;A href="https://github.com/dropbox/dropbox-sdk-js/blob/b5631e4b5b0e9eb6d3297e1ee57ad29a63d49898/examples/javascript/PKCE-backend/code_flow_example.js#L38" target="_self"&gt;an example of setting the refresh token in this example&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Sep 2021 14:40:24 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Dropbox-SDK-JS-Refresh-token-problem/m-p/543387#M25986</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2021-09-06T14:40:24Z</dc:date>
    </item>
    <item>
      <title>Re: Dropbox SDK JS + Refresh token problem</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Dropbox-SDK-JS-Refresh-token-problem/m-p/543404#M25990</link>
      <description>Hello&lt;BR /&gt;&lt;BR /&gt;Thank you very much.&lt;BR /&gt;&lt;BR /&gt;I will try asap.</description>
      <pubDate>Mon, 06 Sep 2021 15:52:09 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Dropbox-SDK-JS-Refresh-token-problem/m-p/543404#M25990</guid>
      <dc:creator>Alex57600</dc:creator>
      <dc:date>2021-09-06T15:52:09Z</dc:date>
    </item>
  </channel>
</rss>

