<?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: 0Auth2 keeps expiring despite refresh token in Discuss Dropbox Developer &amp; API</title>
    <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/0Auth2-keeps-expiring-despite-refresh-token/m-p/764109#M3995</link>
    <description>&lt;P&gt;Dropbox currently offers short-lived access tokens, which expire after a few hours, and refresh tokens, which don't expire.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need continuous access without repeated manual interaction, you'll need to request "offline" access in order to get a refresh token. The refresh token can be used to programmatically retrieve new short-lived access tokens whenever needed. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We can't offer support for this particular "OAuth2.createService" utility as it's not written by Dropbox, so I suggest referring to the documentation and support resources for that for information on how to use and troubleshoot it. For instance, it's unclear if it automatically requests offline access in order to receive a refresh token (and I don't see your code doing so explicitly), so you should check on that to make sure you're getting, storing, and re-using a refresh token.&lt;/P&gt;</description>
    <pubDate>Mon, 15 Apr 2024 15:23:14 GMT</pubDate>
    <dc:creator>Greg-DB</dc:creator>
    <dc:date>2024-04-15T15:23:14Z</dc:date>
    <item>
      <title>0Auth2 keeps expiring despite refresh token</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/0Auth2-keeps-expiring-despite-refresh-token/m-p/764084#M3992</link>
      <description>&lt;P&gt;Hello everyone! I am not a developer by any means, but with the help of ChatGPT I managed to create a Google App Script that lets me mirror certain Google Drive Folders into my Dropbox. It almost works perfect, except that after a few hours the authentification expires even though I understood that with 0Auth2, new short-lived tokens can be accessed continously without having to manually authenticate again and again?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could someone please point me to the flaw in the script (ChatGPT can't help anymore and thinks everything is fine)? Here is the relevant part of the script:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var DROPBOX_CLIENT_ID = "...";
var DROPBOX_CLIENT_SECRET = "...";

function authorize() {
  var service = OAuth2.createService('dropbox')
    .setAuthorizationBaseUrl('https://www.dropbox.com/oauth2/authorize')
    .setTokenUrl('https://api.dropboxapi.com/oauth2/token')
    .setClientId(DROPBOX_CLIENT_ID)
    .setClientSecret(DROPBOX_CLIENT_SECRET)
    .setCallbackFunction('authCallback')
    .setPropertyStore(PropertiesService.getUserProperties())
    .setScope('files.content.write')
    .setGrantType('authorization_code');

  var authorizationUrl = service.getAuthorizationUrl();
  Logger.log;
  Logger.log(authorizationUrl);
}

function authCallback(request) {
  var service = OAuth2.createService('dropbox')
    .setAuthorizationBaseUrl('https://www.dropbox.com/oauth2/authorize')
    .setTokenUrl('https://api.dropboxapi.com/oauth2/token')
    .setClientId(DROPBOX_CLIENT_ID)
    .setClientSecret(DROPBOX_CLIENT_SECRET)
    .setCallbackFunction('authCallback')
    .setPropertyStore(PropertiesService.getUserProperties())
    .setScope('files.content.write')
    .setGrantType('authorization_code');

  var isAuthorized = service.handleCallback(request);
  if (isAuthorized) {
    return HtmlService.createHtmlOutput;
  } else {
    return HtmlService.createHtmlOutput;
  }
}

function getDropboxAccessToken() {
  var service = OAuth2.createService('dropbox')
    .setPropertyStore(PropertiesService.getUserProperties())
    .setTokenUrl('https://api.dropboxapi.com/oauth2/token')
    .setClientId(DROPBOX_CLIENT_ID)
    .setClientSecret(DROPBOX_CLIENT_SECRET)
    .setScope('files.content.write')
    .setGrantType('authorization_code');

  var accessToken = service.getAccessToken();
  
  if (!accessToken || service.hasAccess() &amp;amp;&amp;amp; service.getAccessToken() === null) {
    var refreshToken = getStoredRefreshToken();
    service.refresh();
    accessToken = service.getAccessToken();
    
    if (accessToken) {
      PropertiesService.getUserProperties().setProperty('DROPBOX_REFRESH_TOKEN', refreshToken); // Speichern des Refresh-Tokens
    }
  }

  return accessToken;
}

function getStoredRefreshToken() {
  return PropertiesService.getUserProperties().getProperty('DROPBOX_REFRESH_TOKEN');
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2024 14:26:48 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/0Auth2-keeps-expiring-despite-refresh-token/m-p/764084#M3992</guid>
      <dc:creator>bnfofficial</dc:creator>
      <dc:date>2024-04-15T14:26:48Z</dc:date>
    </item>
    <item>
      <title>Re: 0Auth2 keeps expiring despite refresh token</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/0Auth2-keeps-expiring-despite-refresh-token/m-p/764109#M3995</link>
      <description>&lt;P&gt;Dropbox currently offers short-lived access tokens, which expire after a few hours, and refresh tokens, which don't expire.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need continuous access without repeated manual interaction, you'll need to request "offline" access in order to get a refresh token. The refresh token can be used to programmatically retrieve new short-lived access tokens whenever needed. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We can't offer support for this particular "OAuth2.createService" utility as it's not written by Dropbox, so I suggest referring to the documentation and support resources for that for information on how to use and troubleshoot it. For instance, it's unclear if it automatically requests offline access in order to receive a refresh token (and I don't see your code doing so explicitly), so you should check on that to make sure you're getting, storing, and re-using a refresh token.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2024 15:23:14 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/0Auth2-keeps-expiring-despite-refresh-token/m-p/764109#M3995</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2024-04-15T15:23:14Z</dc:date>
    </item>
  </channel>
</rss>

