Skip to content

Commit

Permalink
Merge pull request #237 from cozy/fix-auth-old-browsers
Browse files Browse the repository at this point in the history
Fix auth old browsers
  • Loading branch information
ptbrowne authored Dec 4, 2017
2 parents d8ff8a6 + 6199abb commit f283160
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
16 changes: 13 additions & 3 deletions dist/cozy-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,18 @@ return /******/ (function(modules) { // webpackBootstrap
updateLastSync: settings.updateLastSync
};

var ensureHasReconnectParam = function ensureHasReconnectParam(_url) {
var url = new URL(_url);
if (url.searchParams && !url.searchParams.has('reconnect')) {
url.searchParams.append('reconnect', 1);
} else if (!url.search || url.search.indexOf('reconnect') === -1) {
// Some old navigators do not have the searchParams API
// and it is not polyfilled by babel-polyfill
url.search = url.search + '&reconnect=1';
}
return url.toString();
};

var Client = function () {
function Client(options) {
_classCallCheck(this, Client);
Expand Down Expand Up @@ -811,9 +823,7 @@ return /******/ (function(modules) { // webpackBootstrap
}
if (_this._oauth) {
if (forceTokenRefresh && _this._clientParams.redirectURI) {
var url = new URL(_this._clientParams.redirectURI);
if (!url.searchParams.has('reconnect')) url.searchParams.append('reconnect', 1);
_this._clientParams.redirectURI = url.toString();
_this._clientParams.redirectURI = ensureHasReconnectParam(_this._clientParams.redirectURI);
}
return auth.oauthFlow(_this, _this._storage, _this._clientParams, _this._onRegistered, forceTokenRefresh);
}
Expand Down
2 changes: 1 addition & 1 deletion dist/cozy-client.js.map

Large diffs are not rendered by default.

16 changes: 13 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@ const settingsProto = {
updateLastSync: settings.updateLastSync
}

const ensureHasReconnectParam = _url => {
const url = new URL(_url)
if (url.searchParams && !url.searchParams.has('reconnect')) {
url.searchParams.append('reconnect', 1)
} else if (!url.search || url.search.indexOf('reconnect') === -1) {
// Some old navigators do not have the searchParams API
// and it is not polyfilled by babel-polyfill
url.search = url.search + '&reconnect=1'
}
return url.toString()
}

class Client {
constructor (options) {
this.data = {}
Expand Down Expand Up @@ -220,9 +232,7 @@ class Client {
}
if (this._oauth) {
if (forceTokenRefresh && this._clientParams.redirectURI) {
const url = new URL(this._clientParams.redirectURI)
if (!url.searchParams.has('reconnect')) url.searchParams.append('reconnect', 1)
this._clientParams.redirectURI = url.toString()
this._clientParams.redirectURI = ensureHasReconnectParam(this._clientParams.redirectURI)
}
return auth.oauthFlow(
this,
Expand Down

0 comments on commit f283160

Please sign in to comment.