@simbachain/vue-authenticate
Advanced tools
Comparing version 1.5.0 to 1.5.1
/** | ||
* vue-authenticate v1.5.0 | ||
* vue-authenticate v1.5.1 | ||
* https://github.com/dgrubelic/vue-authenticate | ||
@@ -1640,3 +1640,3 @@ * Released under the MIT License. | ||
setLoggedInProvider(provider) { | ||
this.storage.setItem('LoggedInProvider', token); | ||
this.storage.setItem('LoggedInProvider', provider); | ||
} | ||
@@ -1643,0 +1643,0 @@ |
/** | ||
* vue-authenticate v1.5.0 | ||
* vue-authenticate v1.5.1 | ||
* https://github.com/dgrubelic/vue-authenticate | ||
@@ -1636,3 +1636,3 @@ * Released under the MIT License. | ||
setLoggedInProvider(provider) { | ||
this.storage.setItem('LoggedInProvider', token); | ||
this.storage.setItem('LoggedInProvider', provider); | ||
} | ||
@@ -1639,0 +1639,0 @@ |
/** | ||
* vue-authenticate v1.5.0 | ||
* vue-authenticate v1.5.1 | ||
* https://github.com/dgrubelic/vue-authenticate | ||
@@ -1638,3 +1638,3 @@ * Released under the MIT License. | ||
VueAuthenticate.prototype.setLoggedInProvider = function setLoggedInProvider (provider) { | ||
this.storage.setItem('LoggedInProvider', token); | ||
this.storage.setItem('LoggedInProvider', provider); | ||
}; | ||
@@ -1641,0 +1641,0 @@ |
/** | ||
* vue-authenticate v1.5.0 | ||
* vue-authenticate v1.5.1 | ||
* 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=e||self).VueAuthenticate=t(e.sha256,e.Base64,e.WordArray)}(this,function(s,a,t){"use strict";function o(e){return void 0===e}function p(e){return"function"==typeof e}function h(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]=h(t[e],o[e])}),t}function c(e,t){if(/^(?:[a-z]+:)?\/\//i.test(t))return t;var o=[e,t].join("/");return o.replace(/[\/]+/g,"/").replace(/\/\?/g,"?").replace(/\/\#/g,"#").replace(/\:\//g,"://")}function u(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 r(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 n(e,t,o){return[encodeURIComponent(e),"=",encodeURIComponent(t),(n=(r=o).path,i=r.domain,s=r.expires,a=r.secure,[null==n?"":";path="+n,null==i?"":";domain="+i,null==s?"":";expires="+s.toUTCString(),null==a||!1===a?"":";secure"].join(""))].join("");var r,n,i,s,a}function i(e,t){for(var o,r=void 0,n=e,i=t.split("."),s=0;s<i.length;s++){var a=i[s];if(r=n[a],null===(o=r)||"object"!=typeof o)break;n=n[a]}return r}function f(e,t,o,r){return(e=e||{}).url=e.url||t.url||c(t.baseUrl,t.loginUrl),e[t.requestDataKey]=r||e[t.requestDataKey],e.method=e.method||"POST",e.withCredentials=e.withCredentials||t.withCredentials,e}s=s&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s,a=a&&Object.prototype.hasOwnProperty.call(a,"default")?a.default:a,t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t,"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 d=setTimeout;function g(){}function m(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=[],_(e,this)}function v(o,r){for(;3===o._state;)o=o._value;0!==o._state?(o._handled=!0,m._immediateFn(function(){var e=1===o._state?r.onFulfilled:r.onRejected;if(null!==e){var t;try{t=e(o._value)}catch(e){return void w(r.promise,e)}y(r.promise,t)}else(1===o._state?y:w)(r.promise,o._value)})):o._deferreds.push(r)}function y(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 m)return t._state=3,t._value=e,void k(t);if("function"==typeof o)return void _((r=o,n=e,function(){r.apply(n,arguments)}),t)}t._state=1,t._value=e,k(t)}catch(e){w(t,e)}var r,n}function w(e,t){e._state=2,e._value=t,k(e)}function k(e){2===e._state&&0===e._deferreds.length&&m._immediateFn(function(){e._handled||m._unhandledRejectionFn(e._value)});for(var t=0,o=e._deferreds.length;t<o;t++)v(e,e._deferreds[t]);e._deferreds=null}function C(e,t,o){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof t?t:null,this.promise=o}function _(e,t){var o=!1;try{e(function(e){o||(o=!0,y(t,e))},function(e){o||(o=!0,w(t,e))})}catch(e){if(o)return;o=!0,w(t,e)}}m.prototype.catch=function(e){return this.then(null,e)},m.prototype.then=function(e,t){var o=new this.constructor(g);return v(this,new C(e,t,o)),o},m.all=function(e){var a=Array.prototype.slice.call(e);return new m(function(r,n){if(0===a.length)return r([]);var i=a.length;function s(t,e){try{if(e&&("object"==typeof e||"function"==typeof e)){var o=e.then;if("function"==typeof o)return void o.call(e,function(e){s(t,e)},n)}a[t]=e,0==--i&&r(a)}catch(e){n(e)}}for(var e=0;e<a.length;e++)s(e,a[e])})},m.resolve=function(t){return t&&"object"==typeof t&&t.constructor===m?t:new m(function(e){e(t)})},m.reject=function(o){return new m(function(e,t){t(o)})},m.race=function(n){return new m(function(e,t){for(var o=0,r=n.length;o<r;o++)n[o].then(e,t)})},m._immediateFn="function"==typeof setImmediate?function(e){setImmediate(e)}:function(e){d(e,0)},m._unhandledRejectionFn=function(e){"undefined"!=typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",e)},m._setImmediateFn=function(e){m._immediateFn=e},m._setUnhandledRejectionFn=function(e){m._unhandledRejectionFn=e};var I="undefined"!=typeof document?document:{createElement:function(){}},b="undefined"!=typeof window?window:{atob:function(){},open:function(){},location:{},localStorage:{setItem:function(){},getItem:function(){},removeItem:function(){}},sessionStorage:{setItem:function(){},getItem:function(){},removeItem:function(){}}};function T(){try{return b.location.hostname}catch(e){}return""}function e(e){try{return o(e)?b.location.origin:""+b.location.origin+e}catch(e){}return e||null}function P(e){this._defaultOptions=h({domain:T(),expires:null,path:"/",secure:!1},e)}var U={baseUrl:null,tokenPath:"access_token",refreshTokenPath:"refresh_token",tokenName:"token",tokenPrefix:"vueauth",tokenHeader:"Authorization",tokenType:"Bearer",refreshType:null,refreshTokenName:"refresh_token",refreshTokenPrefix:null,pkce:!1,expirationName:"expiration",expirationPrefix:null,loginUrl:"/auth/login",registerUrl:"/auth/register",logoutUrl:null,refreshUrl:"/auth/login/refresh",storageType:"localStorage",storageNamespace:"vue-authenticate",cookieStorage:{domain:T(),path:"/",secure:!1},requestDataKey:"data",responseDataKey:"data",bindRequestInterceptor: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})},bindResponseInterceptor: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()&&!n._isRefreshing){n._isRefreshing=!0;try{return n.refresh().then(function(e){return n._isRefreshing=!1,n.$http(r)}).catch(function(e){return n._isRefreshing=!1,Promise.reject(e)})}catch(e){return console.log("Shouldn't be here!"),console.log(e),n._isRefreshing=!1,Promise.reject(t)}}return Promise.reject(t)})},providers:{facebook:{name:"facebook",url:"/auth/facebook",authorizationEndpoint:"https://www.facebook.com/v2.5/dialog/oauth",redirectUri:e("/"),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:e(),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:e(),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:e(),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:e(),oauthType:"1.0",popupOptions:{width:495,height:645}},bitbucket:{name:"bitbucket",url:"/auth/bitbucket",authorizationEndpoint:"https://bitbucket.org/site/oauth2/authorize",redirectUri:e("/"),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:e(),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:e(),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:e(),oauthType:"1.0",popupOptions:null},oauth2:{name:null,url:"/auth/oauth2",clientId:null,redirectUri:e(),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"}}}};P.prototype.setItem=function(e,t){var o=n(e,t,h({},this._defaultOptions));this._setCookie(o)},P.prototype.getItem=function(e){var t=function(e){if(void 0===e&&(e=""),0===e.length)return{};var s={},t=new RegExp("\\s*;\\s*");return e.split(t).forEach(function(e){var t=e.split("="),o=t[0],r=t[1],n=decodeURIComponent(o),i=decodeURIComponent(r);s[n]=i}),s}(this._getCookie());return t.hasOwnProperty(e)?t[e]:null},P.prototype.removeItem=function(e){var t=h({},this._defaultOptions),o=n(e,"",h(t,{expires:new Date(0)}));this._setCookie(o)},P.prototype._getCookie=function(){try{return"undefined"===I.cookie?"":I.cookie}catch(e){}return""},P.prototype._setCookie=function(e){try{I.cookie=e}catch(e){}};function j(e){this.namespace=e||null}j.prototype.setItem=function(e,t){b.localStorage.setItem(this._getStorageKey(e),t)},j.prototype.getItem=function(e){return b.localStorage.getItem(this._getStorageKey(e))},j.prototype.removeItem=function(e){b.localStorage.removeItem(this._getStorageKey(e))},j.prototype._getStorageKey=function(e){return this.namespace?[this.namespace,e].join("."):e};function S(e){this.namespace=e||null,this._storage={}}S.prototype.setItem=function(e,t){this._storage[this._getStorageKey(e)]=t},S.prototype.getItem=function(e){return this._storage[this._getStorageKey(e)]},S.prototype.removeItem=function(e){delete this._storage[this._getStorageKey(e)]},S.prototype._getStorageKey=function(e){return this.namespace?[this.namespace,e].join("."):e};function O(e){this.namespace=e||null}O.prototype.setItem=function(e,t){b.sessionStorage.setItem(this._getStorageKey(e),t)},O.prototype.getItem=function(e){return b.sessionStorage.getItem(this._getStorageKey(e))},O.prototype.removeItem=function(e){b.sessionStorage.removeItem(this._getStorageKey(e))},O.prototype._getStorageKey=function(e){return this.namespace?[this.namespace,e].join("."):e};function R(e,t,o){this.popup=null,this.url=e,this.name=t,this.popupOptions=o}R.prototype.open=function(e,t){try{return this.popup=b.open(this.url,this.name,this._stringifyOptions()),this.popup&&this.popup.focus&&this.popup.focus(),t?m.resolve():this.pooling(e)}catch(e){return m.reject(new Error("OAuth popup error occurred"))}},R.prototype.pooling=function(t){var a=this;return new m(function(r,n){var e=I.createElement("a");e.href=t;var i=u(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{if(u(a.popup.location)===i){if(a.popup.location.search||a.popup.location.hash){var e=l(a.popup.location.search.substring(1).replace(/\/$/,"")),t=l(a.popup.location.hash.substring(1).replace(/[\/$]/,"")),o=h({},e);(o=h(o,t)).error?n(new Error(o.error)):r(o)}else 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)})},R.prototype._stringifyOptions=function(){var e=[];for(var t in this.popupOptions)o(this.popupOptions[t])||e.push(t+"="+this.popupOptions[t]);return e.join(",")};function E(e,t,o,r){this.$http=e,this.storage=t,this.providerConfig=h({},x),this.providerConfig=h(this.providerConfig,o),this.options=r}var x={name:null,url:null,authorizationEndpoint:null,scope:null,scopePrefix:null,scopeDelimiter:null,redirectUri:null,requiredUrlParams:null,defaultUrlParams:null,oauthType:"1.0",popupOptions:{}};E.prototype.init=function(t){var o=this;return this.oauthPopup=new R("about:blank",this.providerConfig.name,this.providerConfig.popupOptions),b.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)})})},E.prototype.getRequestToken=function(){var e={method:"POST"};return e[this.options.requestDataKey]=h({},this.providerConfig),e.withCredentials=this.options.withCredentials,this.options.baseUrl?e.url=c(this.options.baseUrl,this.providerConfig.url):e.url=this.providerConfig.url,this.$http(e)},E.prototype.openPopup=function(e){var t=[this.providerConfig.authorizationEndpoint,this.buildQueryString(e[this.options.responseDataKey])].join("?");return this.oauthPopup.popup.location=t,b.cordova?this.oauthPopup.open(this.providerConfig.redirectUri):this.oauthPopup.pooling(this.providerConfig.redirectUri)},E.prototype.exchangeForToken=function(e,t){var o=h({},t);o=h(o,e);var r={method:"POST"};return r[this.options.requestDataKey]=o,r.withCredentials=this.options.withCredentials,this.options.baseUrl?r.url=c(this.options.baseUrl,this.providerConfig.url):r.url=this.providerConfig.url,this.$http(r)};function q(e,t,o,r){this.$http=e,this.storage=t,this.providerConfig=h({},A),this.providerConfig=h(this.providerConfig,o),this.options=r}var A={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",tokenRequestAsForm:!(E.prototype.buildQueryString=function(e){var t=[];for(var o in e){var r=e[o];t.push(encodeURIComponent(o)+"="+encodeURIComponent(r))}return t.join("&")}),refreshRequestAsForm:!1,refreshGrantType:null,pkce:!1,responseParams:{code:"code",clientId:"clientId",redirectUri:"redirectUri"},refreshParams:{clientId:"clientId",grantType:"grantType",scope:"scope"},oauthType:"2.0",popupOptions:{}};q.prototype.getRandomString=function(e){return this.storage.getItem(e)||this.storage.setItem(e,t.random(64)),console.log(this.storage.getItem(e)),this.storage.getItem(e)},q.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(this.getRandomString(this.providerConfig.name+"_pkce")),o=a.stringify(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"");e=e+"&code_challenge="+encodeURIComponent(o)+"&code_challenge_method=S256"}return this.oauthPopup=new R(e,this.providerConfig.name,this.providerConfig.popupOptions),new m(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)})})},q.prototype.exchangeForToken=function(e,t){var o,r=h({},t);for(var n in this.providerConfig.responseParams){var i=this.providerConfig.responseParams[n];switch(n){case"code":r[i]=e.code;break;case"clientId":r[i]=this.providerConfig.clientId;break;case"redirectUri":r[i]=this.providerConfig.redirectUri;break;default:r[i]=e[n]}}e.state&&(r.state=e.state),o=this.options.baseUrl?c(this.options.baseUrl,this.providerConfig.url):this.providerConfig.url;var s=this.getRandomString(this.providerConfig.name+"_pkce");if(s&&(r.code_verifier=s,r.grant_type="authorization_code",console.log(s)),this.providerConfig.tokenRequestAsForm){var a=new FormData;for(var p in r){var u=r[p];a.append(p,u)}r=a}return this.$http.post(o,r,{withCredentials:this.options.withCredentials})},q.prototype._stringifyRequestParams=function(){var n=this,i=[];return["defaultUrlParams","requiredUrlParams","optionalUrlParams"].forEach(function(e){n.providerConfig[e]&&Array.isArray(n.providerConfig[e])&&n.providerConfig[e].forEach(function(e){var t=e.replace(/([\:\-\_]+(.))/g,function(e,t,o,r){return r?o.toUpperCase():o}),o=p(n.providerConfig[e])?n.providerConfig[e]():n.providerConfig[t];if("redirect_uri"!==e||o){if("state"===e){var r=n.providerConfig.name+"_state";o=encodeURIComponent(n.storage.getItem(r))}"scope"===e&&Array.isArray(o)&&(o=o.join(n.providerConfig.scopeDelimiter),n.providerConfig.scopePrefix&&(o=[n.providerConfig.scopePrefix,o].join(n.providerConfig.scopeDelimiter))),i.push([e,o])}})}),i.map(function(e){return e.join("=")}).join("&")},q.prototype.getRefreshToken=function(e){return"storage"===this.options.refreshType?this.storage.getItem(e):null},q.prototype.refresh=function(e){if(!this.options.storageType)throw new Error("Refreshing is not set");var t={};for(var o in"storage"===this.options.refreshType&&(t.refresh_token=this.getRefreshToken(e)),this.providerConfig.refreshParams){var r=this.providerConfig.refreshParams[o];switch(o){case"clientId":t[r]=this.providerConfig.clientId;break;case"grantType":t[r]=this.providerConfig.refreshGrantType;break;default:t[r]=this.providerConfig[o]}}if(this.providerConfig.refreshRequestAsForm){var n=new FormData;for(var i in t){var s=t[i];n.set(i,s)}t=n}var a=f(this.providerConfig,this.options,0,t);return this.$http(a)};var N=function(e,t){var o=h({},U),r=function(e){switch(e.storageType){case"localStorage":try{return b.localStorage.setItem("testKey","test"),b.localStorage.removeItem("testKey"),new j(e.storageNamespace)}catch(e){}case"sessionStorage":try{return b.sessionStorage.setItem("testKey","test"),b.sessionStorage.removeItem("testKey"),new O(e.storageNamespace)}catch(e){}case"cookieStorage":return new P(e.cookieStorage);case"memoryStorage":default:return new S(e.storageNamespace)}}(o=h(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||!p(this.options.bindRequestInterceptor))throw new Error("Request interceptor must be functions");if(this.options.bindRequestInterceptor.call(this,this),!this.options.bindResponseInterceptor||!p(this.options.bindResponseInterceptor))throw new Error("Response interceptor must be functions");this.options.bindResponseInterceptor.call(this,this)};function D(e,t){if(!D.installed){D.installed=!0;var o=null;Object.defineProperties(e.prototype,{$auth:{get:function(){if(!o){if(!this.$http)throw new Error("Request handler instance not found");o=new N(this.$http,t)}return o}}})}}return N.prototype.isAuthenticated=function(){var e,t=this.storage.getItem(this.tokenName);if(t){if(3===t.split(".").length)try{var o=(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},N.prototype.isTokenSet=function(){return!o(this.getToken())&&!!this.getToken()},N.prototype.getToken=function(){return this.storage.getItem(this.tokenName)},N.prototype.setToken=function(e,t){e[this.options.responseDataKey]&&(e=e[this.options.responseDataKey]);var o=i(e,t||this.options.tokenPath);o&&this.storage.setItem(this.tokenName,o)},N.prototype.getLoggedInProvider=function(){return this.storage.getItem("LoggedInProvider")},N.prototype.setLoggedInProvider=function(){this.storage.setItem("LoggedInProvider",token)},N.prototype.getExpiration=function(){return this.options.refreshType?this.storage.getItem(this.expirationName):null},N.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;var o=i(e,t||this.options.refreshTokenPath);return!o&&e&&(o=e[this.options.expirationName]),o&&this.storage.setItem(this.refreshTokenName,o),e}},N.prototype.setExpiration=function(e){var t;if(e.expires_in){var o=parseInt(e.expires_in);isNaN(o)&&(o=0),t=Math.round((new Date).getTime()/1e3)+o}if(!t&&e){var r=parseInt(e[this.options.expirationName]);isNaN(r)&&(r=0),t=Math.round((new Date).getTime()/1e3)+r}return t&&this.storage.setItem(this.expirationName,t),e},N.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(r(t))}catch(e){}},N.prototype.login=function(e,t){var o=this;return t=f(t,this.options,0,e),this.$http(t).then(function(e){if(o.setToken(e),o.setRefreshToken(e),o.isAuthenticated())return m.resolve(e);throw new Error("Server did not provided an access token.")}).catch(function(e){return m.reject(e)})},N.prototype.register=function(e,t){var o=this;return t=f(t,this.options,0,e),this.$http(t).then(function(e){return o.setToken(e),o.setRefreshToken(e),m.resolve(e)}).catch(function(e){return m.reject(e)})},N.prototype.logout=function(e){var t=this;return this.isAuthenticated()?(e=e||{}).url||this.options.logoutUrl?(e.url=e.url?e.url:c(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),m.resolve(e)}).catch(function(e){return m.reject(e)})):(this.storage.removeItem(this.tokenName),m.resolve()):m.reject(new Error("There is no currently authenticated user"))},N.prototype.refresh=function(){var e,t=this,o=this.getLoggedInProvider(),r=this.options.providers[o],n=this.refreshTokenName;if(!r)return reject(new Error("Unknown provider"));switch(r.oauthType){case"2.0":e=new q(this.$http,this.storage,r,this.options);break;default:return reject(new Error("Invalid OAuth type for refresh"))}return e.refresh(n).then(function(e){return t.setToken(e),t.setRefreshToken(e),e}).catch(function(e){throw t.clearStorage(),e})},N.prototype.clearStorage=function(){this.storage.removeItem(this.tokenName),this.storage.removeItem(this.expirationName),this.storage.removeItem(this.refreshTokenName)},N.prototype.authenticate=function(n,i){var s=this;return new m(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 E(s.$http,s.storage,r,s.options);break;case"2.0":e=new q(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)})})},N.prototype.link=function(n,i){var s=this;return new m(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 E(s.$http,s.storage,r,s.options);break;case"2.0":o=new q(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)})},D.factory=function(e,t){return new N(e,t)},D}); | ||
!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=e||self).VueAuthenticate=t(e.sha256,e.Base64,e.WordArray)}(this,function(s,a,t){"use strict";function o(e){return void 0===e}function p(e){return"function"==typeof e}function h(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]=h(t[e],o[e])}),t}function c(e,t){if(/^(?:[a-z]+:)?\/\//i.test(t))return t;var o=[e,t].join("/");return o.replace(/[\/]+/g,"/").replace(/\/\?/g,"?").replace(/\/\#/g,"#").replace(/\:\//g,"://")}function u(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 r(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 n(e,t,o){return[encodeURIComponent(e),"=",encodeURIComponent(t),(n=(r=o).path,i=r.domain,s=r.expires,a=r.secure,[null==n?"":";path="+n,null==i?"":";domain="+i,null==s?"":";expires="+s.toUTCString(),null==a||!1===a?"":";secure"].join(""))].join("");var r,n,i,s,a}function i(e,t){for(var o,r=void 0,n=e,i=t.split("."),s=0;s<i.length;s++){var a=i[s];if(r=n[a],null===(o=r)||"object"!=typeof o)break;n=n[a]}return r}function f(e,t,o,r){return(e=e||{}).url=e.url||t.url||c(t.baseUrl,t.loginUrl),e[t.requestDataKey]=r||e[t.requestDataKey],e.method=e.method||"POST",e.withCredentials=e.withCredentials||t.withCredentials,e}s=s&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s,a=a&&Object.prototype.hasOwnProperty.call(a,"default")?a.default:a,t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t,"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 d=setTimeout;function g(){}function m(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=[],_(e,this)}function v(o,r){for(;3===o._state;)o=o._value;0!==o._state?(o._handled=!0,m._immediateFn(function(){var e=1===o._state?r.onFulfilled:r.onRejected;if(null!==e){var t;try{t=e(o._value)}catch(e){return void w(r.promise,e)}y(r.promise,t)}else(1===o._state?y:w)(r.promise,o._value)})):o._deferreds.push(r)}function y(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 m)return t._state=3,t._value=e,void k(t);if("function"==typeof o)return void _((r=o,n=e,function(){r.apply(n,arguments)}),t)}t._state=1,t._value=e,k(t)}catch(e){w(t,e)}var r,n}function w(e,t){e._state=2,e._value=t,k(e)}function k(e){2===e._state&&0===e._deferreds.length&&m._immediateFn(function(){e._handled||m._unhandledRejectionFn(e._value)});for(var t=0,o=e._deferreds.length;t<o;t++)v(e,e._deferreds[t]);e._deferreds=null}function C(e,t,o){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof t?t:null,this.promise=o}function _(e,t){var o=!1;try{e(function(e){o||(o=!0,y(t,e))},function(e){o||(o=!0,w(t,e))})}catch(e){if(o)return;o=!0,w(t,e)}}m.prototype.catch=function(e){return this.then(null,e)},m.prototype.then=function(e,t){var o=new this.constructor(g);return v(this,new C(e,t,o)),o},m.all=function(e){var a=Array.prototype.slice.call(e);return new m(function(r,n){if(0===a.length)return r([]);var i=a.length;function s(t,e){try{if(e&&("object"==typeof e||"function"==typeof e)){var o=e.then;if("function"==typeof o)return void o.call(e,function(e){s(t,e)},n)}a[t]=e,0==--i&&r(a)}catch(e){n(e)}}for(var e=0;e<a.length;e++)s(e,a[e])})},m.resolve=function(t){return t&&"object"==typeof t&&t.constructor===m?t:new m(function(e){e(t)})},m.reject=function(o){return new m(function(e,t){t(o)})},m.race=function(n){return new m(function(e,t){for(var o=0,r=n.length;o<r;o++)n[o].then(e,t)})},m._immediateFn="function"==typeof setImmediate?function(e){setImmediate(e)}:function(e){d(e,0)},m._unhandledRejectionFn=function(e){"undefined"!=typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",e)},m._setImmediateFn=function(e){m._immediateFn=e},m._setUnhandledRejectionFn=function(e){m._unhandledRejectionFn=e};var I="undefined"!=typeof document?document:{createElement:function(){}},b="undefined"!=typeof window?window:{atob:function(){},open:function(){},location:{},localStorage:{setItem:function(){},getItem:function(){},removeItem:function(){}},sessionStorage:{setItem:function(){},getItem:function(){},removeItem:function(){}}};function T(){try{return b.location.hostname}catch(e){}return""}function e(e){try{return o(e)?b.location.origin:""+b.location.origin+e}catch(e){}return e||null}function P(e){this._defaultOptions=h({domain:T(),expires:null,path:"/",secure:!1},e)}var U={baseUrl:null,tokenPath:"access_token",refreshTokenPath:"refresh_token",tokenName:"token",tokenPrefix:"vueauth",tokenHeader:"Authorization",tokenType:"Bearer",refreshType:null,refreshTokenName:"refresh_token",refreshTokenPrefix:null,pkce:!1,expirationName:"expiration",expirationPrefix:null,loginUrl:"/auth/login",registerUrl:"/auth/register",logoutUrl:null,refreshUrl:"/auth/login/refresh",storageType:"localStorage",storageNamespace:"vue-authenticate",cookieStorage:{domain:T(),path:"/",secure:!1},requestDataKey:"data",responseDataKey:"data",bindRequestInterceptor: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})},bindResponseInterceptor: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()&&!n._isRefreshing){n._isRefreshing=!0;try{return n.refresh().then(function(e){return n._isRefreshing=!1,n.$http(r)}).catch(function(e){return n._isRefreshing=!1,Promise.reject(e)})}catch(e){return console.log("Shouldn't be here!"),console.log(e),n._isRefreshing=!1,Promise.reject(t)}}return Promise.reject(t)})},providers:{facebook:{name:"facebook",url:"/auth/facebook",authorizationEndpoint:"https://www.facebook.com/v2.5/dialog/oauth",redirectUri:e("/"),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:e(),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:e(),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:e(),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:e(),oauthType:"1.0",popupOptions:{width:495,height:645}},bitbucket:{name:"bitbucket",url:"/auth/bitbucket",authorizationEndpoint:"https://bitbucket.org/site/oauth2/authorize",redirectUri:e("/"),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:e(),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:e(),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:e(),oauthType:"1.0",popupOptions:null},oauth2:{name:null,url:"/auth/oauth2",clientId:null,redirectUri:e(),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"}}}};P.prototype.setItem=function(e,t){var o=n(e,t,h({},this._defaultOptions));this._setCookie(o)},P.prototype.getItem=function(e){var t=function(e){if(void 0===e&&(e=""),0===e.length)return{};var s={},t=new RegExp("\\s*;\\s*");return e.split(t).forEach(function(e){var t=e.split("="),o=t[0],r=t[1],n=decodeURIComponent(o),i=decodeURIComponent(r);s[n]=i}),s}(this._getCookie());return t.hasOwnProperty(e)?t[e]:null},P.prototype.removeItem=function(e){var t=h({},this._defaultOptions),o=n(e,"",h(t,{expires:new Date(0)}));this._setCookie(o)},P.prototype._getCookie=function(){try{return"undefined"===I.cookie?"":I.cookie}catch(e){}return""},P.prototype._setCookie=function(e){try{I.cookie=e}catch(e){}};function j(e){this.namespace=e||null}j.prototype.setItem=function(e,t){b.localStorage.setItem(this._getStorageKey(e),t)},j.prototype.getItem=function(e){return b.localStorage.getItem(this._getStorageKey(e))},j.prototype.removeItem=function(e){b.localStorage.removeItem(this._getStorageKey(e))},j.prototype._getStorageKey=function(e){return this.namespace?[this.namespace,e].join("."):e};function S(e){this.namespace=e||null,this._storage={}}S.prototype.setItem=function(e,t){this._storage[this._getStorageKey(e)]=t},S.prototype.getItem=function(e){return this._storage[this._getStorageKey(e)]},S.prototype.removeItem=function(e){delete this._storage[this._getStorageKey(e)]},S.prototype._getStorageKey=function(e){return this.namespace?[this.namespace,e].join("."):e};function O(e){this.namespace=e||null}O.prototype.setItem=function(e,t){b.sessionStorage.setItem(this._getStorageKey(e),t)},O.prototype.getItem=function(e){return b.sessionStorage.getItem(this._getStorageKey(e))},O.prototype.removeItem=function(e){b.sessionStorage.removeItem(this._getStorageKey(e))},O.prototype._getStorageKey=function(e){return this.namespace?[this.namespace,e].join("."):e};function R(e,t,o){this.popup=null,this.url=e,this.name=t,this.popupOptions=o}R.prototype.open=function(e,t){try{return this.popup=b.open(this.url,this.name,this._stringifyOptions()),this.popup&&this.popup.focus&&this.popup.focus(),t?m.resolve():this.pooling(e)}catch(e){return m.reject(new Error("OAuth popup error occurred"))}},R.prototype.pooling=function(t){var a=this;return new m(function(r,n){var e=I.createElement("a");e.href=t;var i=u(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{if(u(a.popup.location)===i){if(a.popup.location.search||a.popup.location.hash){var e=l(a.popup.location.search.substring(1).replace(/\/$/,"")),t=l(a.popup.location.hash.substring(1).replace(/[\/$]/,"")),o=h({},e);(o=h(o,t)).error?n(new Error(o.error)):r(o)}else 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)})},R.prototype._stringifyOptions=function(){var e=[];for(var t in this.popupOptions)o(this.popupOptions[t])||e.push(t+"="+this.popupOptions[t]);return e.join(",")};function E(e,t,o,r){this.$http=e,this.storage=t,this.providerConfig=h({},x),this.providerConfig=h(this.providerConfig,o),this.options=r}var x={name:null,url:null,authorizationEndpoint:null,scope:null,scopePrefix:null,scopeDelimiter:null,redirectUri:null,requiredUrlParams:null,defaultUrlParams:null,oauthType:"1.0",popupOptions:{}};E.prototype.init=function(t){var o=this;return this.oauthPopup=new R("about:blank",this.providerConfig.name,this.providerConfig.popupOptions),b.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)})})},E.prototype.getRequestToken=function(){var e={method:"POST"};return e[this.options.requestDataKey]=h({},this.providerConfig),e.withCredentials=this.options.withCredentials,this.options.baseUrl?e.url=c(this.options.baseUrl,this.providerConfig.url):e.url=this.providerConfig.url,this.$http(e)},E.prototype.openPopup=function(e){var t=[this.providerConfig.authorizationEndpoint,this.buildQueryString(e[this.options.responseDataKey])].join("?");return this.oauthPopup.popup.location=t,b.cordova?this.oauthPopup.open(this.providerConfig.redirectUri):this.oauthPopup.pooling(this.providerConfig.redirectUri)},E.prototype.exchangeForToken=function(e,t){var o=h({},t);o=h(o,e);var r={method:"POST"};return r[this.options.requestDataKey]=o,r.withCredentials=this.options.withCredentials,this.options.baseUrl?r.url=c(this.options.baseUrl,this.providerConfig.url):r.url=this.providerConfig.url,this.$http(r)};function q(e,t,o,r){this.$http=e,this.storage=t,this.providerConfig=h({},A),this.providerConfig=h(this.providerConfig,o),this.options=r}var A={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",tokenRequestAsForm:!(E.prototype.buildQueryString=function(e){var t=[];for(var o in e){var r=e[o];t.push(encodeURIComponent(o)+"="+encodeURIComponent(r))}return t.join("&")}),refreshRequestAsForm:!1,refreshGrantType:null,pkce:!1,responseParams:{code:"code",clientId:"clientId",redirectUri:"redirectUri"},refreshParams:{clientId:"clientId",grantType:"grantType",scope:"scope"},oauthType:"2.0",popupOptions:{}};q.prototype.getRandomString=function(e){return this.storage.getItem(e)||this.storage.setItem(e,t.random(64)),console.log(this.storage.getItem(e)),this.storage.getItem(e)},q.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(this.getRandomString(this.providerConfig.name+"_pkce")),o=a.stringify(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"");e=e+"&code_challenge="+encodeURIComponent(o)+"&code_challenge_method=S256"}return this.oauthPopup=new R(e,this.providerConfig.name,this.providerConfig.popupOptions),new m(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)})})},q.prototype.exchangeForToken=function(e,t){var o,r=h({},t);for(var n in this.providerConfig.responseParams){var i=this.providerConfig.responseParams[n];switch(n){case"code":r[i]=e.code;break;case"clientId":r[i]=this.providerConfig.clientId;break;case"redirectUri":r[i]=this.providerConfig.redirectUri;break;default:r[i]=e[n]}}e.state&&(r.state=e.state),o=this.options.baseUrl?c(this.options.baseUrl,this.providerConfig.url):this.providerConfig.url;var s=this.getRandomString(this.providerConfig.name+"_pkce");if(s&&(r.code_verifier=s,r.grant_type="authorization_code",console.log(s)),this.providerConfig.tokenRequestAsForm){var a=new FormData;for(var p in r){var u=r[p];a.append(p,u)}r=a}return this.$http.post(o,r,{withCredentials:this.options.withCredentials})},q.prototype._stringifyRequestParams=function(){var n=this,i=[];return["defaultUrlParams","requiredUrlParams","optionalUrlParams"].forEach(function(e){n.providerConfig[e]&&Array.isArray(n.providerConfig[e])&&n.providerConfig[e].forEach(function(e){var t=e.replace(/([\:\-\_]+(.))/g,function(e,t,o,r){return r?o.toUpperCase():o}),o=p(n.providerConfig[e])?n.providerConfig[e]():n.providerConfig[t];if("redirect_uri"!==e||o){if("state"===e){var r=n.providerConfig.name+"_state";o=encodeURIComponent(n.storage.getItem(r))}"scope"===e&&Array.isArray(o)&&(o=o.join(n.providerConfig.scopeDelimiter),n.providerConfig.scopePrefix&&(o=[n.providerConfig.scopePrefix,o].join(n.providerConfig.scopeDelimiter))),i.push([e,o])}})}),i.map(function(e){return e.join("=")}).join("&")},q.prototype.getRefreshToken=function(e){return"storage"===this.options.refreshType?this.storage.getItem(e):null},q.prototype.refresh=function(e){if(!this.options.storageType)throw new Error("Refreshing is not set");var t={};for(var o in"storage"===this.options.refreshType&&(t.refresh_token=this.getRefreshToken(e)),this.providerConfig.refreshParams){var r=this.providerConfig.refreshParams[o];switch(o){case"clientId":t[r]=this.providerConfig.clientId;break;case"grantType":t[r]=this.providerConfig.refreshGrantType;break;default:t[r]=this.providerConfig[o]}}if(this.providerConfig.refreshRequestAsForm){var n=new FormData;for(var i in t){var s=t[i];n.set(i,s)}t=n}var a=f(this.providerConfig,this.options,0,t);return this.$http(a)};var N=function(e,t){var o=h({},U),r=function(e){switch(e.storageType){case"localStorage":try{return b.localStorage.setItem("testKey","test"),b.localStorage.removeItem("testKey"),new j(e.storageNamespace)}catch(e){}case"sessionStorage":try{return b.sessionStorage.setItem("testKey","test"),b.sessionStorage.removeItem("testKey"),new O(e.storageNamespace)}catch(e){}case"cookieStorage":return new P(e.cookieStorage);case"memoryStorage":default:return new S(e.storageNamespace)}}(o=h(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||!p(this.options.bindRequestInterceptor))throw new Error("Request interceptor must be functions");if(this.options.bindRequestInterceptor.call(this,this),!this.options.bindResponseInterceptor||!p(this.options.bindResponseInterceptor))throw new Error("Response interceptor must be functions");this.options.bindResponseInterceptor.call(this,this)};function D(e,t){if(!D.installed){D.installed=!0;var o=null;Object.defineProperties(e.prototype,{$auth:{get:function(){if(!o){if(!this.$http)throw new Error("Request handler instance not found");o=new N(this.$http,t)}return o}}})}}return N.prototype.isAuthenticated=function(){var e,t=this.storage.getItem(this.tokenName);if(t){if(3===t.split(".").length)try{var o=(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},N.prototype.isTokenSet=function(){return!o(this.getToken())&&!!this.getToken()},N.prototype.getToken=function(){return this.storage.getItem(this.tokenName)},N.prototype.setToken=function(e,t){e[this.options.responseDataKey]&&(e=e[this.options.responseDataKey]);var o=i(e,t||this.options.tokenPath);o&&this.storage.setItem(this.tokenName,o)},N.prototype.getLoggedInProvider=function(){return this.storage.getItem("LoggedInProvider")},N.prototype.setLoggedInProvider=function(e){this.storage.setItem("LoggedInProvider",e)},N.prototype.getExpiration=function(){return this.options.refreshType?this.storage.getItem(this.expirationName):null},N.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;var o=i(e,t||this.options.refreshTokenPath);return!o&&e&&(o=e[this.options.expirationName]),o&&this.storage.setItem(this.refreshTokenName,o),e}},N.prototype.setExpiration=function(e){var t;if(e.expires_in){var o=parseInt(e.expires_in);isNaN(o)&&(o=0),t=Math.round((new Date).getTime()/1e3)+o}if(!t&&e){var r=parseInt(e[this.options.expirationName]);isNaN(r)&&(r=0),t=Math.round((new Date).getTime()/1e3)+r}return t&&this.storage.setItem(this.expirationName,t),e},N.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(r(t))}catch(e){}},N.prototype.login=function(e,t){var o=this;return t=f(t,this.options,0,e),this.$http(t).then(function(e){if(o.setToken(e),o.setRefreshToken(e),o.isAuthenticated())return m.resolve(e);throw new Error("Server did not provided an access token.")}).catch(function(e){return m.reject(e)})},N.prototype.register=function(e,t){var o=this;return t=f(t,this.options,0,e),this.$http(t).then(function(e){return o.setToken(e),o.setRefreshToken(e),m.resolve(e)}).catch(function(e){return m.reject(e)})},N.prototype.logout=function(e){var t=this;return this.isAuthenticated()?(e=e||{}).url||this.options.logoutUrl?(e.url=e.url?e.url:c(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),m.resolve(e)}).catch(function(e){return m.reject(e)})):(this.storage.removeItem(this.tokenName),m.resolve()):m.reject(new Error("There is no currently authenticated user"))},N.prototype.refresh=function(){var e,t=this,o=this.getLoggedInProvider(),r=this.options.providers[o],n=this.refreshTokenName;if(!r)return reject(new Error("Unknown provider"));switch(r.oauthType){case"2.0":e=new q(this.$http,this.storage,r,this.options);break;default:return reject(new Error("Invalid OAuth type for refresh"))}return e.refresh(n).then(function(e){return t.setToken(e),t.setRefreshToken(e),e}).catch(function(e){throw t.clearStorage(),e})},N.prototype.clearStorage=function(){this.storage.removeItem(this.tokenName),this.storage.removeItem(this.expirationName),this.storage.removeItem(this.refreshTokenName)},N.prototype.authenticate=function(n,i){var s=this;return new m(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 E(s.$http,s.storage,r,s.options);break;case"2.0":e=new q(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)})})},N.prototype.link=function(n,i){var s=this;return new m(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 E(s.$http,s.storage,r,s.options);break;case"2.0":o=new q(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)})},D.factory=function(e,t){return new N(e,t)},D}); |
{ | ||
"name": "@simbachain/vue-authenticate", | ||
"version": "1.5.0", | ||
"version": "1.5.1", | ||
"description": "Authentication library for Vue.js", | ||
@@ -5,0 +5,0 @@ "main": "dist/vue-authenticate.common.js", |
[**WARNING**]: README file is currently in process of rewrite and will be released soon. | ||
# vue-authenticate | ||
# @simbachain/vue-authenticate | ||
[![Join the chat at https://gitter.im/vuejs-auth/vue-authenticate](https://badges.gitter.im/vue-authenticate/Lobby.svg)](https://gitter.im/vuejs-auth/vue-authenticate?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
Fork of [vue-authenticate](https://github.com/dgrubelic/vue-authenticate) adding support for refresh tokens and PKCE auth code flow. | ||
@@ -7,0 +7,0 @@ **vue-authenticate** is easily configurable solution for [Vue.js](https://vuejs.org/) that provides local login/registration as well as Social login using Github, Facebook, Google and other OAuth providers. |
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
205893