@simbachain/vue-authenticate
Advanced tools
Comparing version 1.5.5 to 1.5.6
@@ -329,3 +329,3 @@ /** | ||
function Promise(fn) { | ||
function Promise$1(fn) { | ||
if (typeof this !== 'object') | ||
@@ -351,3 +351,3 @@ throw new TypeError('Promises must be constructed via new'); | ||
self._handled = true; | ||
Promise._immediateFn(function () { | ||
Promise$1._immediateFn(function () { | ||
var cb = self._state === 1 ? deferred.onFulfilled : deferred.onRejected; | ||
@@ -379,3 +379,3 @@ if (cb === null) { | ||
var then = newValue.then; | ||
if (newValue instanceof Promise) { | ||
if (newValue instanceof Promise$1) { | ||
self._state = 3; | ||
@@ -406,5 +406,5 @@ self._value = newValue; | ||
if (self._state === 2 && self._deferreds.length === 0) { | ||
Promise._immediateFn(function () { | ||
Promise$1._immediateFn(function () { | ||
if (!self._handled) { | ||
Promise._unhandledRejectionFn(self._value); | ||
Promise$1._unhandledRejectionFn(self._value); | ||
} | ||
@@ -454,7 +454,7 @@ }); | ||
Promise.prototype['catch'] = function (onRejected) { | ||
Promise$1.prototype['catch'] = function (onRejected) { | ||
return this.then(null, onRejected); | ||
}; | ||
Promise.prototype.then = function (onFulfilled, onRejected) { | ||
Promise$1.prototype.then = function (onFulfilled, onRejected) { | ||
var prom = new this.constructor(noop); | ||
@@ -466,6 +466,6 @@ | ||
Promise.all = function (arr) { | ||
Promise$1.all = function (arr) { | ||
var args = Array.prototype.slice.call(arr); | ||
return new Promise(function (resolve, reject) { | ||
return new Promise$1(function (resolve, reject) { | ||
if (args.length === 0) return resolve([]); | ||
@@ -504,8 +504,8 @@ var remaining = args.length; | ||
Promise.resolve = function (value) { | ||
if (value && typeof value === 'object' && value.constructor === Promise) { | ||
Promise$1.resolve = function (value) { | ||
if (value && typeof value === 'object' && value.constructor === Promise$1) { | ||
return value; | ||
} | ||
return new Promise(function (resolve) { | ||
return new Promise$1(function (resolve) { | ||
resolve(value); | ||
@@ -515,4 +515,4 @@ }); | ||
Promise.reject = function (value) { | ||
return new Promise(function (resolve, reject) { | ||
Promise$1.reject = function (value) { | ||
return new Promise$1(function (resolve, reject) { | ||
reject(value); | ||
@@ -522,4 +522,4 @@ }); | ||
Promise.race = function (values) { | ||
return new Promise(function (resolve, reject) { | ||
Promise$1.race = function (values) { | ||
return new Promise$1(function (resolve, reject) { | ||
for (var i = 0, len = values.length; i < len; i++) { | ||
@@ -532,3 +532,3 @@ values[i].then(resolve, reject); | ||
// Use polyfill for setImmediate for performance gains | ||
Promise._immediateFn = | ||
Promise$1._immediateFn = | ||
(typeof setImmediate === 'function' && | ||
@@ -542,3 +542,3 @@ function (fn) { | ||
Promise._unhandledRejectionFn = function _unhandledRejectionFn(err) { | ||
Promise$1._unhandledRejectionFn = function _unhandledRejectionFn(err) { | ||
if (typeof console !== 'undefined' && console) { | ||
@@ -554,4 +554,4 @@ console.warn('Possible Unhandled Promise Rejection:', err); // eslint-disable-line no-console | ||
*/ | ||
Promise._setImmediateFn = function _setImmediateFn(fn) { | ||
Promise._immediateFn = fn; | ||
Promise$1._setImmediateFn = function _setImmediateFn(fn) { | ||
Promise$1._immediateFn = fn; | ||
}; | ||
@@ -564,4 +564,4 @@ | ||
*/ | ||
Promise._setUnhandledRejectionFn = function _setUnhandledRejectionFn(fn) { | ||
Promise._unhandledRejectionFn = fn; | ||
Promise$1._setUnhandledRejectionFn = function _setUnhandledRejectionFn(fn) { | ||
Promise$1._unhandledRejectionFn = fn; | ||
}; | ||
@@ -959,3 +959,3 @@ | ||
if (skipPooling) { | ||
return Promise.resolve(); | ||
return Promise$1.resolve(); | ||
} else { | ||
@@ -965,3 +965,3 @@ return this.pooling(redirectUri); | ||
} catch (e) { | ||
return Promise.reject(new Error('OAuth popup error occurred')); | ||
return Promise$1.reject(new Error('OAuth popup error occurred')); | ||
} | ||
@@ -971,3 +971,3 @@ } | ||
pooling(redirectUri) { | ||
return new Promise((resolve, reject) => { | ||
return new Promise$1((resolve, reject) => { | ||
const redirectUriParser = $document.createElement('a'); | ||
@@ -1037,3 +1037,3 @@ redirectUriParser.href = redirectUri; | ||
const defaultProviderConfig = { | ||
const defaultProviderConfig$1 = { | ||
name: null, | ||
@@ -1056,3 +1056,3 @@ url: null, | ||
this.storage = storage; | ||
this.providerConfig = objectExtend({}, defaultProviderConfig); | ||
this.providerConfig = objectExtend({}, defaultProviderConfig$1); | ||
this.providerConfig = objectExtend(this.providerConfig, providerConfig); | ||
@@ -1168,3 +1168,3 @@ this.options = options; | ||
*/ | ||
const defaultProviderConfig$1 = { | ||
const defaultProviderConfig = { | ||
name: null, | ||
@@ -1210,3 +1210,3 @@ url: null, | ||
this.storage = storage; | ||
this.providerConfig = objectExtend({}, defaultProviderConfig$1); | ||
this.providerConfig = objectExtend({}, defaultProviderConfig); | ||
this.providerConfig = objectExtend(this.providerConfig, providerConfig); | ||
@@ -1255,3 +1255,3 @@ this.options = options; | ||
return new Promise((resolve, reject) => { | ||
return new Promise$1((resolve, reject) => { | ||
this.oauthPopup | ||
@@ -1724,3 +1724,3 @@ .open(this.providerConfig.redirectUri) | ||
if(this.isAuthenticated()){ | ||
return Promise.resolve(response); | ||
return Promise$1.resolve(response); | ||
} | ||
@@ -1730,3 +1730,3 @@ throw new Error('Server did not provided an access token.'); | ||
.catch(error => { | ||
return Promise.reject(error) | ||
return Promise$1.reject(error) | ||
}) | ||
@@ -1748,5 +1748,5 @@ } | ||
this.setRefreshToken(response); | ||
return Promise.resolve(response); | ||
return Promise$1.resolve(response); | ||
}) | ||
.catch(err => Promise.reject(err)) | ||
.catch(err => Promise$1.reject(err)) | ||
} | ||
@@ -1761,3 +1761,3 @@ | ||
if (!this.isAuthenticated()) { | ||
return Promise.reject( | ||
return Promise$1.reject( | ||
new Error('There is no currently authenticated user') | ||
@@ -1782,8 +1782,8 @@ ); | ||
this.storage.removeItem(this.tokenName); | ||
return Promise.resolve(response); | ||
return Promise$1.resolve(response); | ||
}) | ||
.catch(err => Promise.reject(err)) | ||
.catch(err => Promise$1.reject(err)) | ||
} else { | ||
this.storage.removeItem(this.tokenName); | ||
return Promise.resolve(); | ||
return Promise$1.resolve(); | ||
} | ||
@@ -1850,3 +1850,3 @@ } | ||
authenticate(provider, userData) { | ||
return new Promise((resolve, reject) => { | ||
return new Promise$1((resolve, reject) => { | ||
var providerConfig = this.options.providers[provider]; | ||
@@ -1904,3 +1904,3 @@ if (!providerConfig) { | ||
link(provider, userData) { | ||
return new Promise((resolve, reject) => { | ||
return new Promise$1((resolve, reject) => { | ||
var providerConfig = this.options.providers[provider]; | ||
@@ -1968,3 +1968,3 @@ if (!providerConfig) { | ||
var chain = []; | ||
var promise = Promise.reject(error); | ||
var promise = Promise$1.reject(error); | ||
@@ -1982,3 +1982,3 @@ this.options.refreshAuthFailInterceptors.forEach((interceptor)=>{ | ||
defaultBindResponseInterceptor = ($auth) => { | ||
defaultBindResponseInterceptor($auth) { | ||
$auth.$http.interceptors.response.use((response) => { | ||
@@ -2031,3 +2031,3 @@ return response | ||
// If refresh is already going, our request will run after it, e.g. when refreshed | ||
return new Promise((resolve, reject) =>{ | ||
return new Promise$1((resolve, reject) =>{ | ||
setTimeout(()=>{ | ||
@@ -2039,3 +2039,3 @@ $auth.$http(originalRequest).then(resolve).catch(reject); | ||
} | ||
return Promise.reject(error) | ||
return Promise$1.reject(error) | ||
}); | ||
@@ -2042,0 +2042,0 @@ } |
@@ -321,3 +321,3 @@ /** | ||
function Promise(fn) { | ||
function Promise$1(fn) { | ||
if (typeof this !== 'object') | ||
@@ -343,3 +343,3 @@ throw new TypeError('Promises must be constructed via new'); | ||
self._handled = true; | ||
Promise._immediateFn(function () { | ||
Promise$1._immediateFn(function () { | ||
var cb = self._state === 1 ? deferred.onFulfilled : deferred.onRejected; | ||
@@ -371,3 +371,3 @@ if (cb === null) { | ||
var then = newValue.then; | ||
if (newValue instanceof Promise) { | ||
if (newValue instanceof Promise$1) { | ||
self._state = 3; | ||
@@ -398,5 +398,5 @@ self._value = newValue; | ||
if (self._state === 2 && self._deferreds.length === 0) { | ||
Promise._immediateFn(function () { | ||
Promise$1._immediateFn(function () { | ||
if (!self._handled) { | ||
Promise._unhandledRejectionFn(self._value); | ||
Promise$1._unhandledRejectionFn(self._value); | ||
} | ||
@@ -446,7 +446,7 @@ }); | ||
Promise.prototype['catch'] = function (onRejected) { | ||
Promise$1.prototype['catch'] = function (onRejected) { | ||
return this.then(null, onRejected); | ||
}; | ||
Promise.prototype.then = function (onFulfilled, onRejected) { | ||
Promise$1.prototype.then = function (onFulfilled, onRejected) { | ||
var prom = new this.constructor(noop); | ||
@@ -458,6 +458,6 @@ | ||
Promise.all = function (arr) { | ||
Promise$1.all = function (arr) { | ||
var args = Array.prototype.slice.call(arr); | ||
return new Promise(function (resolve, reject) { | ||
return new Promise$1(function (resolve, reject) { | ||
if (args.length === 0) return resolve([]); | ||
@@ -496,8 +496,8 @@ var remaining = args.length; | ||
Promise.resolve = function (value) { | ||
if (value && typeof value === 'object' && value.constructor === Promise) { | ||
Promise$1.resolve = function (value) { | ||
if (value && typeof value === 'object' && value.constructor === Promise$1) { | ||
return value; | ||
} | ||
return new Promise(function (resolve) { | ||
return new Promise$1(function (resolve) { | ||
resolve(value); | ||
@@ -507,4 +507,4 @@ }); | ||
Promise.reject = function (value) { | ||
return new Promise(function (resolve, reject) { | ||
Promise$1.reject = function (value) { | ||
return new Promise$1(function (resolve, reject) { | ||
reject(value); | ||
@@ -514,4 +514,4 @@ }); | ||
Promise.race = function (values) { | ||
return new Promise(function (resolve, reject) { | ||
Promise$1.race = function (values) { | ||
return new Promise$1(function (resolve, reject) { | ||
for (var i = 0, len = values.length; i < len; i++) { | ||
@@ -524,3 +524,3 @@ values[i].then(resolve, reject); | ||
// Use polyfill for setImmediate for performance gains | ||
Promise._immediateFn = | ||
Promise$1._immediateFn = | ||
(typeof setImmediate === 'function' && | ||
@@ -534,3 +534,3 @@ function (fn) { | ||
Promise._unhandledRejectionFn = function _unhandledRejectionFn(err) { | ||
Promise$1._unhandledRejectionFn = function _unhandledRejectionFn(err) { | ||
if (typeof console !== 'undefined' && console) { | ||
@@ -546,4 +546,4 @@ console.warn('Possible Unhandled Promise Rejection:', err); // eslint-disable-line no-console | ||
*/ | ||
Promise._setImmediateFn = function _setImmediateFn(fn) { | ||
Promise._immediateFn = fn; | ||
Promise$1._setImmediateFn = function _setImmediateFn(fn) { | ||
Promise$1._immediateFn = fn; | ||
}; | ||
@@ -556,4 +556,4 @@ | ||
*/ | ||
Promise._setUnhandledRejectionFn = function _setUnhandledRejectionFn(fn) { | ||
Promise._unhandledRejectionFn = fn; | ||
Promise$1._setUnhandledRejectionFn = function _setUnhandledRejectionFn(fn) { | ||
Promise$1._unhandledRejectionFn = fn; | ||
}; | ||
@@ -951,3 +951,3 @@ | ||
if (skipPooling) { | ||
return Promise.resolve(); | ||
return Promise$1.resolve(); | ||
} else { | ||
@@ -957,3 +957,3 @@ return this.pooling(redirectUri); | ||
} catch (e) { | ||
return Promise.reject(new Error('OAuth popup error occurred')); | ||
return Promise$1.reject(new Error('OAuth popup error occurred')); | ||
} | ||
@@ -963,3 +963,3 @@ } | ||
pooling(redirectUri) { | ||
return new Promise((resolve, reject) => { | ||
return new Promise$1((resolve, reject) => { | ||
const redirectUriParser = $document.createElement('a'); | ||
@@ -1029,3 +1029,3 @@ redirectUriParser.href = redirectUri; | ||
const defaultProviderConfig = { | ||
const defaultProviderConfig$1 = { | ||
name: null, | ||
@@ -1048,3 +1048,3 @@ url: null, | ||
this.storage = storage; | ||
this.providerConfig = objectExtend({}, defaultProviderConfig); | ||
this.providerConfig = objectExtend({}, defaultProviderConfig$1); | ||
this.providerConfig = objectExtend(this.providerConfig, providerConfig); | ||
@@ -1160,3 +1160,3 @@ this.options = options; | ||
*/ | ||
const defaultProviderConfig$1 = { | ||
const defaultProviderConfig = { | ||
name: null, | ||
@@ -1202,3 +1202,3 @@ url: null, | ||
this.storage = storage; | ||
this.providerConfig = objectExtend({}, defaultProviderConfig$1); | ||
this.providerConfig = objectExtend({}, defaultProviderConfig); | ||
this.providerConfig = objectExtend(this.providerConfig, providerConfig); | ||
@@ -1247,3 +1247,3 @@ this.options = options; | ||
return new Promise((resolve, reject) => { | ||
return new Promise$1((resolve, reject) => { | ||
this.oauthPopup | ||
@@ -1716,3 +1716,3 @@ .open(this.providerConfig.redirectUri) | ||
if(this.isAuthenticated()){ | ||
return Promise.resolve(response); | ||
return Promise$1.resolve(response); | ||
} | ||
@@ -1722,3 +1722,3 @@ throw new Error('Server did not provided an access token.'); | ||
.catch(error => { | ||
return Promise.reject(error) | ||
return Promise$1.reject(error) | ||
}) | ||
@@ -1740,5 +1740,5 @@ } | ||
this.setRefreshToken(response); | ||
return Promise.resolve(response); | ||
return Promise$1.resolve(response); | ||
}) | ||
.catch(err => Promise.reject(err)) | ||
.catch(err => Promise$1.reject(err)) | ||
} | ||
@@ -1753,3 +1753,3 @@ | ||
if (!this.isAuthenticated()) { | ||
return Promise.reject( | ||
return Promise$1.reject( | ||
new Error('There is no currently authenticated user') | ||
@@ -1774,8 +1774,8 @@ ); | ||
this.storage.removeItem(this.tokenName); | ||
return Promise.resolve(response); | ||
return Promise$1.resolve(response); | ||
}) | ||
.catch(err => Promise.reject(err)) | ||
.catch(err => Promise$1.reject(err)) | ||
} else { | ||
this.storage.removeItem(this.tokenName); | ||
return Promise.resolve(); | ||
return Promise$1.resolve(); | ||
} | ||
@@ -1842,3 +1842,3 @@ } | ||
authenticate(provider, userData) { | ||
return new Promise((resolve, reject) => { | ||
return new Promise$1((resolve, reject) => { | ||
var providerConfig = this.options.providers[provider]; | ||
@@ -1896,3 +1896,3 @@ if (!providerConfig) { | ||
link(provider, userData) { | ||
return new Promise((resolve, reject) => { | ||
return new Promise$1((resolve, reject) => { | ||
var providerConfig = this.options.providers[provider]; | ||
@@ -1960,3 +1960,3 @@ if (!providerConfig) { | ||
var chain = []; | ||
var promise = Promise.reject(error); | ||
var promise = Promise$1.reject(error); | ||
@@ -1974,3 +1974,3 @@ this.options.refreshAuthFailInterceptors.forEach((interceptor)=>{ | ||
defaultBindResponseInterceptor = ($auth) => { | ||
defaultBindResponseInterceptor($auth) { | ||
$auth.$http.interceptors.response.use((response) => { | ||
@@ -2023,3 +2023,3 @@ return response | ||
// If refresh is already going, our request will run after it, e.g. when refreshed | ||
return new Promise((resolve, reject) =>{ | ||
return new Promise$1((resolve, reject) =>{ | ||
setTimeout(()=>{ | ||
@@ -2031,3 +2031,3 @@ $auth.$http(originalRequest).then(resolve).catch(reject); | ||
} | ||
return Promise.reject(error) | ||
return Promise$1.reject(error) | ||
}); | ||
@@ -2034,0 +2034,0 @@ } |
/** | ||
* vue-authenticate v1.5.4 | ||
* vue-authenticate v1.5.5 | ||
* https://github.com/dgrubelic/vue-authenticate | ||
@@ -335,3 +335,3 @@ * Released under the MIT License. | ||
function Promise(fn) { | ||
function Promise$1(fn) { | ||
if (typeof this !== 'object') | ||
@@ -357,3 +357,3 @@ { throw new TypeError('Promises must be constructed via new'); } | ||
self._handled = true; | ||
Promise._immediateFn(function () { | ||
Promise$1._immediateFn(function () { | ||
var cb = self._state === 1 ? deferred.onFulfilled : deferred.onRejected; | ||
@@ -385,3 +385,3 @@ if (cb === null) { | ||
var then = newValue.then; | ||
if (newValue instanceof Promise) { | ||
if (newValue instanceof Promise$1) { | ||
self._state = 3; | ||
@@ -412,5 +412,5 @@ self._value = newValue; | ||
if (self._state === 2 && self._deferreds.length === 0) { | ||
Promise._immediateFn(function () { | ||
Promise$1._immediateFn(function () { | ||
if (!self._handled) { | ||
Promise._unhandledRejectionFn(self._value); | ||
Promise$1._unhandledRejectionFn(self._value); | ||
} | ||
@@ -460,7 +460,7 @@ }); | ||
Promise.prototype['catch'] = function (onRejected) { | ||
Promise$1.prototype['catch'] = function (onRejected) { | ||
return this.then(null, onRejected); | ||
}; | ||
Promise.prototype.then = function (onFulfilled, onRejected) { | ||
Promise$1.prototype.then = function (onFulfilled, onRejected) { | ||
var prom = new this.constructor(noop); | ||
@@ -472,6 +472,6 @@ | ||
Promise.all = function (arr) { | ||
Promise$1.all = function (arr) { | ||
var args = Array.prototype.slice.call(arr); | ||
return new Promise(function (resolve, reject) { | ||
return new Promise$1(function (resolve, reject) { | ||
if (args.length === 0) { return resolve([]); } | ||
@@ -510,8 +510,8 @@ var remaining = args.length; | ||
Promise.resolve = function (value) { | ||
if (value && typeof value === 'object' && value.constructor === Promise) { | ||
Promise$1.resolve = function (value) { | ||
if (value && typeof value === 'object' && value.constructor === Promise$1) { | ||
return value; | ||
} | ||
return new Promise(function (resolve) { | ||
return new Promise$1(function (resolve) { | ||
resolve(value); | ||
@@ -521,4 +521,4 @@ }); | ||
Promise.reject = function (value) { | ||
return new Promise(function (resolve, reject) { | ||
Promise$1.reject = function (value) { | ||
return new Promise$1(function (resolve, reject) { | ||
reject(value); | ||
@@ -528,4 +528,4 @@ }); | ||
Promise.race = function (values) { | ||
return new Promise(function (resolve, reject) { | ||
Promise$1.race = function (values) { | ||
return new Promise$1(function (resolve, reject) { | ||
for (var i = 0, len = values.length; i < len; i++) { | ||
@@ -538,3 +538,3 @@ values[i].then(resolve, reject); | ||
// Use polyfill for setImmediate for performance gains | ||
Promise._immediateFn = | ||
Promise$1._immediateFn = | ||
(typeof setImmediate === 'function' && | ||
@@ -548,3 +548,3 @@ function (fn) { | ||
Promise._unhandledRejectionFn = function _unhandledRejectionFn(err) { | ||
Promise$1._unhandledRejectionFn = function _unhandledRejectionFn(err) { | ||
if (typeof console !== 'undefined' && console) { | ||
@@ -560,4 +560,4 @@ console.warn('Possible Unhandled Promise Rejection:', err); // eslint-disable-line no-console | ||
*/ | ||
Promise._setImmediateFn = function _setImmediateFn(fn) { | ||
Promise._immediateFn = fn; | ||
Promise$1._setImmediateFn = function _setImmediateFn(fn) { | ||
Promise$1._immediateFn = fn; | ||
}; | ||
@@ -570,4 +570,4 @@ | ||
*/ | ||
Promise._setUnhandledRejectionFn = function _setUnhandledRejectionFn(fn) { | ||
Promise._unhandledRejectionFn = fn; | ||
Promise$1._setUnhandledRejectionFn = function _setUnhandledRejectionFn(fn) { | ||
Promise$1._unhandledRejectionFn = fn; | ||
}; | ||
@@ -956,3 +956,3 @@ | ||
if (skipPooling) { | ||
return Promise.resolve(); | ||
return Promise$1.resolve(); | ||
} else { | ||
@@ -962,3 +962,3 @@ return this.pooling(redirectUri); | ||
} catch (e) { | ||
return Promise.reject(new Error('OAuth popup error occurred')); | ||
return Promise$1.reject(new Error('OAuth popup error occurred')); | ||
} | ||
@@ -970,3 +970,3 @@ }; | ||
return new Promise(function (resolve, reject) { | ||
return new Promise$1(function (resolve, reject) { | ||
var redirectUriParser = $document.createElement('a'); | ||
@@ -1035,3 +1035,3 @@ redirectUriParser.href = redirectUri; | ||
var defaultProviderConfig = { | ||
var defaultProviderConfig$1 = { | ||
name: null, | ||
@@ -1053,3 +1053,3 @@ url: null, | ||
this.storage = storage; | ||
this.providerConfig = objectExtend({}, defaultProviderConfig); | ||
this.providerConfig = objectExtend({}, defaultProviderConfig$1); | ||
this.providerConfig = objectExtend(this.providerConfig, providerConfig); | ||
@@ -1165,3 +1165,3 @@ this.options = options; | ||
*/ | ||
var defaultProviderConfig$1 = { | ||
var defaultProviderConfig = { | ||
name: null, | ||
@@ -1206,3 +1206,3 @@ url: null, | ||
this.storage = storage; | ||
this.providerConfig = objectExtend({}, defaultProviderConfig$1); | ||
this.providerConfig = objectExtend({}, defaultProviderConfig); | ||
this.providerConfig = objectExtend(this.providerConfig, providerConfig); | ||
@@ -1252,3 +1252,3 @@ this.options = options; | ||
return new Promise(function (resolve, reject) { | ||
return new Promise$1(function (resolve, reject) { | ||
this$1.oauthPopup | ||
@@ -1722,3 +1722,3 @@ .open(this$1.providerConfig.redirectUri) | ||
if(this$1.isAuthenticated()){ | ||
return Promise.resolve(response); | ||
return Promise$1.resolve(response); | ||
} | ||
@@ -1728,3 +1728,3 @@ throw new Error('Server did not provided an access token.'); | ||
.catch(function (error) { | ||
return Promise.reject(error) | ||
return Promise$1.reject(error) | ||
}) | ||
@@ -1748,5 +1748,5 @@ }; | ||
this$1.setRefreshToken(response); | ||
return Promise.resolve(response); | ||
return Promise$1.resolve(response); | ||
}) | ||
.catch(function (err) { return Promise.reject(err); }) | ||
.catch(function (err) { return Promise$1.reject(err); }) | ||
}; | ||
@@ -1763,3 +1763,3 @@ | ||
if (!this.isAuthenticated()) { | ||
return Promise.reject( | ||
return Promise$1.reject( | ||
new Error('There is no currently authenticated user') | ||
@@ -1784,8 +1784,8 @@ ); | ||
this$1.storage.removeItem(this$1.tokenName); | ||
return Promise.resolve(response); | ||
return Promise$1.resolve(response); | ||
}) | ||
.catch(function (err) { return Promise.reject(err); }) | ||
.catch(function (err) { return Promise$1.reject(err); }) | ||
} else { | ||
this.storage.removeItem(this.tokenName); | ||
return Promise.resolve(); | ||
return Promise$1.resolve(); | ||
} | ||
@@ -1856,3 +1856,3 @@ }; | ||
return new Promise(function (resolve, reject) { | ||
return new Promise$1(function (resolve, reject) { | ||
var providerConfig = this$1.options.providers[provider]; | ||
@@ -1912,3 +1912,3 @@ if (!providerConfig) { | ||
return new Promise(function (resolve, reject) { | ||
return new Promise$1(function (resolve, reject) { | ||
var providerConfig = this$1.options.providers[provider]; | ||
@@ -1975,10 +1975,10 @@ if (!providerConfig) { | ||
var chain = []; | ||
var promise = Promise.resolve(error); | ||
var promise = Promise$1.reject(error); | ||
this.options.refreshAuthFailInterceptors.forEach(function (interceptor){ | ||
chain.unshift(interceptor.fulfilled, interceptor.rejected); | ||
chain.unshift(interceptor); | ||
}); | ||
while (chain.length) { | ||
promise = promise.then(chain.shift(), chain.shift()); | ||
promise = promise.catch(chain.shift()); | ||
} | ||
@@ -1990,4 +1990,2 @@ | ||
VueAuthenticate.prototype.defaultBindResponseInterceptor = function defaultBindResponseInterceptor ($auth) { | ||
var this$1 = this; | ||
$auth.$http.interceptors.response.use(function (response) { | ||
@@ -2009,9 +2007,9 @@ return response | ||
if (!$auth._isRefreshing) { | ||
if(this$1.last_token_refresh_attempt && | ||
((new Date) - this$1.last_token_refresh_attempt) < 5*60*100){ //check we haven't tried to refresh in the last 5 minutes | ||
if($auth.last_token_refresh_attempt && | ||
((new Date) - $auth.last_token_refresh_attempt) < 5*60*100){ //check we haven't tried to refresh in the last 5 minutes | ||
// Don't retry a refresh on fail | ||
return this$1.runAuthInterceptor(error); | ||
return $auth.runAuthInterceptor(error); | ||
} | ||
$auth._isRefreshing = true; | ||
this$1.last_token_refresh_attempt = new Date(); | ||
$auth.last_token_refresh_attempt = new Date(); | ||
// Try to refresh our token | ||
@@ -2030,3 +2028,3 @@ try { | ||
// return Promise.reject(error) | ||
return this$1.runAuthInterceptor(error) | ||
return $auth.runAuthInterceptor(error) | ||
}) | ||
@@ -2038,3 +2036,3 @@ }catch (e){ | ||
// return Promise.reject(error) | ||
return this$1.runAuthInterceptor(error) | ||
return $auth.runAuthInterceptor(error) | ||
@@ -2044,3 +2042,3 @@ } | ||
// If refresh is already going, our request will run after it, e.g. when refreshed | ||
return new Promise(function (resolve, reject) { | ||
return new Promise$1(function (resolve, reject) { | ||
setTimeout(function (){ | ||
@@ -2052,3 +2050,3 @@ $auth.$http(originalRequest).then(resolve).catch(reject); | ||
} | ||
return Promise.reject(error) | ||
return Promise$1.reject(error) | ||
}); | ||
@@ -2055,0 +2053,0 @@ }; |
/** | ||
* vue-authenticate v1.5.4 | ||
* vue-authenticate v1.5.5 | ||
* https://github.com/dgrubelic/vue-authenticate | ||
@@ -8,2 +8,2 @@ * Released under the MIT License. | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("crypto-js/sha256"),require("crypto-js/enc-base64"),require("crypto-js/lib-typedarrays")):"function"==typeof define&&define.amd?define(["crypto-js/sha256","crypto-js/enc-base64","crypto-js/lib-typedarrays"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).VueAuthenticate=t(e.sha256,e.Base64,e.WordArray)}(this,function(e,t,o){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=r(e),a=r(t),n=r(o);function i(e){return void 0===e}function p(e){return"function"==typeof e}function u(t,o){return null==t||null==o||Object.keys(o).forEach(function(e){"[object Object]"!=Object.prototype.toString.call(o[e])||"[object Object]"!=Object.prototype.toString.call(t[e])?t[e]=o[e]:t[e]=u(t[e],o[e])}),t}function h(e,t){if(/^(?:[a-z]+:)?\/\//i.test(t))return t;return[e,t].join("/").replace(/[\/]+/g,"/").replace(/\/\?/g,"?").replace(/\/\#/g,"#").replace(/\:\//g,"://")}function c(e){var t="https:"===e.protocol;return e.protocol+"//"+e.hostname+":"+(e.port||(t?"443":"80"))+(/^\//.test(e.pathname)?e.pathname:"/"+e.pathname)}function l(e){var t,o,r={};return(e||"").split("&").forEach(function(e){e&&(o=e.split("="),t=decodeURIComponent(o[0]),r[t]=!o[1]||decodeURIComponent(o[1]))}),r}function f(e){var t;if("undefined"!=typeof module&&module.exports)try{t=require("buffer").Buffer}catch(e){}function o(e){switch(e.length){case 4:var t=((7&e.charCodeAt(0))<<18|(63&e.charCodeAt(1))<<12|(63&e.charCodeAt(2))<<6|63&e.charCodeAt(3))-65536;return r(55296+(t>>>10))+r(56320+(1023&t));case 3:return r((15&e.charCodeAt(0))<<12|(63&e.charCodeAt(1))<<6|63&e.charCodeAt(2));default:return r((31&e.charCodeAt(0))<<6|63&e.charCodeAt(1))}}var r=String.fromCharCode,n=new RegExp(["[À-ß][-¿]","[à-ï][-¿]{2}","[ð-÷][-¿]{3}"].join("|"),"g");return(t?function(e){return(e.constructor===t.constructor?e:new t(e,"base64")).toString()}:function(e){return atob(e).replace(n,o)})(String(e).replace(/[-_]/g,function(e){return"-"===e?"+":"/"}).replace(/[^A-Za-z0-9\+\/]/g,""))}function d(e,t,o){return[encodeURIComponent(e),"=",encodeURIComponent(t),(e=(r=o).path,t=r.domain,o=r.expires,r=r.secure,[null==e?"":";path="+e,null==t?"":";domain="+t,null==o?"":";expires="+o.toUTCString(),null==r||!1===r?"":";secure"].join(""))].join("");var r}function g(e,t){for(var o,r=void 0,n=e,i=t.split("."),s=0;s<i.length;s++){var a=i[s],r=n[a];if(null===(o=r)||"object"!=typeof o)break;n=n[a]}return r}function m(e,t,o,r){return(e=e||{}).url=e.url||t.url||h(t.baseUrl,t.loginUrl),e[t.requestDataKey]=r||e[t.requestDataKey],e.method=e.method||"POST",e.withCredentials=e.withCredentials||t.withCredentials,e}"function"!=typeof Object.assign&&(Object.assign=function(e,t){var o=arguments;if(null==e)throw new TypeError("Cannot convert undefined or null to object");for(var r=Object(e),n=1;n<arguments.length;n++){var i=o[n];if(null!=i)for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(r[s]=i[s])}return r});var y=setTimeout;function v(){}function w(e){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],b(e,this)}function k(o,r){for(;3===o._state;)o=o._value;0!==o._state?(o._handled=!0,w._immediateFn(function(){var e,t=1===o._state?r.onFulfilled:r.onRejected;if(null!==t){try{e=t(o._value)}catch(e){return void I(r.promise,e)}_(r.promise,e)}else(1===o._state?_:I)(r.promise,o._value)})):o._deferreds.push(r)}function _(t,e){try{if(e===t)throw new TypeError("A promise cannot be resolved with itself.");if(e&&("object"==typeof e||"function"==typeof e)){var o=e.then;if(e instanceof w)return t._state=3,t._value=e,void C(t);if("function"==typeof o)return void b((r=o,n=e,function(){r.apply(n,arguments)}),t)}t._state=1,t._value=e,C(t)}catch(e){I(t,e)}var r,n}function I(e,t){e._state=2,e._value=t,C(e)}function C(e){2===e._state&&0===e._deferreds.length&&w._immediateFn(function(){e._handled||w._unhandledRejectionFn(e._value)});for(var t=0,o=e._deferreds.length;t<o;t++)k(e,e._deferreds[t]);e._deferreds=null}function T(e,t,o){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof t?t:null,this.promise=o}function b(e,t){var o=!1;try{e(function(e){o||(o=!0,_(t,e))},function(e){o||(o=!0,I(t,e))})}catch(e){if(o)return;o=!0,I(t,e)}}w.prototype.catch=function(e){return this.then(null,e)},w.prototype.then=function(e,t){var o=new this.constructor(v);return k(this,new T(e,t,o)),o},w.all=function(e){var a=Array.prototype.slice.call(e);return new w(function(n,i){if(0===a.length)return n([]);var s=a.length;for(var e=0;e<a.length;e++)!function t(o,e){try{if(e&&("object"==typeof e||"function"==typeof e)){var r=e.then;if("function"==typeof r)return void r.call(e,function(e){t(o,e)},i)}a[o]=e,0==--s&&n(a)}catch(e){i(e)}}(e,a[e])})},w.resolve=function(t){return t&&"object"==typeof t&&t.constructor===w?t:new w(function(e){e(t)})},w.reject=function(o){return new w(function(e,t){t(o)})},w.race=function(n){return new w(function(e,t){for(var o=0,r=n.length;o<r;o++)n[o].then(e,t)})},w._immediateFn="function"==typeof setImmediate?function(e){setImmediate(e)}:function(e){y(e,0)},w._unhandledRejectionFn=function(e){"undefined"!=typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",e)},w._setImmediateFn=function(e){w._immediateFn=e},w._setUnhandledRejectionFn=function(e){w._unhandledRejectionFn=e};var P="undefined"!=typeof document?document:{createElement:function(){}},U="undefined"!=typeof window?window:{atob:function(){},open:function(){},location:{},localStorage:{setItem:function(){},getItem:function(){},removeItem:function(){}},sessionStorage:{setItem:function(){},getItem:function(){},removeItem:function(){}}};function j(){try{return U.location.hostname}catch(e){}return""}function R(e){try{return i(e)?U.location.origin:""+U.location.origin+e}catch(e){}return e||null}function S(e){this._defaultOptions=u({domain:j(),expires:null,path:"/",secure:!1},e)}var E={baseUrl:null,tokenPath:"access_token",refreshTokenPath:"refresh_token",tokenName:"token",tokenPrefix:"vueauth",tokenHeader:"Authorization",tokenType:"Bearer",expirationName:"expiration",expirationPrefix:null,loginUrl:"/auth/login",registerUrl:"/auth/register",logoutUrl:null,refreshUrl:"/auth/login/refresh",storageType:"localStorage",storageNamespace:"vue-authenticate",cookieStorage:{domain:j(),path:"/",secure:!1},requestDataKey:"data",responseDataKey:"data",last_token_refresh_attempt:null,refreshAuthFailInterceptors:[],bindRequestInterceptor:null,bindResponseInterceptor:null,providers:{facebook:{name:"facebook",url:"/auth/facebook",authorizationEndpoint:"https://www.facebook.com/v2.5/dialog/oauth",redirectUri:R("/"),requiredUrlParams:["display","scope"],scope:["email"],scopeDelimiter:",",display:"popup",oauthType:"2.0",popupOptions:{width:580,height:400}},google:{name:"google",url:"/auth/google",authorizationEndpoint:"https://accounts.google.com/o/oauth2/auth",redirectUri:R(),requiredUrlParams:["scope"],optionalUrlParams:["display"],scope:["profile","email"],scopePrefix:"openid",scopeDelimiter:" ",display:"popup",oauthType:"2.0",popupOptions:{width:452,height:633}},github:{name:"github",url:"/auth/github",authorizationEndpoint:"https://github.com/login/oauth/authorize",redirectUri:R(),optionalUrlParams:["scope"],scope:["user:email"],scopeDelimiter:" ",oauthType:"2.0",popupOptions:{width:1020,height:618}},instagram:{name:"instagram",url:"/auth/instagram",authorizationEndpoint:"https://api.instagram.com/oauth/authorize",redirectUri:R(),requiredUrlParams:["scope"],scope:["basic"],scopeDelimiter:"+",oauthType:"2.0",popupOptions:{width:null,height:null}},twitter:{name:"twitter",url:"/auth/twitter",authorizationEndpoint:"https://api.twitter.com/oauth/authenticate",redirectUri:R(),oauthType:"1.0",popupOptions:{width:495,height:645}},bitbucket:{name:"bitbucket",url:"/auth/bitbucket",authorizationEndpoint:"https://bitbucket.org/site/oauth2/authorize",redirectUri:R("/"),optionalUrlParams:["scope"],scope:["email"],scopeDelimiter:" ",oauthType:"2.0",popupOptions:{width:1020,height:618}},linkedin:{name:"linkedin",url:"/auth/linkedin",authorizationEndpoint:"https://www.linkedin.com/oauth/v2/authorization",redirectUri:R(),requiredUrlParams:["state","scope"],scope:["r_emailaddress"],scopeDelimiter:" ",state:"STATE",oauthType:"2.0",popupOptions:{width:527,height:582}},live:{name:"live",url:"/auth/live",authorizationEndpoint:"https://login.live.com/oauth20_authorize.srf",redirectUri:R(),requiredUrlParams:["display","scope"],scope:["wl.emails"],scopeDelimiter:" ",display:"popup",oauthType:"2.0",popupOptions:{width:500,height:560}},oauth1:{name:null,url:"/auth/oauth1",authorizationEndpoint:null,redirectUri:R(),oauthType:"1.0",popupOptions:null},oauth2:{name:null,url:"/auth/oauth2",clientId:null,redirectUri:R(),authorizationEndpoint:null,defaultUrlParams:["response_type","client_id","redirect_uri"],requiredUrlParams:null,optionalUrlParams:null,scope:null,scopePrefix:null,scopeDelimiter:null,state:null,oauthType:"2.0",popupOptions:null,responseType:"code",responseParams:{code:"code",clientId:"clientId",redirectUri:"redirectUri"}}}};S.prototype.setItem=function(e,t){t=d(e,t,u({},this._defaultOptions));this._setCookie(t)},S.prototype.getItem=function(e){var t=function(e){if(0===(e=void 0===e?"":e).length)return{};var o={},t=new RegExp("\\s*;\\s*");return e.split(t).forEach(function(e){var t=e.split("="),e=t[0],t=t[1],e=decodeURIComponent(e),t=decodeURIComponent(t);o[e]=t}),o}(this._getCookie());return t.hasOwnProperty(e)?t[e]:null},S.prototype.removeItem=function(e){var t=u({},this._defaultOptions),t=d(e,"",u(t,{expires:new Date(0)}));this._setCookie(t)},S.prototype._getCookie=function(){try{return"undefined"===P.cookie?"":P.cookie}catch(e){}return""},S.prototype._setCookie=function(e){try{P.cookie=e}catch(e){}};function O(e){this.namespace=e||null}O.prototype.setItem=function(e,t){U.localStorage.setItem(this._getStorageKey(e),t)},O.prototype.getItem=function(e){return U.localStorage.getItem(this._getStorageKey(e))},O.prototype.removeItem=function(e){U.localStorage.removeItem(this._getStorageKey(e))},O.prototype._getStorageKey=function(e){return this.namespace?[this.namespace,e].join("."):e};function x(e){this.namespace=e||null,this._storage={}}x.prototype.setItem=function(e,t){this._storage[this._getStorageKey(e)]=t},x.prototype.getItem=function(e){return this._storage[this._getStorageKey(e)]},x.prototype.removeItem=function(e){delete this._storage[this._getStorageKey(e)]},x.prototype._getStorageKey=function(e){return this.namespace?[this.namespace,e].join("."):e};function A(e){this.namespace=e||null}A.prototype.setItem=function(e,t){U.sessionStorage.setItem(this._getStorageKey(e),t)},A.prototype.getItem=function(e){return U.sessionStorage.getItem(this._getStorageKey(e))},A.prototype.removeItem=function(e){U.sessionStorage.removeItem(this._getStorageKey(e))},A.prototype._getStorageKey=function(e){return this.namespace?[this.namespace,e].join("."):e};function q(e,t,o){this.popup=null,this.url=e,this.name=t,this.popupOptions=o}q.prototype.open=function(e,t){try{return this.popup=U.open(this.url,this.name,this._stringifyOptions()),this.popup&&this.popup.focus&&this.popup.focus(),t?w.resolve():this.pooling(e)}catch(e){return w.reject(new Error("OAuth popup error occurred"))}},q.prototype.pooling=function(t){var s=this;return new w(function(o,r){var e=P.createElement("a");e.href=t;var n=c(e),i=setInterval(function(){s.popup&&!s.popup.closed&&void 0!==s.popup.closed||(clearInterval(i),i=null,r(new Error("Auth popup window closed")));try{var e,t;c(s.popup.location)===n&&(s.popup.location.search||s.popup.location.hash?(t=l(s.popup.location.search.substring(1).replace(/\/$/,"")),e=l(s.popup.location.hash.substring(1).replace(/[\/$]/,"")),t=u({},t),(t=u(t,e)).error?r(new Error(t.error)):o(t)):r(new Error("OAuth redirect has occurred but no query or hash parameters were found.")),clearInterval(i),i=null,s.popup.close())}catch(e){}},250)})},q.prototype._stringifyOptions=function(){var e,t=[];for(e in this.popupOptions)i(this.popupOptions[e])||t.push(e+"="+this.popupOptions[e]);return t.join(",")};function N(e,t,o,r){this.$http=e,this.storage=t,this.providerConfig=u({},D),this.providerConfig=u(this.providerConfig,o),this.options=r}var D={name:null,url:null,authorizationEndpoint:null,scope:null,scopePrefix:null,scopeDelimiter:null,redirectUri:null,requiredUrlParams:null,defaultUrlParams:null,oauthType:"1.0",popupOptions:{}};N.prototype.init=function(t){var o=this;return this.oauthPopup=new q("about:blank",this.providerConfig.name,this.providerConfig.popupOptions),U.cordova||this.oauthPopup.open(this.providerConfig.redirectUri,!0),this.getRequestToken().then(function(e){return o.openPopup(e).then(function(e){return o.exchangeForToken(e,t)})})},N.prototype.getRequestToken=function(){var e={method:"POST"};return e[this.options.requestDataKey]=u({},this.providerConfig),e.withCredentials=this.options.withCredentials,this.options.baseUrl?e.url=h(this.options.baseUrl,this.providerConfig.url):e.url=this.providerConfig.url,this.$http(e)},N.prototype.openPopup=function(e){e=[this.providerConfig.authorizationEndpoint,this.buildQueryString(e[this.options.responseDataKey])].join("?");return this.oauthPopup.popup.location=e,U.cordova?this.oauthPopup.open(this.providerConfig.redirectUri):this.oauthPopup.pooling(this.providerConfig.redirectUri)},N.prototype.exchangeForToken=function(e,t){t=u({},t),t=u(t,e),e={method:"POST"};return e[this.options.requestDataKey]=t,e.withCredentials=this.options.withCredentials,this.options.baseUrl?e.url=h(this.options.baseUrl,this.providerConfig.url):e.url=this.providerConfig.url,this.$http(e)};function K(e,t,o,r){this.$http=e,this.storage=t,this.providerConfig=u({},F),this.providerConfig=u(this.providerConfig,o),this.options=r}var F={name:null,url:null,clientId:null,authorizationEndpoint:null,redirectUri:null,scope:null,scopePrefix:null,scopeDelimiter:null,state:null,requiredUrlParams:null,defaultUrlParams:["response_type","client_id","redirect_uri"],responseType:"code",responseGrantType:"authorization_code",refreshGrantType:"refresh_token",refreshType:null,refreshTokenPrefix:null,tokenRequestAsForm:!(N.prototype.buildQueryString=function(e){var t,o=[];for(t in e){var r=e[t];o.push(encodeURIComponent(t)+"="+encodeURIComponent(r))}return o.join("&")}),refreshRequestAsForm:!1,pkce:!1,responseParams:{code:"code",clientId:"clientId",redirectUri:"redirectUri"},refreshParams:{clientId:"clientId",grantType:"grantType",scope:"scope"},oauthType:"2.0",popupOptions:{}};K.prototype.generateRandomForKey=function(e){return this.storage.getItem(e)||this.storage.setItem(e,n.default.random(64)),console.log(this.storage.getItem(e)),this.storage.getItem(e)},K.prototype.init=function(r){var n=this,i=this.providerConfig.name+"_state";p(this.providerConfig.state)?this.storage.setItem(i,this.providerConfig.state()):"string"==typeof this.providerConfig.state&&this.storage.setItem(i,this.providerConfig.state);var e=[this.providerConfig.authorizationEndpoint,this._stringifyRequestParams()].join("?");if("S256"===this.providerConfig.pkce){if("code"!==this.providerConfig.responseType)throw new Error("Cannot use PKCE with response type "+this.providerConfig.responseType);var t=s.default(this.generateRandomForKey(this.providerConfig.name+"_pkce")),t=a.default.stringify(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,""),e=e+"&code_challenge="+encodeURIComponent(t)+"&code_challenge_method=S256"}return this.oauthPopup=new q(e,this.providerConfig.name,this.providerConfig.popupOptions),new w(function(t,o){n.oauthPopup.open(n.providerConfig.redirectUri).then(function(e){return"token"!==n.providerConfig.responseType&&n.providerConfig.url?e.state&&e.state!==n.storage.getItem(i)?o(new Error("State parameter value does not match original OAuth request state value")):void n.exchangeForToken(e,r).then(function(e){return n.storage.removeItem(n.providerConfig.name+"_pkce"),e.data}).then(t):t(e)}).catch(function(e){o(e)})})},K.prototype.exchangeForToken=function(e,t){var o,r,n=u({},t);for(o in this.providerConfig.responseParams){var i=this.providerConfig.responseParams[o];switch(o){case"code":n[i]=e.code;break;case"clientId":n[i]=this.providerConfig.clientId;break;case"redirectUri":n[i]=this.providerConfig.redirectUri;break;case"grantType":n[i]=this.providerConfig.responseGrantType;break;default:n[i]=e[o]}}if(e.state&&(n.state=e.state),r=this.options.baseUrl?h(this.options.baseUrl,this.providerConfig.url):this.providerConfig.url,!this.providerConfig.pkce||(t=this.storage.getItem(this.providerConfig.name+"_pkce"))&&(n.code_verifier=t,n.grant_type="authorization_code",console.log(t)),this.providerConfig.tokenRequestAsForm){var s,a=new FormData;for(s in n){var p=n[s];a.append(s,p)}n=a}return this.$http.post(r,n,{withCredentials:this.options.withCredentials})},K.prototype._stringifyRequestParams=function(){var r=this,n=[];return["defaultUrlParams","requiredUrlParams","optionalUrlParams"].forEach(function(e){r.providerConfig[e]&&Array.isArray(r.providerConfig[e])&&r.providerConfig[e].forEach(function(e){var t=e.replace(/([\:\-\_]+(.))/g,function(e,t,o,r){return r?o.toUpperCase():o}),o=p(r.providerConfig[e])?r.providerConfig[e]():r.providerConfig[t];"redirect_uri"===e&&!o||("state"===e&&(t=r.providerConfig.name+"_state",o=encodeURIComponent(r.storage.getItem(t))),"scope"===e&&Array.isArray(o)&&(o=o.join(r.providerConfig.scopeDelimiter),r.providerConfig.scopePrefix&&(o=[r.providerConfig.scopePrefix,o].join(r.providerConfig.scopeDelimiter))),n.push([e,o]))})}),n.map(function(e){return e.join("=")}).join("&")},K.prototype.getRefreshToken=function(e){return"storage"===this.options.refreshType?this.storage.getItem(e):null},K.prototype.refresh=function(e){if(!this.options.storageType)throw new Error("Refreshing is not set");var t,o={};for(t in"storage"===this.options.refreshType&&(o.refresh_token=this.getRefreshToken(e)),this.providerConfig.refreshParams){var r=this.providerConfig.refreshParams[t];switch(t){case"clientId":o[r]=this.providerConfig.clientId;break;case"grantType":o[r]=this.providerConfig.refreshGrantType;break;default:o[r]=this.providerConfig[t]}}if(this.providerConfig.refreshRequestAsForm){var n,i=new FormData;for(n in o){var s=o[n];i.set(n,s)}o=i}e=m(this.providerConfig,this.options,0,o);return this.$http(e)};var $=function(e,t){var o=u({},E),r=function(e){switch(e.storageType){case"localStorage":try{return U.localStorage.setItem("testKey","test"),U.localStorage.removeItem("testKey"),new O(e.storageNamespace)}catch(e){}case"sessionStorage":try{return U.sessionStorage.setItem("testKey","test"),U.sessionStorage.removeItem("testKey"),new A(e.storageNamespace)}catch(e){}case"cookieStorage":return new S(e.cookieStorage);case"memoryStorage":default:return new x(e.storageNamespace)}}(o=u(o,t));if(Object.defineProperties(this,{$http:{get:function(){return e}},options:{get:function(){return o}},storage:{get:function(){return r}},tokenName:{get:function(){return this.options.tokenPrefix?[this.options.tokenPrefix,this.options.tokenName].join("_"):this.options.tokenName}},refreshTokenName:{get:function(){return this.options.refreshTokenPrefix?[this.options.refreshTokenPrefix,this.options.refreshTokenName].join("_"):this.options.refreshTokenName}},expirationName:{get:function(){return this.options.expirationPrefix?[this.options.expirationPrefix,this.options.expirationName].join("_"):this.options.expirationName}}}),this.options.bindRequestInterceptor){if(!p(this.options.bindRequestInterceptor))throw new Error("Request interceptor must be functions");this.options.bindRequestInterceptor.call(this,this)}else this.defaultBindRequestInterceptor.call(this,this);if(this.options.bindResponseInterceptor){if(!p(this.options.bindResponseInterceptor))throw new Error("Response interceptor must be functions");this.options.bindResponseInterceptor.call(this,this)}else this.defaultBindResponseInterceptor.call(this,this)};function z(e,t){var o;z.installed||(z.installed=!0,o=null,Object.defineProperties(e.prototype,{$auth:{get:function(){if(!o){if(!this.$http)throw new Error("Request handler instance not found");o=new $(this.$http,t)}return o}}}))}return $.prototype.isAuthenticated=function(){var e=this.storage.getItem(this.tokenName);if(e){if(3===e.split(".").length)try{var t=(t=(t=e).split(".")[1].replace("-","+").replace("_","/"),JSON.parse(window.atob(t)).exp);if("number"==typeof t)return Math.round((new Date).getTime()/1e3)<t}catch(e){return!0}return!0}return!1},$.prototype.isTokenSet=function(){return!i(this.getToken())&&!!this.getToken()},$.prototype.getToken=function(){return this.storage.getItem(this.tokenName)},$.prototype.setToken=function(e,t){t=g(e=e[this.options.responseDataKey]?e[this.options.responseDataKey]:e,t||this.options.tokenPath);t&&this.storage.setItem(this.tokenName,t)},$.prototype.getLoggedInProvider=function(){return this.storage.getItem("LoggedInProvider")},$.prototype.setLoggedInProvider=function(e){this.storage.setItem("LoggedInProvider",e)},$.prototype.getExpiration=function(){return this.options.refreshType?this.storage.getItem(this.expirationName):null},$.prototype.setRefreshToken=function(e,t){if(this.options.refreshType){if(e[this.options.responseDataKey]&&(e=e[this.options.responseDataKey]),this.setExpiration(e),"storage"!==this.options.refreshType)return e;t=g(e,t||this.options.refreshTokenPath);return(t=!t&&e?e[this.options.expirationName]:t)&&this.storage.setItem(this.refreshTokenName,t),e}},$.prototype.setExpiration=function(e){var t,o;return e.expires_in&&(o=parseInt(e.expires_in),isNaN(o)&&(o=0),t=Math.round((new Date).getTime()/1e3)+o),!t&&e&&(o=parseInt(e[this.options.expirationName]),isNaN(o)&&(o=0),t=Math.round((new Date).getTime()/1e3)+o),t&&this.storage.setItem(this.expirationName,t),e},$.prototype.getPayload=function(){var e=this.storage.getItem(this.tokenName);if(e&&3===e.split(".").length)try{var t=e.split(".")[1].replace("-","+").replace("_","/");return JSON.parse(f(t))}catch(e){}},$.prototype.login=function(e,t){var o=this;return t=m(t,this.options,0,e),this.$http(t).then(function(e){if(o.setToken(e),o.setRefreshToken(e),o.isAuthenticated())return w.resolve(e);throw new Error("Server did not provided an access token.")}).catch(function(e){return w.reject(e)})},$.prototype.register=function(e,t){var o=this;return t=m(t,this.options,0,e),this.$http(t).then(function(e){return o.setToken(e),o.setRefreshToken(e),w.resolve(e)}).catch(function(e){return w.reject(e)})},$.prototype.logout=function(e){var t=this;return this.isAuthenticated()?(e=e||{}).url||this.options.logoutUrl?(e.url=e.url||h(this.options.baseUrl,this.options.logoutUrl),e.method=e.method||"POST",e[this.options.requestDataKey]=e[this.options.requestDataKey]||void 0,e.withCredentials=e.withCredentials||this.options.withCredentials,this.$http(e).then(function(e){return t.storage.removeItem(t.tokenName),w.resolve(e)}).catch(function(e){return w.reject(e)})):(this.storage.removeItem(this.tokenName),w.resolve()):w.reject(new Error("There is no currently authenticated user"))},$.prototype.refresh=function(){var t=this,e=this.getLoggedInProvider(),o=this.options.providers[e],e=this.refreshTokenName;return o?"2.0"!==o.oauthType?reject(new Error("Invalid OAuth type for refresh")):new K(this.$http,this.storage,o,this.options).refresh(e).then(function(e){return t.setToken(e),t.setRefreshToken(e),e}).catch(function(e){throw t.clearStorage(),e}):reject(new Error("Unknown provider"))},$.prototype.clearStorage=function(){this.storage.removeItem(this.tokenName),this.storage.removeItem(this.expirationName),this.storage.removeItem(this.refreshTokenName)},$.prototype.authenticate=function(n,i){var s=this;return new w(function(t,o){var e,r=s.options.providers[n];if(!r)return o(new Error("Unknown provider"));switch(r.oauthType){case"1.0":e=new N(s.$http,s.storage,r,s.options);break;case"2.0":e=new K(s.$http,s.storage,r,s.options);break;default:return o(new Error("Invalid OAuth type"))}return e.init(i).then(function(e){return s.setToken(e,r.tokenPath),s.setRefreshToken(e,r.refreshTokenPath),s.setLoggedInProvider(n),s.isAuthenticated()?t(e):o(new Error("Authentication failed"))}).catch(function(e){return o(e)})})},$.prototype.link=function(n,i){var s=this;return new w(function(t,e){var o,r=s.options.providers[n];if(!r)return e(new Error("Unknown provider"));switch(r.oauthType){case"1.0":o=new N(s.$http,s.storage,r,s.options);break;case"2.0":o=new K(s.$http,s.storage,r,s.options);break;default:return e(new Error("Invalid OAuth type"))}return o.init(i).then(function(e){e[s.options.responseDataKey]&&(e=e[s.options.responseDataKey]),t(e)}).catch(e)})},$.prototype.defaultBindRequestInterceptor=function(t){var o=t.options.tokenHeader;t.$http.interceptors.request.use(function(e){return t.isAuthenticated()?e.headers[o]=[t.options.tokenType,t.getToken()].join(" "):delete e.headers[o],e})},$.prototype.runAuthInterceptor=function(e){var t=[],o=w.resolve(e);for(this.options.refreshAuthFailInterceptors.forEach(function(e){t.unshift(e.fulfilled,e.rejected)});t.length;)o=o.then(t.shift(),t.shift());return o},$.prototype.defaultBindResponseInterceptor=function(n){var i=this;n.$http.interceptors.response.use(function(e){return e},function(t){var e=t.config,o=t.response.status,r=e;if(401===o&&n.options.refreshType&&n.isTokenSet()){if(n._isRefreshing)return new w(function(e,t){setTimeout(function(){n.$http(r).then(e).catch(t)},100)});if(i.last_token_refresh_attempt&&new Date-i.last_token_refresh_attempt<3e4)return i.runAuthInterceptor(t);n._isRefreshing=!0,i.last_token_refresh_attempt=new Date;try{return n.refresh().then(function(e){return n._isRefreshing=!1,n.$http(r)}).catch(function(e){return n._isRefreshing=!1,i.runAuthInterceptor(e)})}catch(e){return console.log("Shouldn't be here!"),console.log(e),n._isRefreshing=!1,i.runAuthInterceptor(t)}}return w.reject(t)})},z.factory=function(e,t){return new $(e,t)},z}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("crypto-js/sha256"),require("crypto-js/enc-base64"),require("crypto-js/lib-typedarrays")):"function"==typeof define&&define.amd?define(["crypto-js/sha256","crypto-js/enc-base64","crypto-js/lib-typedarrays"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).VueAuthenticate=t(e.sha256,e.Base64,e.WordArray)}(this,function(e,t,o){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=r(e),a=r(t),n=r(o);function i(e){return void 0===e}function p(e){return"function"==typeof e}function u(t,o){return null==t||null==o||Object.keys(o).forEach(function(e){"[object Object]"!=Object.prototype.toString.call(o[e])||"[object Object]"!=Object.prototype.toString.call(t[e])?t[e]=o[e]:t[e]=u(t[e],o[e])}),t}function h(e,t){if(/^(?:[a-z]+:)?\/\//i.test(t))return t;return[e,t].join("/").replace(/[\/]+/g,"/").replace(/\/\?/g,"?").replace(/\/\#/g,"#").replace(/\:\//g,"://")}function c(e){var t="https:"===e.protocol;return e.protocol+"//"+e.hostname+":"+(e.port||(t?"443":"80"))+(/^\//.test(e.pathname)?e.pathname:"/"+e.pathname)}function l(e){var t,o,r={};return(e||"").split("&").forEach(function(e){e&&(o=e.split("="),t=decodeURIComponent(o[0]),r[t]=!o[1]||decodeURIComponent(o[1]))}),r}function f(e){var t;if("undefined"!=typeof module&&module.exports)try{t=require("buffer").Buffer}catch(e){}function o(e){switch(e.length){case 4:var t=((7&e.charCodeAt(0))<<18|(63&e.charCodeAt(1))<<12|(63&e.charCodeAt(2))<<6|63&e.charCodeAt(3))-65536;return r(55296+(t>>>10))+r(56320+(1023&t));case 3:return r((15&e.charCodeAt(0))<<12|(63&e.charCodeAt(1))<<6|63&e.charCodeAt(2));default:return r((31&e.charCodeAt(0))<<6|63&e.charCodeAt(1))}}var r=String.fromCharCode,n=new RegExp(["[À-ß][-¿]","[à-ï][-¿]{2}","[ð-÷][-¿]{3}"].join("|"),"g");return(t?function(e){return(e.constructor===t.constructor?e:new t(e,"base64")).toString()}:function(e){return atob(e).replace(n,o)})(String(e).replace(/[-_]/g,function(e){return"-"===e?"+":"/"}).replace(/[^A-Za-z0-9\+\/]/g,""))}function d(e,t,o){return[encodeURIComponent(e),"=",encodeURIComponent(t),(e=(r=o).path,t=r.domain,o=r.expires,r=r.secure,[null==e?"":";path="+e,null==t?"":";domain="+t,null==o?"":";expires="+o.toUTCString(),null==r||!1===r?"":";secure"].join(""))].join("");var r}function g(e,t){for(var o,r=void 0,n=e,i=t.split("."),s=0;s<i.length;s++){var a=i[s],r=n[a];if(null===(o=r)||"object"!=typeof o)break;n=n[a]}return r}function m(e,t,o,r){return(e=e||{}).url=e.url||t.url||h(t.baseUrl,t.loginUrl),e[t.requestDataKey]=r||e[t.requestDataKey],e.method=e.method||"POST",e.withCredentials=e.withCredentials||t.withCredentials,e}"function"!=typeof Object.assign&&(Object.assign=function(e,t){var o=arguments;if(null==e)throw new TypeError("Cannot convert undefined or null to object");for(var r=Object(e),n=1;n<arguments.length;n++){var i=o[n];if(null!=i)for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(r[s]=i[s])}return r});var y=setTimeout;function v(){}function w(e){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],b(e,this)}function k(o,r){for(;3===o._state;)o=o._value;0!==o._state?(o._handled=!0,w._immediateFn(function(){var e,t=1===o._state?r.onFulfilled:r.onRejected;if(null!==t){try{e=t(o._value)}catch(e){return void I(r.promise,e)}_(r.promise,e)}else(1===o._state?_:I)(r.promise,o._value)})):o._deferreds.push(r)}function _(t,e){try{if(e===t)throw new TypeError("A promise cannot be resolved with itself.");if(e&&("object"==typeof e||"function"==typeof e)){var o=e.then;if(e instanceof w)return t._state=3,t._value=e,void C(t);if("function"==typeof o)return void b((r=o,n=e,function(){r.apply(n,arguments)}),t)}t._state=1,t._value=e,C(t)}catch(e){I(t,e)}var r,n}function I(e,t){e._state=2,e._value=t,C(e)}function C(e){2===e._state&&0===e._deferreds.length&&w._immediateFn(function(){e._handled||w._unhandledRejectionFn(e._value)});for(var t=0,o=e._deferreds.length;t<o;t++)k(e,e._deferreds[t]);e._deferreds=null}function T(e,t,o){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof t?t:null,this.promise=o}function b(e,t){var o=!1;try{e(function(e){o||(o=!0,_(t,e))},function(e){o||(o=!0,I(t,e))})}catch(e){if(o)return;o=!0,I(t,e)}}w.prototype.catch=function(e){return this.then(null,e)},w.prototype.then=function(e,t){var o=new this.constructor(v);return k(this,new T(e,t,o)),o},w.all=function(e){var a=Array.prototype.slice.call(e);return new w(function(n,i){if(0===a.length)return n([]);var s=a.length;for(var e=0;e<a.length;e++)!function t(o,e){try{if(e&&("object"==typeof e||"function"==typeof e)){var r=e.then;if("function"==typeof r)return void r.call(e,function(e){t(o,e)},i)}a[o]=e,0==--s&&n(a)}catch(e){i(e)}}(e,a[e])})},w.resolve=function(t){return t&&"object"==typeof t&&t.constructor===w?t:new w(function(e){e(t)})},w.reject=function(o){return new w(function(e,t){t(o)})},w.race=function(n){return new w(function(e,t){for(var o=0,r=n.length;o<r;o++)n[o].then(e,t)})},w._immediateFn="function"==typeof setImmediate?function(e){setImmediate(e)}:function(e){y(e,0)},w._unhandledRejectionFn=function(e){"undefined"!=typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",e)},w._setImmediateFn=function(e){w._immediateFn=e},w._setUnhandledRejectionFn=function(e){w._unhandledRejectionFn=e};var P="undefined"!=typeof document?document:{createElement:function(){}},U="undefined"!=typeof window?window:{atob:function(){},open:function(){},location:{},localStorage:{setItem:function(){},getItem:function(){},removeItem:function(){}},sessionStorage:{setItem:function(){},getItem:function(){},removeItem:function(){}}};function j(){try{return U.location.hostname}catch(e){}return""}function R(e){try{return i(e)?U.location.origin:""+U.location.origin+e}catch(e){}return e||null}function S(e){this._defaultOptions=u({domain:j(),expires:null,path:"/",secure:!1},e)}var E={baseUrl:null,tokenPath:"access_token",refreshTokenPath:"refresh_token",tokenName:"token",tokenPrefix:"vueauth",tokenHeader:"Authorization",tokenType:"Bearer",expirationName:"expiration",expirationPrefix:null,loginUrl:"/auth/login",registerUrl:"/auth/register",logoutUrl:null,refreshUrl:"/auth/login/refresh",storageType:"localStorage",storageNamespace:"vue-authenticate",cookieStorage:{domain:j(),path:"/",secure:!1},requestDataKey:"data",responseDataKey:"data",last_token_refresh_attempt:null,refreshAuthFailInterceptors:[],bindRequestInterceptor:null,bindResponseInterceptor:null,providers:{facebook:{name:"facebook",url:"/auth/facebook",authorizationEndpoint:"https://www.facebook.com/v2.5/dialog/oauth",redirectUri:R("/"),requiredUrlParams:["display","scope"],scope:["email"],scopeDelimiter:",",display:"popup",oauthType:"2.0",popupOptions:{width:580,height:400}},google:{name:"google",url:"/auth/google",authorizationEndpoint:"https://accounts.google.com/o/oauth2/auth",redirectUri:R(),requiredUrlParams:["scope"],optionalUrlParams:["display"],scope:["profile","email"],scopePrefix:"openid",scopeDelimiter:" ",display:"popup",oauthType:"2.0",popupOptions:{width:452,height:633}},github:{name:"github",url:"/auth/github",authorizationEndpoint:"https://github.com/login/oauth/authorize",redirectUri:R(),optionalUrlParams:["scope"],scope:["user:email"],scopeDelimiter:" ",oauthType:"2.0",popupOptions:{width:1020,height:618}},instagram:{name:"instagram",url:"/auth/instagram",authorizationEndpoint:"https://api.instagram.com/oauth/authorize",redirectUri:R(),requiredUrlParams:["scope"],scope:["basic"],scopeDelimiter:"+",oauthType:"2.0",popupOptions:{width:null,height:null}},twitter:{name:"twitter",url:"/auth/twitter",authorizationEndpoint:"https://api.twitter.com/oauth/authenticate",redirectUri:R(),oauthType:"1.0",popupOptions:{width:495,height:645}},bitbucket:{name:"bitbucket",url:"/auth/bitbucket",authorizationEndpoint:"https://bitbucket.org/site/oauth2/authorize",redirectUri:R("/"),optionalUrlParams:["scope"],scope:["email"],scopeDelimiter:" ",oauthType:"2.0",popupOptions:{width:1020,height:618}},linkedin:{name:"linkedin",url:"/auth/linkedin",authorizationEndpoint:"https://www.linkedin.com/oauth/v2/authorization",redirectUri:R(),requiredUrlParams:["state","scope"],scope:["r_emailaddress"],scopeDelimiter:" ",state:"STATE",oauthType:"2.0",popupOptions:{width:527,height:582}},live:{name:"live",url:"/auth/live",authorizationEndpoint:"https://login.live.com/oauth20_authorize.srf",redirectUri:R(),requiredUrlParams:["display","scope"],scope:["wl.emails"],scopeDelimiter:" ",display:"popup",oauthType:"2.0",popupOptions:{width:500,height:560}},oauth1:{name:null,url:"/auth/oauth1",authorizationEndpoint:null,redirectUri:R(),oauthType:"1.0",popupOptions:null},oauth2:{name:null,url:"/auth/oauth2",clientId:null,redirectUri:R(),authorizationEndpoint:null,defaultUrlParams:["response_type","client_id","redirect_uri"],requiredUrlParams:null,optionalUrlParams:null,scope:null,scopePrefix:null,scopeDelimiter:null,state:null,oauthType:"2.0",popupOptions:null,responseType:"code",responseParams:{code:"code",clientId:"clientId",redirectUri:"redirectUri"}}}};S.prototype.setItem=function(e,t){t=d(e,t,u({},this._defaultOptions));this._setCookie(t)},S.prototype.getItem=function(e){var t=function(e){if(0===(e=void 0===e?"":e).length)return{};var o={},t=new RegExp("\\s*;\\s*");return e.split(t).forEach(function(e){var t=e.split("="),e=t[0],t=t[1],e=decodeURIComponent(e),t=decodeURIComponent(t);o[e]=t}),o}(this._getCookie());return t.hasOwnProperty(e)?t[e]:null},S.prototype.removeItem=function(e){var t=u({},this._defaultOptions),t=d(e,"",u(t,{expires:new Date(0)}));this._setCookie(t)},S.prototype._getCookie=function(){try{return"undefined"===P.cookie?"":P.cookie}catch(e){}return""},S.prototype._setCookie=function(e){try{P.cookie=e}catch(e){}};function O(e){this.namespace=e||null}O.prototype.setItem=function(e,t){U.localStorage.setItem(this._getStorageKey(e),t)},O.prototype.getItem=function(e){return U.localStorage.getItem(this._getStorageKey(e))},O.prototype.removeItem=function(e){U.localStorage.removeItem(this._getStorageKey(e))},O.prototype._getStorageKey=function(e){return this.namespace?[this.namespace,e].join("."):e};function x(e){this.namespace=e||null,this._storage={}}x.prototype.setItem=function(e,t){this._storage[this._getStorageKey(e)]=t},x.prototype.getItem=function(e){return this._storage[this._getStorageKey(e)]},x.prototype.removeItem=function(e){delete this._storage[this._getStorageKey(e)]},x.prototype._getStorageKey=function(e){return this.namespace?[this.namespace,e].join("."):e};function A(e){this.namespace=e||null}A.prototype.setItem=function(e,t){U.sessionStorage.setItem(this._getStorageKey(e),t)},A.prototype.getItem=function(e){return U.sessionStorage.getItem(this._getStorageKey(e))},A.prototype.removeItem=function(e){U.sessionStorage.removeItem(this._getStorageKey(e))},A.prototype._getStorageKey=function(e){return this.namespace?[this.namespace,e].join("."):e};function q(e,t,o){this.popup=null,this.url=e,this.name=t,this.popupOptions=o}q.prototype.open=function(e,t){try{return this.popup=U.open(this.url,this.name,this._stringifyOptions()),this.popup&&this.popup.focus&&this.popup.focus(),t?w.resolve():this.pooling(e)}catch(e){return w.reject(new Error("OAuth popup error occurred"))}},q.prototype.pooling=function(t){var a=this;return new w(function(r,n){var e=P.createElement("a");e.href=t;var i=c(e),s=setInterval(function(){a.popup&&!a.popup.closed&&void 0!==a.popup.closed||(clearInterval(s),s=null,n(new Error("Auth popup window closed")));try{var e,t,o;c(a.popup.location)===i&&(a.popup.location.search||a.popup.location.hash?(e=l(a.popup.location.search.substring(1).replace(/\/$/,"")),t=l(a.popup.location.hash.substring(1).replace(/[\/$]/,"")),o=u({},e),(o=u(o,t)).error?n(new Error(o.error)):r(o)):n(new Error("OAuth redirect has occurred but no query or hash parameters were found.")),clearInterval(s),s=null,a.popup.close())}catch(e){}},250)})},q.prototype._stringifyOptions=function(){var e,t=[];for(e in this.popupOptions)i(this.popupOptions[e])||t.push(e+"="+this.popupOptions[e]);return t.join(",")};function N(e,t,o,r){this.$http=e,this.storage=t,this.providerConfig=u({},D),this.providerConfig=u(this.providerConfig,o),this.options=r}var D={name:null,url:null,authorizationEndpoint:null,scope:null,scopePrefix:null,scopeDelimiter:null,redirectUri:null,requiredUrlParams:null,defaultUrlParams:null,oauthType:"1.0",popupOptions:{}};N.prototype.init=function(t){var o=this;return this.oauthPopup=new q("about:blank",this.providerConfig.name,this.providerConfig.popupOptions),U.cordova||this.oauthPopup.open(this.providerConfig.redirectUri,!0),this.getRequestToken().then(function(e){return o.openPopup(e).then(function(e){return o.exchangeForToken(e,t)})})},N.prototype.getRequestToken=function(){var e={method:"POST"};return e[this.options.requestDataKey]=u({},this.providerConfig),e.withCredentials=this.options.withCredentials,this.options.baseUrl?e.url=h(this.options.baseUrl,this.providerConfig.url):e.url=this.providerConfig.url,this.$http(e)},N.prototype.openPopup=function(e){e=[this.providerConfig.authorizationEndpoint,this.buildQueryString(e[this.options.responseDataKey])].join("?");return this.oauthPopup.popup.location=e,U.cordova?this.oauthPopup.open(this.providerConfig.redirectUri):this.oauthPopup.pooling(this.providerConfig.redirectUri)},N.prototype.exchangeForToken=function(e,t){t=u({},t),t=u(t,e),e={method:"POST"};return e[this.options.requestDataKey]=t,e.withCredentials=this.options.withCredentials,this.options.baseUrl?e.url=h(this.options.baseUrl,this.providerConfig.url):e.url=this.providerConfig.url,this.$http(e)};function K(e,t,o,r){this.$http=e,this.storage=t,this.providerConfig=u({},F),this.providerConfig=u(this.providerConfig,o),this.options=r}var F={name:null,url:null,clientId:null,authorizationEndpoint:null,redirectUri:null,scope:null,scopePrefix:null,scopeDelimiter:null,state:null,requiredUrlParams:null,defaultUrlParams:["response_type","client_id","redirect_uri"],responseType:"code",responseGrantType:"authorization_code",refreshGrantType:"refresh_token",refreshType:null,refreshTokenPrefix:null,tokenRequestAsForm:!(N.prototype.buildQueryString=function(e){var t,o=[];for(t in e){var r=e[t];o.push(encodeURIComponent(t)+"="+encodeURIComponent(r))}return o.join("&")}),refreshRequestAsForm:!1,pkce:!1,responseParams:{code:"code",clientId:"clientId",redirectUri:"redirectUri"},refreshParams:{clientId:"clientId",grantType:"grantType",scope:"scope"},oauthType:"2.0",popupOptions:{}};K.prototype.generateRandomForKey=function(e){return this.storage.getItem(e)||this.storage.setItem(e,n.default.random(64)),console.log(this.storage.getItem(e)),this.storage.getItem(e)},K.prototype.init=function(r){var n=this,i=this.providerConfig.name+"_state";p(this.providerConfig.state)?this.storage.setItem(i,this.providerConfig.state()):"string"==typeof this.providerConfig.state&&this.storage.setItem(i,this.providerConfig.state);var e=[this.providerConfig.authorizationEndpoint,this._stringifyRequestParams()].join("?");if("S256"===this.providerConfig.pkce){if("code"!==this.providerConfig.responseType)throw new Error("Cannot use PKCE with response type "+this.providerConfig.responseType);var t=s.default(this.generateRandomForKey(this.providerConfig.name+"_pkce")),t=a.default.stringify(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,""),e=e+"&code_challenge="+encodeURIComponent(t)+"&code_challenge_method=S256"}return this.oauthPopup=new q(e,this.providerConfig.name,this.providerConfig.popupOptions),new w(function(t,o){n.oauthPopup.open(n.providerConfig.redirectUri).then(function(e){return"token"!==n.providerConfig.responseType&&n.providerConfig.url?e.state&&e.state!==n.storage.getItem(i)?o(new Error("State parameter value does not match original OAuth request state value")):void n.exchangeForToken(e,r).then(function(e){return n.storage.removeItem(n.providerConfig.name+"_pkce"),e.data}).then(t):t(e)}).catch(function(e){o(e)})})},K.prototype.exchangeForToken=function(e,t){var o,r,n=u({},t);for(o in this.providerConfig.responseParams){var i=this.providerConfig.responseParams[o];switch(o){case"code":n[i]=e.code;break;case"clientId":n[i]=this.providerConfig.clientId;break;case"redirectUri":n[i]=this.providerConfig.redirectUri;break;case"grantType":n[i]=this.providerConfig.responseGrantType;break;default:n[i]=e[o]}}if(e.state&&(n.state=e.state),r=this.options.baseUrl?h(this.options.baseUrl,this.providerConfig.url):this.providerConfig.url,!this.providerConfig.pkce||(t=this.storage.getItem(this.providerConfig.name+"_pkce"))&&(n.code_verifier=t,n.grant_type="authorization_code",console.log(t)),this.providerConfig.tokenRequestAsForm){var s,a=new FormData;for(s in n){var p=n[s];a.append(s,p)}n=a}return this.$http.post(r,n,{withCredentials:this.options.withCredentials})},K.prototype._stringifyRequestParams=function(){var r=this,n=[];return["defaultUrlParams","requiredUrlParams","optionalUrlParams"].forEach(function(e){r.providerConfig[e]&&Array.isArray(r.providerConfig[e])&&r.providerConfig[e].forEach(function(e){var t=e.replace(/([\:\-\_]+(.))/g,function(e,t,o,r){return r?o.toUpperCase():o}),o=p(r.providerConfig[e])?r.providerConfig[e]():r.providerConfig[t];"redirect_uri"===e&&!o||("state"===e&&(t=r.providerConfig.name+"_state",o=encodeURIComponent(r.storage.getItem(t))),"scope"===e&&Array.isArray(o)&&(o=o.join(r.providerConfig.scopeDelimiter),r.providerConfig.scopePrefix&&(o=[r.providerConfig.scopePrefix,o].join(r.providerConfig.scopeDelimiter))),n.push([e,o]))})}),n.map(function(e){return e.join("=")}).join("&")},K.prototype.getRefreshToken=function(e){return"storage"===this.options.refreshType?this.storage.getItem(e):null},K.prototype.refresh=function(e){if(!this.options.storageType)throw new Error("Refreshing is not set");var t,o={};for(t in"storage"===this.options.refreshType&&(o.refresh_token=this.getRefreshToken(e)),this.providerConfig.refreshParams){var r=this.providerConfig.refreshParams[t];switch(t){case"clientId":o[r]=this.providerConfig.clientId;break;case"grantType":o[r]=this.providerConfig.refreshGrantType;break;default:o[r]=this.providerConfig[t]}}if(this.providerConfig.refreshRequestAsForm){var n,i=new FormData;for(n in o){var s=o[n];i.set(n,s)}o=i}e=m(this.providerConfig,this.options,0,o);return this.$http(e)};var $=function(e,t){var o=u({},E),r=function(e){switch(e.storageType){case"localStorage":try{return U.localStorage.setItem("testKey","test"),U.localStorage.removeItem("testKey"),new O(e.storageNamespace)}catch(e){}case"sessionStorage":try{return U.sessionStorage.setItem("testKey","test"),U.sessionStorage.removeItem("testKey"),new A(e.storageNamespace)}catch(e){}case"cookieStorage":return new S(e.cookieStorage);case"memoryStorage":default:return new x(e.storageNamespace)}}(o=u(o,t));if(Object.defineProperties(this,{$http:{get:function(){return e}},options:{get:function(){return o}},storage:{get:function(){return r}},tokenName:{get:function(){return this.options.tokenPrefix?[this.options.tokenPrefix,this.options.tokenName].join("_"):this.options.tokenName}},refreshTokenName:{get:function(){return this.options.refreshTokenPrefix?[this.options.refreshTokenPrefix,this.options.refreshTokenName].join("_"):this.options.refreshTokenName}},expirationName:{get:function(){return this.options.expirationPrefix?[this.options.expirationPrefix,this.options.expirationName].join("_"):this.options.expirationName}}}),this.options.bindRequestInterceptor){if(!p(this.options.bindRequestInterceptor))throw new Error("Request interceptor must be functions");this.options.bindRequestInterceptor.call(this,this)}else this.defaultBindRequestInterceptor.call(this,this);if(this.options.bindResponseInterceptor){if(!p(this.options.bindResponseInterceptor))throw new Error("Response interceptor must be functions");this.options.bindResponseInterceptor.call(this,this)}else this.defaultBindResponseInterceptor.call(this,this)};function z(e,t){var o;z.installed||(z.installed=!0,o=null,Object.defineProperties(e.prototype,{$auth:{get:function(){if(!o){if(!this.$http)throw new Error("Request handler instance not found");o=new $(this.$http,t)}return o}}}))}return $.prototype.isAuthenticated=function(){var e,t=this.storage.getItem(this.tokenName);if(t){if(3===t.split(".").length)try{var o=(e=(e=t).split(".")[1].replace("-","+").replace("_","/"),JSON.parse(window.atob(e)).exp);if("number"==typeof o)return Math.round((new Date).getTime()/1e3)<o}catch(e){return!0}return!0}return!1},$.prototype.isTokenSet=function(){return!i(this.getToken())&&!!this.getToken()},$.prototype.getToken=function(){return this.storage.getItem(this.tokenName)},$.prototype.setToken=function(e,t){t=g(e=e[this.options.responseDataKey]?e[this.options.responseDataKey]:e,t||this.options.tokenPath);t&&this.storage.setItem(this.tokenName,t)},$.prototype.getLoggedInProvider=function(){return this.storage.getItem("LoggedInProvider")},$.prototype.setLoggedInProvider=function(e){this.storage.setItem("LoggedInProvider",e)},$.prototype.getExpiration=function(){return this.options.refreshType?this.storage.getItem(this.expirationName):null},$.prototype.setRefreshToken=function(e,t){if(this.options.refreshType){if(e[this.options.responseDataKey]&&(e=e[this.options.responseDataKey]),this.setExpiration(e),"storage"!==this.options.refreshType)return e;t=g(e,t||this.options.refreshTokenPath);return(t=!t&&e?e[this.options.expirationName]:t)&&this.storage.setItem(this.refreshTokenName,t),e}},$.prototype.setExpiration=function(e){var t,o;return e.expires_in&&(o=parseInt(e.expires_in),isNaN(o)&&(o=0),t=Math.round((new Date).getTime()/1e3)+o),!t&&e&&(o=parseInt(e[this.options.expirationName]),isNaN(o)&&(o=0),t=Math.round((new Date).getTime()/1e3)+o),t&&this.storage.setItem(this.expirationName,t),e},$.prototype.getPayload=function(){var e=this.storage.getItem(this.tokenName);if(e&&3===e.split(".").length)try{var t=e.split(".")[1].replace("-","+").replace("_","/");return JSON.parse(f(t))}catch(e){}},$.prototype.login=function(e,t){var o=this;return t=m(t,this.options,0,e),this.$http(t).then(function(e){if(o.setToken(e),o.setRefreshToken(e),o.isAuthenticated())return w.resolve(e);throw new Error("Server did not provided an access token.")}).catch(function(e){return w.reject(e)})},$.prototype.register=function(e,t){var o=this;return t=m(t,this.options,0,e),this.$http(t).then(function(e){return o.setToken(e),o.setRefreshToken(e),w.resolve(e)}).catch(function(e){return w.reject(e)})},$.prototype.logout=function(e){var t=this;return this.isAuthenticated()?(e=e||{}).url||this.options.logoutUrl?(e.url=e.url||h(this.options.baseUrl,this.options.logoutUrl),e.method=e.method||"POST",e[this.options.requestDataKey]=e[this.options.requestDataKey]||void 0,e.withCredentials=e.withCredentials||this.options.withCredentials,this.$http(e).then(function(e){return t.storage.removeItem(t.tokenName),w.resolve(e)}).catch(function(e){return w.reject(e)})):(this.storage.removeItem(this.tokenName),w.resolve()):w.reject(new Error("There is no currently authenticated user"))},$.prototype.refresh=function(){var t=this,e=this.getLoggedInProvider(),o=this.options.providers[e],e=this.refreshTokenName;return o?"2.0"!==o.oauthType?reject(new Error("Invalid OAuth type for refresh")):new K(this.$http,this.storage,o,this.options).refresh(e).then(function(e){return t.setToken(e),t.setRefreshToken(e),e}).catch(function(e){throw t.clearStorage(),e}):reject(new Error("Unknown provider"))},$.prototype.clearStorage=function(){this.storage.removeItem(this.tokenName),this.storage.removeItem(this.expirationName),this.storage.removeItem(this.refreshTokenName)},$.prototype.authenticate=function(n,i){var s=this;return new w(function(t,o){var e,r=s.options.providers[n];if(!r)return o(new Error("Unknown provider"));switch(r.oauthType){case"1.0":e=new N(s.$http,s.storage,r,s.options);break;case"2.0":e=new K(s.$http,s.storage,r,s.options);break;default:return o(new Error("Invalid OAuth type"))}return e.init(i).then(function(e){return s.setToken(e,r.tokenPath),s.setRefreshToken(e,r.refreshTokenPath),s.setLoggedInProvider(n),s.isAuthenticated()?t(e):o(new Error("Authentication failed"))}).catch(function(e){return o(e)})})},$.prototype.link=function(n,i){var s=this;return new w(function(t,e){var o,r=s.options.providers[n];if(!r)return e(new Error("Unknown provider"));switch(r.oauthType){case"1.0":o=new N(s.$http,s.storage,r,s.options);break;case"2.0":o=new K(s.$http,s.storage,r,s.options);break;default:return e(new Error("Invalid OAuth type"))}return o.init(i).then(function(e){e[s.options.responseDataKey]&&(e=e[s.options.responseDataKey]),t(e)}).catch(e)})},$.prototype.defaultBindRequestInterceptor=function(t){var o=t.options.tokenHeader;t.$http.interceptors.request.use(function(e){return t.isAuthenticated()?e.headers[o]=[t.options.tokenType,t.getToken()].join(" "):delete e.headers[o],e})},$.prototype.runAuthInterceptor=function(e){var t=[],o=w.reject(e);for(this.options.refreshAuthFailInterceptors.forEach(function(e){t.unshift(e)});t.length;)o=o.catch(t.shift());return o},$.prototype.defaultBindResponseInterceptor=function(n){n.$http.interceptors.response.use(function(e){return e},function(t){var e=t.config,o=t.response.status,r=e;if(401===o&&n.options.refreshType&&n.isTokenSet()){if(n._isRefreshing)return new w(function(e,t){setTimeout(function(){n.$http(r).then(e).catch(t)},100)});if(n.last_token_refresh_attempt&&new Date-n.last_token_refresh_attempt<3e4)return n.runAuthInterceptor(t);n._isRefreshing=!0,n.last_token_refresh_attempt=new Date;try{return n.refresh().then(function(e){return n._isRefreshing=!1,n.$http(r)}).catch(function(e){return n._isRefreshing=!1,n.runAuthInterceptor(e)})}catch(e){return console.log("Shouldn't be here!"),console.log(e),n._isRefreshing=!1,n.runAuthInterceptor(t)}}return w.reject(t)})},z.factory=function(e,t){return new $(e,t)},z}); |
{ | ||
"name": "@simbachain/vue-authenticate", | ||
"version": "1.5.5", | ||
"version": "1.5.6", | ||
"description": "Authentication library for Vue.js", | ||
@@ -5,0 +5,0 @@ "main": "dist/vue-authenticate.common.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
210729
5635