Page MenuHomePhorge

D5139.1775245406.diff
No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None

D5139.1775245406.diff

diff --git a/plugins/kolab_files/kolab_files.js b/plugins/kolab_files/kolab_files.js
--- a/plugins/kolab_files/kolab_files.js
+++ b/plugins/kolab_files/kolab_files.js
@@ -127,6 +127,9 @@
}
kolab_files_init();
+
+ rcmail.addEventListener('responsebeforerefresh', kolab_files_token_refresh);
+ rcmail.addEventListener('responsebeforekeep-alive', kolab_files_token_refresh);
});
@@ -274,6 +277,28 @@
return rcmail.is_framed() && parent.rcmail.env.files_token ? parent.rcmail.env.files_token : rcmail.env.files_token;
};
+// Event handler for refresh/keep-alive action that can bring a refreshed access token
+function kolab_files_token_refresh(data)
+{
+ var i, win, env = data && data.response ? data.response.env : {};
+
+ if (!env.files_token || rcmail.env.files_token == env.files_token) {
+ return;
+ }
+
+ file_api.set_env({ token: env.files_token });
+
+ // Propagate the change to all iframes
+ for (i = 0; i < window.frames.length; i++) {
+ win = window.frames[i];
+ try {
+ win.file_api.set_env({ token: env.files_token });
+ } catch (e) {
+ // ignore
+ }
+ }
+};
+
function kolab_files_from_cloud_widget(elem)
{
$('<a class="button btn btn-secondary fromcloud">')
diff --git a/plugins/kolab_files/kolab_files.php b/plugins/kolab_files/kolab_files.php
--- a/plugins/kolab_files/kolab_files.php
+++ b/plugins/kolab_files/kolab_files.php
@@ -39,22 +39,14 @@
// we use libkolab::http_request() from libkolab with its configuration
$this->require_plugin('libkolab');
+ // Register hooks related to token refresh (must be before is_token_valid() below)
+ $this->add_hook('refresh', [$this, 'refresh']);
+ $this->add_hook('oauth_refresh_token', [$this, 'oauth_refresh_token']);
+
if (isset($this->rc->oauth)) {
$this->rc->oauth->is_token_valid();
-
- // This is excessive, but we have no good way of detecting when chwala no longer has a valid token,
- // and we have to make sure kolab_files_engine::get_api_token triggers the chwala_authenticate hook,
- // to update the credentials it uses to retrieve a new token.
- $_SESSION['kolab_files_token'] = null;
- if ($engine = $this->engine()) {
- $this->rc->output->set_env('files_token', $engine->get_api_token());
- }
}
- // Register hooks
- $this->add_hook('refresh', [$this, 'refresh']);
- $this->add_hook('oauth_refresh_token', [$this, 'oauth_refresh_token']);
-
// Plugin actions for other tasks
$this->register_action('plugin.kolab_files', [$this, 'actions']);

File Metadata

Mime Type
text/plain
Expires
Fri, Apr 3, 7:43 PM (13 h, 38 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18826100
Default Alt Text
D5139.1775245406.diff (2 KB)

Event Timeline