UNPKG

@mo-platform/auth

Version:

Mo authentication library

2 lines 21.8 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("moauth",[],e):"object"==typeof exports?exports.moauth=e():t.moauth=e()}(window,function(){return function(r){var n={};function o(t){if(n[t])return n[t].exports;var e=n[t]={i:t,l:!1,exports:{}};return r[t].call(e.exports,e,e.exports,o),e.l=!0,e.exports}return o.m=r,o.c=n,o.d=function(t,e,r){o.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(o.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)o.d(r,n,function(t){return e[t]}.bind(null,n));return r},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="",o(o.s=1)}([function(t,e,r){"use strict";t.exports=function(t){return null!==t&&"object"==typeof t}},function(t,e,r){t.exports=r(8)},function(t,r,e){var n;n="undefined"!=typeof window?window:"undefined"!=typeof self?self:(console.warn("Using browser-only version of superagent in non-browser environment"),this);var o=e(3),i=e(4),s=e(0),a=e(5),u=e(7);function h(){}var c=r=t.exports=function(t,e){return"function"==typeof e?new r.Request("GET",t).end(e):1==arguments.length?new r.Request("GET",t):new r.Request(t,e)};r.Request=_,c.getXHR=function(){if(!(!n.XMLHttpRequest||n.location&&"file:"==n.location.protocol&&n.ActiveXObject))return new XMLHttpRequest;try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(t){}try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(t){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(t){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(t){}throw Error("Browser-only version of superagent could not find XHR")};var l="".trim?function(t){return t.trim()}:function(t){return t.replace(/(^\s*|\s*$)/g,"")};function p(t){if(!s(t))return t;var e=[];for(var r in t)f(e,r,t[r]);return e.join("&")}function f(e,r,t){if(null!=t)if(Array.isArray(t))t.forEach(function(t){f(e,r,t)});else if(s(t))for(var n in t)f(e,r+"["+n+"]",t[n]);else e.push(encodeURIComponent(r)+"="+encodeURIComponent(t));else null===t&&e.push(encodeURIComponent(r))}function d(t){for(var e,r,n={},o=t.split("&"),i=0,s=o.length;i<s;++i)-1==(r=(e=o[i]).indexOf("="))?n[decodeURIComponent(e)]="":n[decodeURIComponent(e.slice(0,r))]=decodeURIComponent(e.slice(r+1));return n}function y(t){return/[\/+]json($|[^-\w])/.test(t)}function m(t){this.req=t,this.xhr=this.req.xhr,this.text="HEAD"!=this.req.method&&(""===this.xhr.responseType||"text"===this.xhr.responseType)||void 0===this.xhr.responseType?this.xhr.responseText:null,this.statusText=this.req.xhr.statusText;var e=this.xhr.status;1223===e&&(e=204),this._setStatusProperties(e),this.header=this.headers=function(t){for(var e,r,n,o,i=t.split(/\r?\n/),s={},a=0,u=i.length;a<u;++a)-1!==(e=(r=i[a]).indexOf(":"))&&(n=r.slice(0,e).toLowerCase(),o=l(r.slice(e+1)),s[n]=o);return s}(this.xhr.getAllResponseHeaders()),this.header["content-type"]=this.xhr.getResponseHeader("content-type"),this._setHeaderProperties(this.header),null===this.text&&t._responseType?this.body=this.xhr.response:this.body="HEAD"!=this.req.method?this._parseBody(this.text?this.text:this.xhr.response):null}function _(t,e){var n=this;this._query=this._query||[],this.method=t,this.url=e,this.header={},this._header={},this.on("end",function(){var e,r=null,t=null;try{t=new m(n)}catch(t){return(r=new Error("Parser is unable to parse the response")).parse=!0,r.original=t,n.xhr?(r.rawResponse=void 0===n.xhr.responseType?n.xhr.responseText:n.xhr.response,r.status=n.xhr.status?n.xhr.status:null,r.statusCode=r.status):(r.rawResponse=null,r.status=null),n.callback(r)}n.emit("response",t);try{n._isResponseOK(t)||(e=new Error(t.statusText||"Unsuccessful HTTP response"))}catch(t){e=t}e?(e.original=r,e.response=t,e.status=t.status,n.callback(e,t)):n.callback(null,t)})}function v(t,e,r){var n=c("DELETE",t);return"function"==typeof e&&(r=e,e=null),e&&n.send(e),r&&n.end(r),n}c.serializeObject=p,c.parseString=d,c.types={html:"text/html",json:"application/json",xml:"text/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},c.serialize={"application/x-www-form-urlencoded":p,"application/json":JSON.stringify},c.parse={"application/x-www-form-urlencoded":d,"application/json":JSON.parse},a(m.prototype),m.prototype._parseBody=function(t){var e=c.parse[this.type];return this.req._parser?this.req._parser(this,t):(!e&&y(this.type)&&(e=c.parse["application/json"]),e&&t&&(t.length||t instanceof Object)?e(t):null)},m.prototype.toError=function(){var t=this.req,e=t.method,r=t.url,n="cannot "+e+" "+r+" ("+this.status+")",o=new Error(n);return o.status=this.status,o.method=e,o.url=r,o},c.Response=m,o(_.prototype),i(_.prototype),_.prototype.type=function(t){return this.set("Content-Type",c.types[t]||t),this},_.prototype.accept=function(t){return this.set("Accept",c.types[t]||t),this},_.prototype.auth=function(t,e,r){1===arguments.length&&(e=""),"object"==typeof e&&null!==e&&(r=e,e=""),r||(r={type:"function"==typeof btoa?"basic":"auto"});return this._auth(t,e,r,function(t){if("function"==typeof btoa)return btoa(t);throw new Error("Cannot use basic auth, btoa is not a function")})},_.prototype.query=function(t){return"string"!=typeof t&&(t=p(t)),t&&this._query.push(t),this},_.prototype.attach=function(t,e,r){if(e){if(this._data)throw Error("superagent can't mix .send() and .attach()");this._getFormData().append(t,e,r||e.name)}return this},_.prototype._getFormData=function(){return this._formData||(this._formData=new n.FormData),this._formData},_.prototype.callback=function(t,e){if(this._shouldRetry(t,e))return this._retry();var r=this._callback;this.clearTimeout(),t&&(this._maxRetries&&(t.retries=this._retries-1),this.emit("error",t)),r(t,e)},_.prototype.crossDomainError=function(){var t=new Error("Request has been terminated\nPossible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.");t.crossDomain=!0,t.status=this.status,t.method=this.method,t.url=this.url,this.callback(t)},_.prototype.buffer=_.prototype.ca=_.prototype.agent=function(){return console.warn("This is not supported in browser version of superagent"),this},_.prototype.pipe=_.prototype.write=function(){throw Error("Streaming is not supported in browser version of superagent")},_.prototype._isHost=function(t){return t&&"object"==typeof t&&!Array.isArray(t)&&"[object Object]"!==Object.prototype.toString.call(t)},_.prototype.end=function(t){return this._endCalled&&console.warn("Warning: .end() was called twice. This is not supported in superagent"),this._endCalled=!0,this._callback=t||h,this._finalizeQueryString(),this._end()},_.prototype._end=function(){var r=this,n=this.xhr=c.getXHR(),t=this._formData||this._data;this._setTimeouts(),n.onreadystatechange=function(){var t=n.readyState;if(2<=t&&r._responseTimeoutTimer&&clearTimeout(r._responseTimeoutTimer),4==t){var e;try{e=n.status}catch(t){e=0}if(!e){if(r.timedout||r._aborted)return;return r.crossDomainError()}r.emit("end")}};var e=function(t,e){0<e.total&&(e.percent=e.loaded/e.total*100),e.direction=t,r.emit("progress",e)};if(this.hasListeners("progress"))try{n.onprogress=e.bind(null,"download"),n.upload&&(n.upload.onprogress=e.bind(null,"upload"))}catch(t){}try{this.username&&this.password?n.open(this.method,this.url,!0,this.username,this.password):n.open(this.method,this.url,!0)}catch(t){return this.callback(t)}if(this._withCredentials&&(n.withCredentials=!0),!this._formData&&"GET"!=this.method&&"HEAD"!=this.method&&"string"!=typeof t&&!this._isHost(t)){var o=this._header["content-type"],i=this._serializer||c.serialize[o?o.split(";")[0]:""];!i&&y(o)&&(i=c.serialize["application/json"]),i&&(t=i(t))}for(var s in this.header)null!=this.header[s]&&this.header.hasOwnProperty(s)&&n.setRequestHeader(s,this.header[s]);return this._responseType&&(n.responseType=this._responseType),this.emit("request",this),n.send(void 0!==t?t:null),this},c.agent=function(){return new u},["GET","POST","OPTIONS","PATCH","PUT","DELETE"].forEach(function(n){u.prototype[n.toLowerCase()]=function(t,e){var r=new c.Request(n,t);return this._setDefaults(r),e&&r.end(e),r}}),u.prototype.del=u.prototype.delete,c.get=function(t,e,r){var n=c("GET",t);return"function"==typeof e&&(r=e,e=null),e&&n.query(e),r&&n.end(r),n},c.head=function(t,e,r){var n=c("HEAD",t);return"function"==typeof e&&(r=e,e=null),e&&n.query(e),r&&n.end(r),n},c.options=function(t,e,r){var n=c("OPTIONS",t);return"function"==typeof e&&(r=e,e=null),e&&n.send(e),r&&n.end(r),n},c.del=v,c.delete=v,c.patch=function(t,e,r){var n=c("PATCH",t);return"function"==typeof e&&(r=e,e=null),e&&n.send(e),r&&n.end(r),n},c.post=function(t,e,r){var n=c("POST",t);return"function"==typeof e&&(r=e,e=null),e&&n.send(e),r&&n.end(r),n},c.put=function(t,e,r){var n=c("PUT",t);return"function"==typeof e&&(r=e,e=null),e&&n.send(e),r&&n.end(r),n}},function(t,e,r){function n(t){if(t)return function(t){for(var e in n.prototype)t[e]=n.prototype[e];return t}(t)}(t.exports=n).prototype.on=n.prototype.addEventListener=function(t,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+t]=this._callbacks["$"+t]||[]).push(e),this},n.prototype.once=function(t,e){function r(){this.off(t,r),e.apply(this,arguments)}return r.fn=e,this.on(t,r),this},n.prototype.off=n.prototype.removeListener=n.prototype.removeAllListeners=n.prototype.removeEventListener=function(t,e){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var r,n=this._callbacks["$"+t];if(!n)return this;if(1==arguments.length)return delete this._callbacks["$"+t],this;for(var o=0;o<n.length;o++)if((r=n[o])===e||r.fn===e){n.splice(o,1);break}return 0===n.length&&delete this._callbacks["$"+t],this},n.prototype.emit=function(t){this._callbacks=this._callbacks||{};for(var e=new Array(arguments.length-1),r=this._callbacks["$"+t],n=1;n<arguments.length;n++)e[n-1]=arguments[n];if(r){n=0;for(var o=(r=r.slice(0)).length;n<o;++n)r[n].apply(this,e)}return this},n.prototype.listeners=function(t){return this._callbacks=this._callbacks||{},this._callbacks["$"+t]||[]},n.prototype.hasListeners=function(t){return!!this.listeners(t).length}},function(t,e,r){"use strict";var o=r(0);function n(t){if(t)return function(t){for(var e in n.prototype)t[e]=n.prototype[e];return t}(t)}(t.exports=n).prototype.clearTimeout=function(){return clearTimeout(this._timer),clearTimeout(this._responseTimeoutTimer),delete this._timer,delete this._responseTimeoutTimer,this},n.prototype.parse=function(t){return this._parser=t,this},n.prototype.responseType=function(t){return this._responseType=t,this},n.prototype.serialize=function(t){return this._serializer=t,this},n.prototype.timeout=function(t){if(!t||"object"!=typeof t)return this._timeout=t,this._responseTimeout=0,this;for(var e in t)switch(e){case"deadline":this._timeout=t.deadline;break;case"response":this._responseTimeout=t.response;break;default:console.warn("Unknown timeout option",e)}return this},n.prototype.retry=function(t,e){return 0!==arguments.length&&!0!==t||(t=1),t<=0&&(t=0),this._maxRetries=t,this._retries=0,this._retryCallback=e,this};var i=["ECONNRESET","ETIMEDOUT","EADDRINFO","ESOCKETTIMEDOUT"];n.prototype._shouldRetry=function(t,e){if(!this._maxRetries||this._retries++>=this._maxRetries)return!1;if(this._retryCallback)try{var r=this._retryCallback(t,e);if(!0===r)return!0;if(!1===r)return!1}catch(t){console.error(t)}if(e&&e.status&&500<=e.status&&501!=e.status)return!0;if(t){if(t.code&&~i.indexOf(t.code))return!0;if(t.timeout&&"ECONNABORTED"==t.code)return!0;if(t.crossDomain)return!0}return!1},n.prototype._retry=function(){return this.clearTimeout(),this.req&&(this.req=null,this.req=this.request()),this._aborted=!1,this.timedout=!1,this._end()},n.prototype.then=function(t,e){if(!this._fullfilledPromise){var o=this;this._endCalled&&console.warn("Warning: superagent request was sent twice, because both .end() and .then() were called. Never call .end() if you use promises"),this._fullfilledPromise=new Promise(function(r,n){o.end(function(t,e){t?n(t):r(e)})})}return this._fullfilledPromise.then(t,e)},n.prototype.catch=function(t){return this.then(void 0,t)},n.prototype.use=function(t){return t(this),this},n.prototype.ok=function(t){if("function"!=typeof t)throw Error("Callback required");return this._okCallback=t,this},n.prototype._isResponseOK=function(t){return!!t&&(this._okCallback?this._okCallback(t):200<=t.status&&t.status<300)},n.prototype.getHeader=n.prototype.get=function(t){return this._header[t.toLowerCase()]},n.prototype.set=function(t,e){if(o(t)){for(var r in t)this.set(r,t[r]);return this}return this._header[t.toLowerCase()]=e,this.header[t]=e,this},n.prototype.unset=function(t){return delete this._header[t.toLowerCase()],delete this.header[t],this},n.prototype.field=function(t,e){if(null==t)throw new Error(".field(name, val) name can not be empty");if(this._data&&console.error(".field() can't be used if .send() is used. Please use only .send() or only .field() & .attach()"),o(t)){for(var r in t)this.field(r,t[r]);return this}if(Array.isArray(e)){for(var n in e)this.field(t,e[n]);return this}if(null==e)throw new Error(".field(name, val) val can not be empty");return"boolean"==typeof e&&(e=""+e),this._getFormData().append(t,e),this},n.prototype.abort=function(){return this._aborted||(this._aborted=!0,this.xhr&&this.xhr.abort(),this.req&&this.req.abort(),this.clearTimeout(),this.emit("abort")),this},n.prototype._auth=function(t,e,r,n){switch(r.type){case"basic":this.set("Authorization","Basic "+n(t+":"+e));break;case"auto":this.username=t,this.password=e;break;case"bearer":this.set("Authorization","Bearer "+t)}return this},n.prototype.withCredentials=function(t){return null==t&&(t=!0),this._withCredentials=t,this},n.prototype.redirects=function(t){return this._maxRedirects=t,this},n.prototype.maxResponseSize=function(t){if("number"!=typeof t)throw TypeError("Invalid argument");return this._maxResponseSize=t,this},n.prototype.toJSON=function(){return{method:this.method,url:this.url,data:this._data,headers:this._header}},n.prototype.send=function(t){var e=o(t),r=this._header["content-type"];if(this._formData&&console.error(".send() can't be used if .attach() or .field() is used. Please use only .send() or only .field() & .attach()"),e&&!this._data)Array.isArray(t)?this._data=[]:this._isHost(t)||(this._data={});else if(t&&this._data&&this._isHost(this._data))throw Error("Can't merge these send calls");if(e&&o(this._data))for(var n in t)this._data[n]=t[n];else"string"==typeof t?(r||this.type("form"),r=this._header["content-type"],this._data="application/x-www-form-urlencoded"==r?this._data?this._data+"&"+t:t:(this._data||"")+t):this._data=t;return!e||this._isHost(t)||r||this.type("json"),this},n.prototype.sortQuery=function(t){return this._sort=void 0===t||t,this},n.prototype._finalizeQueryString=function(){var t=this._query.join("&");if(t&&(this.url+=(0<=this.url.indexOf("?")?"&":"?")+t),this._query.length=0,this._sort){var e=this.url.indexOf("?");if(0<=e){var r=this.url.substring(e+1).split("&");"function"==typeof this._sort?r.sort(this._sort):r.sort(),this.url=this.url.substring(0,e)+"?"+r.join("&")}}},n.prototype._appendQueryString=function(){console.trace("Unsupported")},n.prototype._timeoutError=function(t,e,r){if(!this._aborted){var n=new Error(t+e+"ms exceeded");n.timeout=e,n.code="ECONNABORTED",n.errno=r,this.timedout=!0,this.abort(),this.callback(n)}},n.prototype._setTimeouts=function(){var t=this;this._timeout&&!this._timer&&(this._timer=setTimeout(function(){t._timeoutError("Timeout of ",t._timeout,"ETIME")},this._timeout)),this._responseTimeout&&!this._responseTimeoutTimer&&(this._responseTimeoutTimer=setTimeout(function(){t._timeoutError("Response timeout of ",t._responseTimeout,"ETIMEDOUT")},this._responseTimeout))}},function(t,e,r){"use strict";var o=r(6);function n(t){if(t)return function(t){for(var e in n.prototype)t[e]=n.prototype[e];return t}(t)}(t.exports=n).prototype.get=function(t){return this.header[t.toLowerCase()]},n.prototype._setHeaderProperties=function(t){var e=t["content-type"]||"";this.type=o.type(e);var r=o.params(e);for(var n in r)this[n]=r[n];this.links={};try{t.link&&(this.links=o.parseLinks(t.link))}catch(t){}},n.prototype._setStatusProperties=function(t){var e=t/100|0;this.status=this.statusCode=t,this.statusType=e,this.info=1==e,this.ok=2==e,this.redirect=3==e,this.clientError=4==e,this.serverError=5==e,this.error=(4==e||5==e)&&this.toError(),this.created=201==t,this.accepted=202==t,this.noContent=204==t,this.badRequest=400==t,this.unauthorized=401==t,this.notAcceptable=406==t,this.forbidden=403==t,this.notFound=404==t,this.unprocessableEntity=422==t}},function(t,e,r){"use strict";e.type=function(t){return t.split(/ *; */).shift()},e.params=function(t){return t.split(/ *; */).reduce(function(t,e){var r=e.split(/ *= */),n=r.shift(),o=r.shift();return n&&o&&(t[n]=o),t},{})},e.parseLinks=function(t){return t.split(/ *, */).reduce(function(t,e){var r=e.split(/ *; */),n=r[0].slice(1,-1);return t[r[1].split(/ *= */)[1].slice(1,-1)]=n,t},{})},e.cleanHeader=function(t,e){return delete t["content-type"],delete t["content-length"],delete t["transfer-encoding"],delete t.host,e&&(delete t.authorization,delete t.cookie),t}},function(t,e){function r(){this._defaults=[]}["use","on","once","set","query","type","accept","auth","withCredentials","sortQuery","retry","ok","redirects","timeout","buffer","serialize","parse","ca","key","pfx","cert"].forEach(function(t){r.prototype[t]=function(){return this._defaults.push({fn:t,arguments:arguments}),this}}),r.prototype._setDefaults=function(e){this._defaults.forEach(function(t){e[t.fn].apply(e,t.arguments)})},t.exports=r},function(t,e,r){"use strict";function n(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}r.r(e);var a=r(2),o=function(){function u(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,u);var e=t.authUrl,r=t.clientId,n=t.storage,o=t.loginUrl,i=t.logoutUrl,s=t.userFetchUrl,a=t.accessCheckUrl;this.authUrl=e||"https://moauth.fagbokforlaget.no",this.currentUser=void 0,this.token=void 0,this.clientId=r,this.storage=n||window.localStorage,this.loginUrl=o||this.authUrl+"/_auth/login",this.logoutUrl=i||this.authUrl+"/_auth/logout",this.userFetchUrl=s||this.authUrl+"/_auth/user?token=",this.accessCheckUrl=a||this.authUrl+"/_auth/access/{{productId}}?token={{token}}"}return function(t,e,r){e&&n(t.prototype,e),r&&n(t,r)}(u,[{key:"_loginUrl",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:void 0;return this.loginUrl.includes("?")||(this.loginUrl+="?"),this.loginUrl+"&client_id="+(this.clientId||"generic")+"&redirect_url="+encodeURIComponent(t)+"&scope="+(e||"dbok")}},{key:"_parseQueryString",value:function(t){var e=/\+/g,r=/([^&=]+)=?([^&]*)/g,n=function(t){return decodeURIComponent(t.replace(e," "))},o={},i=t.substring(1);for(/\?/.test(i)&&(i=i.split("?")[1]);;){var s=r.exec(i);if(!s)break;o[n(s[1])]=n(s[2])}return o}},{key:"authorize",value:function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},e=t.redirectUrl,r=t.scope;window.location=this._loginUrl(e||window.location,r)}},{key:"getUser",value:function(){var t=this.storage.getItem("user");return this.currentUser?this.currentUser:t?JSON.parse(t):void 0}},{key:"checkToken",value:function(){var t=this,e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:window.location.search,r=this._parseQueryString(e),n=this;return n.token=r.token||r.access_token||this.storage.getItem("token")||void 0,new Promise(function(e,r){n.isAuthenticated()&&n.token&&void 0!==n.token&&e(n.getUser()),n.token&&void 0!==n.token?(window&&window.history.replaceState({},"",window.location.pathname+window.location.hash||""),n.storage.setItem("token",n.token),n.fetchUser(t.userFetchUrl+encodeURIComponent(n.token)).then(function(t){e(t)}).catch(function(t){r(t)})):r(new Error("access token not found"))})}},{key:"checkAccess",value:function(n){var o=this,i=this.token||this.storage.getItem("token")||void 0;return new Promise(function(e,r){if(i&&void 0!==i){var t=o.accessCheckUrl.replace(/{{productId}}/g,n).replace(/{{token}}/g,i);o.fetchAccess(t).then(function(t){e(t)}).catch(function(t){r(t)})}else r(new Error("access token not found"))})}},{key:"fetchUser",value:function(t){var s=this;return new Promise(function(o,i){a("GET",t).end(function(t,e){if(!t&&200===e.statusCode&&e.body){var r=e.body,n=r.user||r.objects[0];s.storage.setItem("user",JSON.stringify(n)),o(n)}else i(new Error("authentication failed:"+t))})})}},{key:"fetchAccess",value:function(t){return new Promise(function(r,n){a("GET",t).end(function(t,e){!t&&200===e.statusCode&&e.body?e.body.success?r(e.body.product):n(new Error("This user does not have access to this product")):n(t)})})}},{key:"logout",value:function(r){this.storage.removeItem("user"),this.storage.removeItem("token"),this.logoutUrl&&a("GET",this.logoutUrl).end(function(t,e){r&&(window.location=r)})}},{key:"isAuthenticated",value:function(){return!!this.getUser()}}]),u}();e.default=o}])}); //# sourceMappingURL=moauth.bundle.js.map