@nsshunt/stsoauth2plugin 1.0.11 → 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/stsoauth2plugin.mjs +1340 -739
- package/dist/stsoauth2plugin.mjs.map +1 -1
- package/dist/stsoauth2plugin.umd.js +2135 -1
- package/dist/stsoauth2plugin.umd.js.map +1 -1
- package/package.json +6 -6
|
@@ -1,2 +1,2136 @@
|
|
|
1
|
-
(function(l,O){typeof exports=="object"&&typeof module<"u"?O(exports,require("vue"),require("debug"),require("node:worker_threads"),require("@nsshunt/stsutils"),require("@nsshunt/stsvueutils"),require("pinia"),require("@nsshunt/stspublisherserver"),require("node:https"),require("colors"),require("axios"),require("@nsshunt/stsinstrumentation")):typeof define=="function"&&define.amd?define(["exports","vue","debug","node:worker_threads","@nsshunt/stsutils","@nsshunt/stsvueutils","pinia","@nsshunt/stspublisherserver","node:https","colors","axios","@nsshunt/stsinstrumentation"],O):(l=typeof globalThis<"u"?globalThis:l||self,O(l["@nsshunt/stsoauth2plugin"]={},l.vue,l.debug,l.worker_threads,l.stsutils,l.stsvueutils,l.pinia,l.stspublisherserver,l.https,null,l.axios,l.stsinstrumentation))})(this,function(l,O,y,te,G,re,qe,Ye,at,kt,Be,ct){var se,ie,Qe,Ke,ae,We,K,x,Ve,W,ye,j,fe,V,q,ce,ge,Se,pe,z,Ae,Ie,Y,Ne,ve,we,B,X,ke,F,Z,u,ee,Q,le,he,Pe,Ue,De,$,Me,Le,be,Te,He,de,Ce;"use strict";var vt=Object.defineProperty;var wt=(l,O,y)=>O in l?vt(l,O,{enumerable:!0,configurable:!0,writable:!0,value:y}):l[O]=y;var M=(l,O,y)=>(wt(l,typeof O!="symbol"?O+"":O,y),y),st=(l,O,y)=>{if(!O.has(l))throw TypeError("Cannot "+y)};var t=(l,O,y)=>(st(l,O,"read from private field"),y?y.call(l):O.get(l)),h=(l,O,y)=>{if(O.has(l))throw TypeError("Cannot add the same private member more than once");O instanceof WeakSet?O.add(l):O.set(l,y)},D=(l,O,y,te)=>(st(l,O,"write to private field"),te?te.call(l,y):O.set(l,y),y),it=(l,O,y,te)=>({set _(G){D(l,O,G,y)},get _(){return t(l,O,te)}});function lt(e){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,o.get?o:{enumerable:!0,get:()=>e[n]})}}return r.default=e,Object.freeze(r)}const ht=lt(te),Ee=Symbol(),L=Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]";var ne=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ut(e){if(e.__esModule)return e;var r=e.default;if(typeof r=="function"){var n=function o(){if(this instanceof o){var a=[null];a.push.apply(a,arguments);var i=Function.bind.apply(r,a);return new i}return r.apply(this,arguments)};n.prototype=r.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach(function(o){var a=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(n,o,a.get?a:{enumerable:!0,get:function(){return e[o]}})}),n}var $e={},Et={get exports(){return $e},set exports(e){$e=e}};function ft(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var _e={},gt={get exports(){return _e},set exports(e){_e=e}};const pt=ut(Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"})));var Je;function je(){return Je||(Je=1,function(e,r){(function(n,o){e.exports=o()})(ne,function(){var n=n||function(o,a){var i;if(typeof window<"u"&&window.crypto&&(i=window.crypto),typeof self<"u"&&self.crypto&&(i=self.crypto),typeof globalThis<"u"&&globalThis.crypto&&(i=globalThis.crypto),!i&&typeof window<"u"&&window.msCrypto&&(i=window.msCrypto),!i&&typeof ne<"u"&&ne.crypto&&(i=ne.crypto),!i&&typeof ft=="function")try{i=pt}catch{}var p=function(){if(i){if(typeof i.getRandomValues=="function")try{return i.getRandomValues(new Uint32Array(1))[0]}catch{}if(typeof i.randomBytes=="function")try{return i.randomBytes(4).readInt32LE()}catch{}}throw new Error("Native crypto module could not be used to get secure random number.")},S=Object.create||function(){function s(){}return function(c){var f;return s.prototype=c,f=new s,s.prototype=null,f}}(),m={},I=m.lib={},k=I.Base=function(){return{extend:function(s){var c=S(this);return s&&c.mixIn(s),(!c.hasOwnProperty("init")||this.init===c.init)&&(c.init=function(){c.$super.init.apply(this,arguments)}),c.init.prototype=c,c.$super=this,c},create:function(){var s=this.extend();return s.init.apply(s,arguments),s},init:function(){},mixIn:function(s){for(var c in s)s.hasOwnProperty(c)&&(this[c]=s[c]);s.hasOwnProperty("toString")&&(this.toString=s.toString)},clone:function(){return this.init.prototype.extend(this)}}}(),d=I.WordArray=k.extend({init:function(s,c){s=this.words=s||[],c!=a?this.sigBytes=c:this.sigBytes=s.length*4},toString:function(s){return(s||g).stringify(this)},concat:function(s){var c=this.words,f=s.words,T=this.sigBytes,N=s.sigBytes;if(this.clamp(),T%4)for(var U=0;U<N;U++){var b=f[U>>>2]>>>24-U%4*8&255;c[T+U>>>2]|=b<<24-(T+U)%4*8}else for(var H=0;H<N;H+=4)c[T+H>>>2]=f[H>>>2];return this.sigBytes+=N,this},clamp:function(){var s=this.words,c=this.sigBytes;s[c>>>2]&=4294967295<<32-c%4*8,s.length=o.ceil(c/4)},clone:function(){var s=k.clone.call(this);return s.words=this.words.slice(0),s},random:function(s){for(var c=[],f=0;f<s;f+=4)c.push(p());return new d.init(c,s)}}),A=m.enc={},g=A.Hex={stringify:function(s){for(var c=s.words,f=s.sigBytes,T=[],N=0;N<f;N++){var U=c[N>>>2]>>>24-N%4*8&255;T.push((U>>>4).toString(16)),T.push((U&15).toString(16))}return T.join("")},parse:function(s){for(var c=s.length,f=[],T=0;T<c;T+=2)f[T>>>3]|=parseInt(s.substr(T,2),16)<<24-T%8*4;return new d.init(f,c/2)}},P=A.Latin1={stringify:function(s){for(var c=s.words,f=s.sigBytes,T=[],N=0;N<f;N++){var U=c[N>>>2]>>>24-N%4*8&255;T.push(String.fromCharCode(U))}return T.join("")},parse:function(s){for(var c=s.length,f=[],T=0;T<c;T++)f[T>>>2]|=(s.charCodeAt(T)&255)<<24-T%4*8;return new d.init(f,c)}},E=A.Utf8={stringify:function(s){try{return decodeURIComponent(escape(P.stringify(s)))}catch{throw new Error("Malformed UTF-8 data")}},parse:function(s){return P.parse(unescape(encodeURIComponent(s)))}},_=I.BufferedBlockAlgorithm=k.extend({reset:function(){this._data=new d.init,this._nDataBytes=0},_append:function(s){typeof s=="string"&&(s=E.parse(s)),this._data.concat(s),this._nDataBytes+=s.sigBytes},_process:function(s){var c,f=this._data,T=f.words,N=f.sigBytes,U=this.blockSize,b=U*4,H=N/b;s?H=o.ceil(H):H=o.max((H|0)-this._minBufferSize,0);var ue=H*U,J=o.min(ue*4,N);if(ue){for(var Oe=0;Oe<ue;Oe+=U)this._doProcessBlock(T,Oe);c=T.splice(0,ue),f.sigBytes-=J}return new d.init(c,J)},clone:function(){var s=k.clone.call(this);return s._data=this._data.clone(),s},_minBufferSize:0});I.Hasher=_.extend({cfg:k.extend(),init:function(s){this.cfg=this.cfg.extend(s),this.reset()},reset:function(){_.reset.call(this),this._doReset()},update:function(s){return this._append(s),this._process(),this},finalize:function(s){s&&this._append(s);var c=this._doFinalize();return c},blockSize:16,_createHelper:function(s){return function(c,f){return new s.init(f).finalize(c)}},_createHmacHelper:function(s){return function(c,f){return new C.HMAC.init(s,f).finalize(c)}}});var C=m.algo={};return m}(Math);return n})}(gt)),_e}(function(e,r){(function(n,o){e.exports=o(je())})(ne,function(n){return function(o){var a=n,i=a.lib,p=i.WordArray,S=i.Hasher,m=a.algo,I=[],k=[];(function(){function g(C){for(var s=o.sqrt(C),c=2;c<=s;c++)if(!(C%c))return!1;return!0}function P(C){return(C-(C|0))*4294967296|0}for(var E=2,_=0;_<64;)g(E)&&(_<8&&(I[_]=P(o.pow(E,1/2))),k[_]=P(o.pow(E,1/3)),_++),E++})();var d=[],A=m.SHA256=S.extend({_doReset:function(){this._hash=new p.init(I.slice(0))},_doProcessBlock:function(g,P){for(var E=this._hash.words,_=E[0],C=E[1],s=E[2],c=E[3],f=E[4],T=E[5],N=E[6],U=E[7],b=0;b<64;b++){if(b<16)d[b]=g[P+b]|0;else{var H=d[b-15],ue=(H<<25|H>>>7)^(H<<14|H>>>18)^H>>>3,J=d[b-2],Oe=(J<<15|J>>>17)^(J<<13|J>>>19)^J>>>10;d[b]=ue+d[b-7]+Oe+d[b-16]}var yt=f&T^~f&N,St=_&C^_&s^C&s,At=(_<<30|_>>>2)^(_<<19|_>>>13)^(_<<10|_>>>22),It=(f<<26|f>>>6)^(f<<21|f>>>11)^(f<<7|f>>>25),ot=U+It+yt+k[b]+d[b],Nt=At+St;U=N,N=T,T=f,f=c+ot|0,c=s,s=C,C=_,_=ot+Nt|0}E[0]=E[0]+_|0,E[1]=E[1]+C|0,E[2]=E[2]+s|0,E[3]=E[3]+c|0,E[4]=E[4]+f|0,E[5]=E[5]+T|0,E[6]=E[6]+N|0,E[7]=E[7]+U|0},_doFinalize:function(){var g=this._data,P=g.words,E=this._nDataBytes*8,_=g.sigBytes*8;return P[_>>>5]|=128<<24-_%32,P[(_+64>>>9<<4)+14]=o.floor(E/4294967296),P[(_+64>>>9<<4)+15]=E,g.sigBytes=P.length*4,this._process(),this._hash},clone:function(){var g=S.clone.call(this);return g._hash=this._hash.clone(),g}});a.SHA256=S._createHelper(A),a.HmacSHA256=S._createHmacHelper(A)}(Math),n.SHA256})})(Et);var Fe={},Tt={get exports(){return Fe},set exports(e){Fe=e}};(function(e,r){(function(n,o){e.exports=o(je())})(ne,function(n){return function(){var o=n,a=o.lib,i=a.WordArray,p=o.enc;p.Base64={stringify:function(m){var I=m.words,k=m.sigBytes,d=this._map;m.clamp();for(var A=[],g=0;g<k;g+=3)for(var P=I[g>>>2]>>>24-g%4*8&255,E=I[g+1>>>2]>>>24-(g+1)%4*8&255,_=I[g+2>>>2]>>>24-(g+2)%4*8&255,C=P<<16|E<<8|_,s=0;s<4&&g+s*.75<k;s++)A.push(d.charAt(C>>>6*(3-s)&63));var c=d.charAt(64);if(c)for(;A.length%4;)A.push(c);return A.join("")},parse:function(m){var I=m.length,k=this._map,d=this._reverseMap;if(!d){d=this._reverseMap=[];for(var A=0;A<k.length;A++)d[k.charCodeAt(A)]=A}var g=k.charAt(64);if(g){var P=m.indexOf(g);P!==-1&&(I=P)}return S(m,I,d)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="};function S(m,I,k){for(var d=[],A=0,g=0;g<I;g++)if(g%4){var P=k[m.charCodeAt(g-1)]<<g%4*2,E=k[m.charCodeAt(g)]>>>6-g%4*2,_=P|E;d[A>>>2]|=_<<24-A%4*8,A++}return i.create(d,A)}}(),n.enc.Base64})})(Tt);class Xe{constructor(){h(this,se,void 0);M(this,"DigestMessage",async function(r){const n=$e(r);return Fe.stringify(n)});M(this,"CreateRandomString",(r=43)=>{const n=Array.from(t(this,se).getRandomValues(new Uint8Array(r)));return btoa(String.fromCharCode(...n))});try{D(this,se,crypto)}catch{D(this,se,require("crypto"))}}}se=new WeakMap;class Ze{constructor(){M(this,"DecodeQueryParams",r=>{const n={};return Object.keys(r).filter(o=>typeof r[o]<"u").map(o=>{n[decodeURIComponent(o)]=decodeURIComponent(r[o])}),n});M(this,"CreateQueryParams",r=>Object.keys(r).filter(n=>typeof r[n]<"u").map(n=>Array.isArray(r[n])?encodeURIComponent(n)+"="+encodeURIComponent(r[n].join(" ")):encodeURIComponent(n)+"="+encodeURIComponent(r[n])).join("&"));M(this,"_GetQueryParams",r=>{let n={};const o=r.split("?");if(o.length==2){const a=o[1].split("&"),i={};let p;a.forEach(function(S){p=S.split("="),p.length==2&&(i[p[0]]=p[1])}),n=this.DecodeQueryParams(i)}return n});M(this,"GetQueryParams",()=>this._GetQueryParams(window.location.href))}}var Ge=(e=>(e.CODE="code",e.ID_TOKEN="id_token",e.TOKEN="token",e))(Ge||{}),ze=(e=>(e.QUERY="query",e.FRAGMENT="fragment",e.FORM_POST="form_post",e))(ze||{}),Re=(e=>(e.CLIENT_CREDENTIALS="client_credentials",e.AUTHORIZATION_CODE="authorization_code",e.REFRESH_TOKEN="refresh_token",e))(Re||{}),R=(e=>(e.RESTORE_SESSION="RestoreSession",e.AUTHORIZE="Authorize",e.HANDLE_REDIRECT="HandleRedirect",e.LOGOUT="Logout",e.AUTHENTICATE_EVENT="AuthenticateEvent",e.ERROR="Error",e.LOG="__LOG",e.UPDATE_INSTRUMENT="__UPDATE_INSTRUMENT",e.ID_TOKEN="__ID_TOKEN",e.ACCESS_TOKEN="__ACCESS_TOKEN",e.COOKIES="__COOKIES",e.EXECUTE_REFRESH_TOKEN="__EXECUTE_REFRESH_TOKEN",e))(R||{});function xe(e){this.message=e}xe.prototype=new Error,xe.prototype.name="InvalidCharacterError";var et=typeof window<"u"&&window.atob&&window.atob.bind(window)||function(e){var r=String(e).replace(/=+$/,"");if(r.length%4==1)throw new xe("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,o,a=0,i=0,p="";o=r.charAt(i++);~o&&(n=a%4?64*n+o:o,a++%4)?p+=String.fromCharCode(255&n>>(-2*a&6)):0)o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o);return p};function dt(e){var r=e.replace(/-/g,"+").replace(/_/g,"/");switch(r.length%4){case 0:break;case 2:r+="==";break;case 3:r+="=";break;default:throw"Illegal base64url string!"}try{return function(n){return decodeURIComponent(et(n).replace(/(.)/g,function(o,a){var i=a.charCodeAt(0).toString(16).toUpperCase();return i.length<2&&(i="0"+i),"%"+i}))}(r)}catch{return et(r)}}function me(e){this.message=e}function tt(e,r){if(typeof e!="string")throw new me("Invalid token specified");var n=(r=r||{}).header===!0?0:1;try{return JSON.parse(dt(e.split(".")[n]))}catch(o){throw new me("Invalid token specified: "+o.message)}}me.prototype=new Error,me.prototype.name="InvalidTokenError";const rt=qe.defineStore("__sts__STSOauth2Store",{state:()=>({id_token:null,error:null}),actions:{UpdateIdToken(e){this.id_token=e},UpdateError(e){this.error?this.error.message=e:this.error={message:e}}},getters:{LoggedIn:e=>!(typeof e.id_token>"u"||e.id_token===null),UserDetails:e=>{if(e.id_token){const r=e.id_token;return tt(r)}else return null}}});let w;L?w=y(`proc:${process.pid}:stsoauth2manager.ts`):w=y("proc:0:stsoauth2manager.ts");class nt{constructor(r,n){h(this,ie,null);h(this,Qe,new Xe);h(this,Ke,new Ze);h(this,ae,"authorize_options.stsmda.com.au");h(this,We,"session.stsmda.com.au");h(this,K,null);h(this,x,void 0);h(this,Ve,{});h(this,W,void 0);h(this,ye,0);h(this,j,{});h(this,fe,1e4);h(this,V,void 0);h(this,q,void 0);h(this,ce,!1);h(this,ge,100);h(this,Se,50);h(this,pe,r=>{const n=r;if(w(`STSOAuth2Manager:#ProcessMessageResponse: message data = [${JSON.stringify(n)}]`.yellow),n.messageId===-1)switch(n.command){case R.AUTHENTICATE_EVENT:t(this,ve).call(this,n.payload);break;case R.ERROR:t(this,Ne).call(this,n.payload);break;case R.LOG:t(this,Ae).call(this,n.payload);break;case R.UPDATE_INSTRUMENT:t(this,Ie).call(this,n.payload.instrumentName,n.payload.telemetry);break;default:throw new Error(`ProcessMessageResponse command [${n.command}] not valid.`)}else{const o=t(this,j)[n.messageId];if(o)o(n);else throw new Error(`Message: [${n.messageId}] does not exists in callBacks.`)}});h(this,z,r=>(r.messageId=it(this,ye)._++,new Promise((n,o)=>{const a=setTimeout(()=>{delete t(this,j)[r.messageId],o(`Message: [${r.messageId}] timeout error after: [${t(this,fe)}] ms.`)},t(this,fe));t(this,j)[r.messageId]=i=>{clearTimeout(a),delete t(this,j)[r.messageId],w(`STSOAuth2Manager:#PostMessage: resolve callback response= [${JSON.stringify(i)}]`.yellow),n(i)},w(`STSOAuth2Manager:#PostMessage: posting message = [${JSON.stringify(r)}]`.yellow),t(this,W).postMessage(r)})));h(this,Ae,r=>{t(this,K)&&t(this,K).LogEx(r),w(r)});h(this,Ie,(r,n)=>{t(this,K)&&t(this,K).UpdateInstrument(r,n)});h(this,Y,()=>rt(t(this,x).pinia));h(this,Ne,r=>{L||(t(this,Y).call(this).UpdateError({message:r}),setTimeout(()=>{t(this,ie).replace("/error")},0))});h(this,ve,r=>{L||(t(this,x).authenticateEvent&&t(this,x).authenticateEvent(r),t(this,Y).call(this).UpdateIdToken(r))});h(this,we,(r,n)=>{w("STSOAuth2Manager:#SetupRoute".gray),n.beforeEach(async(o,a,i)=>{const p=r.config.globalProperties.$sts[Ee];if(w(`beforeEach: from: [${a.path}], to: [${o.path}]`.gray),t(this,Y).call(this).LoggedIn===!1){if(console.log("Not logged in"),o.path.localeCompare("/authorize")===0){console.log("to = /authorize"),i();return}else if(o.path.localeCompare("/consent")===0&&t(this,Y).call(this).id_token){i();return}if(o.path.localeCompare("/logout")===0){i();return}if(o.path.localeCompare("/error")===0){i();return}if(o.path.localeCompare("/config")===0){i();return}if(o.path.localeCompare("/redirected")===0){i();return}const S=o.query;if(S[G.OAuth2ParameterType.CODE]||S[G.OAuth2ParameterType.ERROR]){w(`STSOAuth2Manager:#SetupRoute:Processing redirect: [${JSON.stringify(S)}]`.magenta);const I=await p.HandleRedirect(S);if(w(`STSOAuth2Manager:#SetupRoute:Redirect result: [${I}]`.magenta),I){i({path:"/",replace:!0});return}else{i({path:"/error",replace:!0});return}}w("STSOAuth2Manager:#SetupRoute:Restoring session");const m=await p.RestoreSession();if(w(`STSOAuth2Manager:#SetupRoute:Session restored: [${m}]`),m!==!0){w("STSOAuth2Manager:#SetupRoute:Session not restored - need to authorize"),p.Authorize(),i();return}else{i("/");return}}else{if(o.path.localeCompare("/consent")===0){i("/");return}if(o.path.localeCompare("/authorize")===0){i("/");return}if(o.path.localeCompare("/logout")===0){i("/");return}i()}})});M(this,"GetAccessToken",async()=>(await t(this,z).call(this,{command:R.ACCESS_TOKEN})).payload);M(this,"ExecuteRefreshToken",async(r=0)=>{if(t(this,ce)===!0){if(r>t(this,ge))throw new Error(`STSOAuth2Manager:ExecuteRefreshToken:maxSemaphoreRetries: [${t(this,ge)}] exceeded.`);return await G.Sleep(t(this,Se)),w(`STSOAuth2Manager:ExecuteRefreshToken:locked by operationSemaphore, retry count: [${r}]`.cyan),await this.ExecuteRefreshToken(r+1)}else{D(this,ce,!0);const n=await t(this,z).call(this,{command:R.EXECUTE_REFRESH_TOKEN});return D(this,ce,!1),n.payload}});M(this,"GetCookies",async()=>(await t(this,z).call(this,{command:R.COOKIES})).payload);M(this,"RestoreSession",async()=>{try{w(`STSOAuth2Manager:RestoreSession:postMessage: [${R.RESTORE_SESSION}]`);const r=await t(this,z).call(this,{command:R.RESTORE_SESSION});return w(`STSOAuth2Manager:RestoreSession:response: [${JSON.stringify(r.payload)}]`),r.payload}catch(r){return console.log(`RestoreSession Error: ${r}`),!1}});M(this,"Authorize",async()=>{try{const r=await t(this,z).call(this,{command:R.AUTHORIZE});t(this,q).set(t(this,ae),r.payload.authorizeOptions);const n=r.payload.url;if(!L)window.location.replace(n);else return r.payload.authorizeOptionsClientCopy}catch(r){console.log(`Authorize Error: ${r}`)}return{}});M(this,"HandleRedirect",async r=>{try{w("STSOAuth2Manager:HandleRedirect".magenta);let n=null;if(r[G.OAuth2ParameterType.CODE]){const o=t(this,q).get(t(this,ae));t(this,q).remove(t(this,ae)),w("STSOAuth2Manager:HandleRedirect: sending HANDLE_REDIRECT command".magenta),n=await t(this,z).call(this,{command:R.HANDLE_REDIRECT,payload:{queryVars:r,authorizeOptions:o}})}else n=await t(this,z).call(this,{command:R.HANDLE_REDIRECT,payload:r});return w(`STSOAuth2Manager:HandleRedirect: HANDLE_REDIRECT response: [${JSON.stringify(n)}]`.magenta),n.payload}catch(n){return console.log(`HandleRedirect Error: ${n}`),!1}});M(this,"Logout",async()=>{try{return(await t(this,z).call(this,{command:R.LOGOUT})).payload}catch(r){return console.log(`Logout Error: ${r}`),!1}});M(this,"InvokeExternalAPI",async()=>{try{return(await t(this,z).call(this,{command:R.LOGOUT})).payload}catch(r){return console.log(`InvokeExternalAPI Error: ${r}`),null}});M(this,"LoggedIn",()=>{try{return t(this,Y).call(this).LoggedIn}catch{return!1}});if(D(this,x,n),!L){if(r.config.globalProperties.$sts[Ye.STSInstrumentControllerPluginKey]){const a=r.config.globalProperties.$sts[Ye.STSInstrumentControllerPluginKey];D(this,K,a.PrimaryPublishInstrumentController)}D(this,ie,r.config.globalProperties.$router)}if(L?D(this,q,new re.ClientStorageFactory({clientStorageType:re.ClientStorageType.MEMORY_STORAGE,usePrefix:!1}).GetStorage()):D(this,q,new re.ClientStorageFactory({clientStorageType:re.ClientStorageType.SESSION_STORAGE,usePrefix:!1}).GetStorage()),t(this,x).workerFactory)D(this,V,t(this,x).workerFactory());else throw new Error("STSOAuth2Manager:constructor: Cannot init STSOAuth2Manager - this.#options.workerFactory not specified");L||(t(this,V).onmessage=a=>{console.log(`this.#worker.onmessage = [${a}]`)},t(this,V).onerror=function(a){console.log(`this.#worker.onerror = [${JSON.stringify(a)}]`)});let o;if(L){const{port1:a,port2:i}=new ht.MessageChannel;D(this,W,a),o={workerPort:i,options:t(this,x).workerOptions},t(this,V).postMessage(o,[i]),t(this,W).on("message",p=>{t(this,pe).call(this,p)}).unref()}else{const{port1:a,port2:i}=new MessageChannel;D(this,W,a),o={workerPort:i,options:t(this,x).workerOptions},t(this,V).postMessage(o,[i]),t(this,W).onmessage=p=>{t(this,pe).call(this,p.data)},t(this,we).call(this,r,t(this,ie))}}}ie=new WeakMap,Qe=new WeakMap,Ke=new WeakMap,ae=new WeakMap,We=new WeakMap,K=new WeakMap,x=new WeakMap,Ve=new WeakMap,W=new WeakMap,ye=new WeakMap,j=new WeakMap,fe=new WeakMap,V=new WeakMap,q=new WeakMap,ce=new WeakMap,ge=new WeakMap,Se=new WeakMap,pe=new WeakMap,z=new WeakMap,Ae=new WeakMap,Ie=new WeakMap,Y=new WeakMap,Ne=new WeakMap,ve=new WeakMap,we=new WeakMap;var oe;(function(e){e[e.ACCEPTED=202]="ACCEPTED",e[e.BAD_GATEWAY=502]="BAD_GATEWAY",e[e.BAD_REQUEST=400]="BAD_REQUEST",e[e.CONFLICT=409]="CONFLICT",e[e.CONTINUE=100]="CONTINUE",e[e.CREATED=201]="CREATED",e[e.EXPECTATION_FAILED=417]="EXPECTATION_FAILED",e[e.FAILED_DEPENDENCY=424]="FAILED_DEPENDENCY",e[e.FORBIDDEN=403]="FORBIDDEN",e[e.GATEWAY_TIMEOUT=504]="GATEWAY_TIMEOUT",e[e.GONE=410]="GONE",e[e.HTTP_VERSION_NOT_SUPPORTED=505]="HTTP_VERSION_NOT_SUPPORTED",e[e.IM_A_TEAPOT=418]="IM_A_TEAPOT",e[e.INSUFFICIENT_SPACE_ON_RESOURCE=419]="INSUFFICIENT_SPACE_ON_RESOURCE",e[e.INSUFFICIENT_STORAGE=507]="INSUFFICIENT_STORAGE",e[e.INTERNAL_SERVER_ERROR=500]="INTERNAL_SERVER_ERROR",e[e.LENGTH_REQUIRED=411]="LENGTH_REQUIRED",e[e.LOCKED=423]="LOCKED",e[e.METHOD_FAILURE=420]="METHOD_FAILURE",e[e.METHOD_NOT_ALLOWED=405]="METHOD_NOT_ALLOWED",e[e.MOVED_PERMANENTLY=301]="MOVED_PERMANENTLY",e[e.MOVED_TEMPORARILY=302]="MOVED_TEMPORARILY",e[e.MULTI_STATUS=207]="MULTI_STATUS",e[e.MULTIPLE_CHOICES=300]="MULTIPLE_CHOICES",e[e.NETWORK_AUTHENTICATION_REQUIRED=511]="NETWORK_AUTHENTICATION_REQUIRED",e[e.NO_CONTENT=204]="NO_CONTENT",e[e.NON_AUTHORITATIVE_INFORMATION=203]="NON_AUTHORITATIVE_INFORMATION",e[e.NOT_ACCEPTABLE=406]="NOT_ACCEPTABLE",e[e.NOT_FOUND=404]="NOT_FOUND",e[e.NOT_IMPLEMENTED=501]="NOT_IMPLEMENTED",e[e.NOT_MODIFIED=304]="NOT_MODIFIED",e[e.OK=200]="OK",e[e.PARTIAL_CONTENT=206]="PARTIAL_CONTENT",e[e.PAYMENT_REQUIRED=402]="PAYMENT_REQUIRED",e[e.PERMANENT_REDIRECT=308]="PERMANENT_REDIRECT",e[e.PRECONDITION_FAILED=412]="PRECONDITION_FAILED",e[e.PRECONDITION_REQUIRED=428]="PRECONDITION_REQUIRED",e[e.PROCESSING=102]="PROCESSING",e[e.PROXY_AUTHENTICATION_REQUIRED=407]="PROXY_AUTHENTICATION_REQUIRED",e[e.REQUEST_HEADER_FIELDS_TOO_LARGE=431]="REQUEST_HEADER_FIELDS_TOO_LARGE",e[e.REQUEST_TIMEOUT=408]="REQUEST_TIMEOUT",e[e.REQUEST_TOO_LONG=413]="REQUEST_TOO_LONG",e[e.REQUEST_URI_TOO_LONG=414]="REQUEST_URI_TOO_LONG",e[e.REQUESTED_RANGE_NOT_SATISFIABLE=416]="REQUESTED_RANGE_NOT_SATISFIABLE",e[e.RESET_CONTENT=205]="RESET_CONTENT",e[e.SEE_OTHER=303]="SEE_OTHER",e[e.SERVICE_UNAVAILABLE=503]="SERVICE_UNAVAILABLE",e[e.SWITCHING_PROTOCOLS=101]="SWITCHING_PROTOCOLS",e[e.TEMPORARY_REDIRECT=307]="TEMPORARY_REDIRECT",e[e.TOO_MANY_REQUESTS=429]="TOO_MANY_REQUESTS",e[e.UNAUTHORIZED=401]="UNAUTHORIZED",e[e.UNAVAILABLE_FOR_LEGAL_REASONS=451]="UNAVAILABLE_FOR_LEGAL_REASONS",e[e.UNPROCESSABLE_ENTITY=422]="UNPROCESSABLE_ENTITY",e[e.UNSUPPORTED_MEDIA_TYPE=415]="UNSUPPORTED_MEDIA_TYPE",e[e.USE_PROXY=305]="USE_PROXY",e[e.MISDIRECTED_REQUEST=421]="MISDIRECTED_REQUEST"})(oe||(oe={}));let v;L?v=y(`proc:${process.pid}:stsoauth2worker.ts`):v=y("proc:0:stsoauth2worker.ts");class Ot{constructor(r,n){h(this,B,void 0);h(this,X,new Xe);h(this,ke,new Ze);h(this,F,"session.stsmda.com.au");h(this,Z,void 0);h(this,u,void 0);h(this,ee,null);h(this,Q,r=>{const n={messageId:-1,command:R.AUTHENTICATE_EVENT};t(this,$).call(this,n,r)});h(this,le,r=>{const n={messageId:-1,command:R.ERROR};t(this,$).call(this,n,r)});h(this,he,r=>{const n={messageId:-1,command:R.LOG};t(this,$).call(this,n,r)});h(this,Pe,()=>{const r=t(this,B).get(t(this,F));return r?r.tokenResponse.access_token:null});h(this,Ue,()=>{if(L){const r=t(this,B).get(t(this,F));return r?r.brokerCookie:null}else return null});h(this,De,(r,n)=>{const o={messageId:-1,command:R.UPDATE_INSTRUMENT};t(this,$).call(this,o,{instrumentName:r,telemetry:n})});M(this,"SetupListener",()=>{t(this,Z).onmessage=async r=>{const n=r.data;switch(v(`STSOAuth2Worker:SetupListener:onmessage: [${n.command}]`),n.command){case R.RESTORE_SESSION:t(this,$).call(this,n,await t(this,Me).call(this));break;case R.AUTHORIZE:t(this,$).call(this,n,await t(this,Le).call(this));break;case R.HANDLE_REDIRECT:t(this,$).call(this,n,await t(this,be).call(this,n.payload));break;case R.LOGOUT:t(this,$).call(this,n,await t(this,Ce).call(this));break;case R.ACCESS_TOKEN:t(this,$).call(this,n,await t(this,Pe).call(this));break;case R.EXECUTE_REFRESH_TOKEN:t(this,$).call(this,n,await t(this,de).call(this));break;case R.COOKIES:t(this,$).call(this,n,await t(this,Ue).call(this));break;default:throw new Error(`Command: [${n.command}'] not found.`)}}});h(this,$,async(r,n)=>{const o={messageId:r.messageId,command:r.command,payload:n};t(this,Z).postMessage(o)});h(this,Me,async()=>{let r=null;const n=t(this,B).get(t(this,F));if(n)r=n.tokenResponse,console.log("Session restored from client storage."),t(this,he).call(this,"Session restored from client storage.");else{const o=`${t(this,u).brokerendpoint}:${t(this,u).brokerport}${t(this,u).brokerapiroot}/session`;console.log("RestoreSession"),console.log(o),t(this,he).call(this,"RestoreSession."),t(this,he).call(this,o);try{const a={method:"post",url:o,data:{[G.OAuth2ParameterType.CLIENT_ID]:t(this,u).client_id,[G.OAuth2ParameterType.SCOPE]:t(this,u).scope,[G.OAuth2ParameterType.REDIRECT_URI]:t(this,u).redirect_uri,[G.OAuth2ParameterType.AUDIENCE]:t(this,u).audience},withCredentials:!0,timeout:t(this,u).timeout};v(`#RestoreSession:session request detail: [${JSON.stringify(a)}]`.magenta),L&&(a.httpsAgent=t(this,ee));const i=await Be(a);if(i.data.status===oe.OK)if(r=i.data.detail,r){const p={tokenResponse:r};L&&(p.brokerCookie=i.headers["set-cookie"]),t(this,B).set(t(this,F),p),console.log("Session restored from server side cookie.")}else console.log("Could not restore previous session. No restoredSessionData available."),console.log(JSON.stringify(i.data));else console.log("Could not restore previous session:-"),console.log(JSON.stringify(i.data))}catch(a){console.log("Could not restore previous session (error state):-"),console.log(a),console.log(JSON.stringify(a))}}return r!==null?(t(this,Q).call(this,r.id_token),console.log("Refreshing tokens ..."),await t(this,de).call(this)):(t(this,Q).call(this,null),!1)});h(this,Le,async()=>{console.log("Authorize ...");const r=t(this,u).client_id,n=t(this,X).CreateRandomString(),o=[Ge.CODE],a=t(this,u).redirect_uri,i=ze.QUERY,p=t(this,u).scope,S=t(this,X).CreateRandomString(),m=t(this,X).CreateRandomString(),I=await t(this,X).DigestMessage(m),d={client_id:r,nonce:n,response_type:o,redirect_uri:a,response_mode:i,scope:p,state:S,code_challenge:I,code_challenge_method:"S256"},A={...d},g=`${t(this,u).authorizeendpoint}:${t(this,u).authorizeport}${t(this,u).authorizeapiroot}${t(this,u).authorizeapi}?${t(this,ke).CreateQueryParams(d)}`;return console.log(g),d.code_verifier=m,console.log(`Authorize:authorizeOptions: [${JSON.stringify(d)}]`),{url:g,authorizeOptions:d,authorizeOptionsClientCopy:A}});h(this,be,async r=>{const n=r.queryVars,o=r.authorizeOptions;if(v("#HandleRedirect: HandleRedirect".magenta),v(`#HandleRedirect: HandleRedirect:Query Vars: [${JSON.stringify(n)}]`.magenta),n[G.OAuth2ParameterType.CODE]){const a=n;console.log(`authorizeOptions from transaction state: [${JSON.stringify(o)}]`);const i=a.state,p=o.state;return p.localeCompare(i)===0?(console.log("redirected state (from queryVars) matched previously saved transaction authorizeOptions state"),await t(this,He).call(this,o,a)):(console.log("redirected state (from queryVars) did NOT match previously saved transaction authorizeOptions state"),console.log(`authorizeOptionsState: [${p}]`),console.log(`redirectState: [${i}]`),t(this,le).call(this,{message:"State un-matched"}),!1)}else return n[G.OAuth2ParameterType.ERROR]?(t(this,le).call(this,{message:"State un-matched"}),!1):(t(this,le).call(this,{message:"State un-matched"}),!1)});h(this,Te,async r=>{v("#GetTokenFromBroker".magenta),t(this,B).remove(t(this,F));const n=`${t(this,u).brokerendpoint}:${t(this,u).brokerport}${t(this,u).brokerapiroot}/token`;try{const o={method:"post",url:n,data:r,withCredentials:!0,timeout:t(this,u).timeout};v(`#GetTokenFromBroker: request config: [${JSON.stringify(o)}]`.magenta),L&&(o.httpsAgent=t(this,ee)),v("#GetTokenFromBroker: axios API call".magenta);const a=await Be(o);if(v(`#GetTokenFromBroker: axios API call result: [${a.status}]`.magenta),a.status===oe.OK){v("#GetTokenFromBroker: storing tokens".magenta);const i=a.data;t(this,Q).call(this,i.id_token);const p={tokenResponse:i};return L&&(p.brokerCookie=a.headers["set-cookie"]),t(this,B).set(t(this,F),p),!0}else return a.status===oe.UNAUTHORIZED?(v(`#GetTokenFromBroker: NOT storing tokens, status: [${a.status}]`.magenta),t(this,Q).call(this,null),!1):(v(`#GetTokenFromBroker: NOT storing tokens (general error 1), status: [${a.status}]`.magenta),t(this,Q).call(this,null),console.log("Could not obtain access_token from token end-point:-"),console.log(JSON.stringify(a.data)),!1)}catch(o){return v(`#GetTokenFromBroker: NOT storing tokens (general error 2), status: [${o}]`.red),t(this,Q).call(this,null),!1}});h(this,He,async(r,n)=>{console.log("#GetToken"),console.log(n),t(this,B).remove(t(this,F));const o={client_id:t(this,u).client_id,scope:t(this,u).scope,code:n.code,redirect_uri:t(this,u).redirect_uri,grant_type:Re.AUTHORIZATION_CODE,code_verifier:r.code_verifier};return await t(this,Te).call(this,o)});h(this,de,async()=>{v("STSOAuth2Worker:#RefreshToken:start".cyan);const r=t(this,B).get(t(this,F));if(r){v(`STSOAuth2Worker:#RefreshToken:sessionData: [${JSON.stringify(r)}]`.cyan);const n=r.tokenResponse,o={client_id:t(this,u).client_id,scope:t(this,u).scope,refresh_token:n.refresh_token,grant_type:Re.REFRESH_TOKEN};return await t(this,Te).call(this,o)}else return v("STSOAuth2Worker:#RefreshToken:sessionData not found within clientSessionStore".red),!1});h(this,Ce,async()=>{console.log("Logout");const r=`${t(this,u).brokerendpoint}:${t(this,u).brokerport}${t(this,u).brokerapiroot}/logout`;console.log(r);const n=t(this,B).get(t(this,F));if(n){const a=n.tokenResponse.refresh_token;console.log(a);const i=tt(a);console.log(i);const p=i.sts_session;console.log(p),t(this,B).remove(t(this,F)),t(this,Q).call(this,null);try{const S={method:"post",url:r,data:{sessionId:p},withCredentials:!0,timeout:t(this,u).timeout};v(`#Logout: request config: [${S}]`.magenta),L&&(S.httpsAgent=t(this,ee));const m=await Be(S);return m.data.status===oe.OK?!0:(console.log("Error during logout (1: server side)"),console.log(JSON.stringify(m.data)),!1)}catch(S){return console.log("Error during logout (2: server side)"),console.log(S),console.log(JSON.stringify(S)),!1}}else return console.log("Error during logout. Could not restore session from session storage."),!1});y.enable("proc:*"),D(this,u,n),v(`STSOAuth2Worker:constructor:#options: [${JSON.stringify(t(this,u))}]`),D(this,B,new re.ClientStorageFactory({clientStorageType:re.ClientStorageType.MEMORY_STORAGE,usePrefix:!1}).GetStorage()),D(this,Z,r),v(`STSOAuth2Worker:constructor:#oauthWorkerPort: [${JSON.stringify(t(this,Z))}]`),L&&t(this,u).agentOptions&&D(this,ee,new at.Agent({keepAlive:t(this,u).agentOptions.keepAlive,maxSockets:t(this,u).agentOptions.maxSockets,maxTotalSockets:t(this,u).agentOptions.maxTotalSockets,maxFreeSockets:t(this,u).agentOptions.maxFreeSockets,timeout:t(this,u).timeout,rejectUnauthorized:t(this,u).agentOptions.rejectUnauthorized})),this.SetupListener(),t(this,De).call(this,ct.Gauge.LOGGER,{LogMessage:"STSOauth2 Plugin - Successfully Loaded"})}}B=new WeakMap,X=new WeakMap,ke=new WeakMap,F=new WeakMap,Z=new WeakMap,u=new WeakMap,ee=new WeakMap,Q=new WeakMap,le=new WeakMap,he=new WeakMap,Pe=new WeakMap,Ue=new WeakMap,De=new WeakMap,$=new WeakMap,Me=new WeakMap,Le=new WeakMap,be=new WeakMap,Te=new WeakMap,He=new WeakMap,de=new WeakMap,Ce=new WeakMap;const _t=qe.defineStore("__sts__TestStore",{state:()=>({count:0}),actions:{UpdateCount(){this.count++}},getters:{CountXX:e=>e.count*2}}),Rt=()=>O.inject(Ee),mt={install:(e,r)=>{const n=new nt(e,r);e.config.globalProperties.$sts||(e.config.globalProperties.$sts={}),e.config.globalProperties.$sts[Ee]=n,e.provide(Ee,n)}};l.AuthorizeOptionsResponseMode=ze,l.AuthorizeOptionsResponseType=Ge,l.IOauth2ListenerCommand=R,l.OAuthGrantTypes=Re,l.STSOAuth2Manager=nt,l.STSOAuth2ManagerPlugin=mt,l.STSOAuth2ManagerPluginKey=Ee,l.STSOAuth2Worker=Ot,l.STSOauth2Store=rt,l.TestStore=_t,l.useSTSOAuth2ManagerPlugin=Rt,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(global2, factory) {
|
|
2
|
+
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("vue"), require("debug"), require("node:worker_threads"), require("@nsshunt/stsutils"), require("@nsshunt/stsvueutils"), require("pinia"), require("@nsshunt/stspublisherserver"), require("node:https"), require("colors"), require("axios"), require("@nsshunt/stsinstrumentation")) : typeof define === "function" && define.amd ? define(["exports", "vue", "debug", "node:worker_threads", "@nsshunt/stsutils", "@nsshunt/stsvueutils", "pinia", "@nsshunt/stspublisherserver", "node:https", "colors", "axios", "@nsshunt/stsinstrumentation"], factory) : (global2 = typeof globalThis !== "undefined" ? globalThis : global2 || self, factory(global2["@nsshunt/stsoauth2plugin"] = {}, global2.vue, global2.debug, global2.worker_threads, global2.stsutils, global2.stsvueutils, global2.pinia, global2.stspublisherserver, global2.https, null, global2.axios, global2.stsinstrumentation));
|
|
3
|
+
})(this, function(exports2, vue, Debug, wt, stsutils, stsvueutils, pinia, stspublisherserver, https, colors, axios, stsinstrumentation) {
|
|
4
|
+
var _crypto, _router, _cUtils, _qParams, _STORAGE_AUTHORIZE_OPTIONS_KEY, _STORAGE_SESSION_KEY, _aic, _options, _messages, _oauth2ManagerPort, _messageId, _messageHandlers, _messageTimeout, _worker, _transactionStore, _operationSemaphore, _maxSemaphoreRetries, _semaphoreRetrySleep, _ProcessMessageResponse, _PostMessage, _HandleLogEvent, _HandleUpdateInstrumentEvent, _GetStore, _HandleErrorEvent, _HandleAuthenticateEvent, _SetupRoute, _clientSessionStore, _cUtils2, _qParams2, _STORAGE_SESSION_KEY2, _oauthWorkerPort, _options2, _httpsAgent, _HandleAuthenticateEvent2, _HandleErrorEvent2, _LogMessage, _GetAccessToken, _GetCookies, _UpdateInstrument, _ProcessCommand, _RestoreSession, _Authorize, _HandleRedirect, _GetTokenFromBroker, _GetToken, _RefreshToken, _Logout;
|
|
5
|
+
"use strict";var __defProp = Object.defineProperty;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __publicField = (obj, key, value) => {
|
|
8
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
9
|
+
return value;
|
|
10
|
+
};
|
|
11
|
+
var __accessCheck = (obj, member, msg) => {
|
|
12
|
+
if (!member.has(obj))
|
|
13
|
+
throw TypeError("Cannot " + msg);
|
|
14
|
+
};
|
|
15
|
+
var __privateGet = (obj, member, getter) => {
|
|
16
|
+
__accessCheck(obj, member, "read from private field");
|
|
17
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
18
|
+
};
|
|
19
|
+
var __privateAdd = (obj, member, value) => {
|
|
20
|
+
if (member.has(obj))
|
|
21
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
22
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
23
|
+
};
|
|
24
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
25
|
+
__accessCheck(obj, member, "write to private field");
|
|
26
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
27
|
+
return value;
|
|
28
|
+
};
|
|
29
|
+
var __privateWrapper = (obj, member, setter, getter) => ({
|
|
30
|
+
set _(value) {
|
|
31
|
+
__privateSet(obj, member, value, setter);
|
|
32
|
+
},
|
|
33
|
+
get _() {
|
|
34
|
+
return __privateGet(obj, member, getter);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
function _interopNamespaceDefault(e2) {
|
|
39
|
+
const n2 = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
40
|
+
if (e2) {
|
|
41
|
+
for (const k in e2) {
|
|
42
|
+
if (k !== "default") {
|
|
43
|
+
const d = Object.getOwnPropertyDescriptor(e2, k);
|
|
44
|
+
Object.defineProperty(n2, k, d.get ? d : {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
get: () => e2[k]
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
n2.default = e2;
|
|
52
|
+
return Object.freeze(n2);
|
|
53
|
+
}
|
|
54
|
+
const wt__namespace = /* @__PURE__ */ _interopNamespaceDefault(wt);
|
|
55
|
+
const STSOAuth2ManagerPluginKey = Symbol();
|
|
56
|
+
const isNode = Object.prototype.toString.call(typeof process !== "undefined" ? process : 0) === "[object process]";
|
|
57
|
+
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
58
|
+
function getAugmentedNamespace(n2) {
|
|
59
|
+
if (n2.__esModule)
|
|
60
|
+
return n2;
|
|
61
|
+
var f = n2.default;
|
|
62
|
+
if (typeof f == "function") {
|
|
63
|
+
var a = function a2() {
|
|
64
|
+
if (this instanceof a2) {
|
|
65
|
+
var args = [null];
|
|
66
|
+
args.push.apply(args, arguments);
|
|
67
|
+
var Ctor = Function.bind.apply(f, args);
|
|
68
|
+
return new Ctor();
|
|
69
|
+
}
|
|
70
|
+
return f.apply(this, arguments);
|
|
71
|
+
};
|
|
72
|
+
a.prototype = f.prototype;
|
|
73
|
+
} else
|
|
74
|
+
a = {};
|
|
75
|
+
Object.defineProperty(a, "__esModule", { value: true });
|
|
76
|
+
Object.keys(n2).forEach(function(k) {
|
|
77
|
+
var d = Object.getOwnPropertyDescriptor(n2, k);
|
|
78
|
+
Object.defineProperty(a, k, d.get ? d : {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function() {
|
|
81
|
+
return n2[k];
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
return a;
|
|
86
|
+
}
|
|
87
|
+
var sha256Exports = {};
|
|
88
|
+
var sha256 = {
|
|
89
|
+
get exports() {
|
|
90
|
+
return sha256Exports;
|
|
91
|
+
},
|
|
92
|
+
set exports(v) {
|
|
93
|
+
sha256Exports = v;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
function commonjsRequire(path) {
|
|
97
|
+
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
|
|
98
|
+
}
|
|
99
|
+
var coreExports = {};
|
|
100
|
+
var core = {
|
|
101
|
+
get exports() {
|
|
102
|
+
return coreExports;
|
|
103
|
+
},
|
|
104
|
+
set exports(v) {
|
|
105
|
+
coreExports = v;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
const __viteBrowserExternal = {};
|
|
109
|
+
const __viteBrowserExternal$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
110
|
+
__proto__: null,
|
|
111
|
+
default: __viteBrowserExternal
|
|
112
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
113
|
+
const require$$0 = /* @__PURE__ */ getAugmentedNamespace(__viteBrowserExternal$1);
|
|
114
|
+
var hasRequiredCore;
|
|
115
|
+
function requireCore() {
|
|
116
|
+
if (hasRequiredCore)
|
|
117
|
+
return coreExports;
|
|
118
|
+
hasRequiredCore = 1;
|
|
119
|
+
(function(module2, exports3) {
|
|
120
|
+
(function(root, factory) {
|
|
121
|
+
{
|
|
122
|
+
module2.exports = factory();
|
|
123
|
+
}
|
|
124
|
+
})(commonjsGlobal, function() {
|
|
125
|
+
var CryptoJS = CryptoJS || function(Math2, undefined$1) {
|
|
126
|
+
var crypto2;
|
|
127
|
+
if (typeof window !== "undefined" && window.crypto) {
|
|
128
|
+
crypto2 = window.crypto;
|
|
129
|
+
}
|
|
130
|
+
if (typeof self !== "undefined" && self.crypto) {
|
|
131
|
+
crypto2 = self.crypto;
|
|
132
|
+
}
|
|
133
|
+
if (typeof globalThis !== "undefined" && globalThis.crypto) {
|
|
134
|
+
crypto2 = globalThis.crypto;
|
|
135
|
+
}
|
|
136
|
+
if (!crypto2 && typeof window !== "undefined" && window.msCrypto) {
|
|
137
|
+
crypto2 = window.msCrypto;
|
|
138
|
+
}
|
|
139
|
+
if (!crypto2 && typeof commonjsGlobal !== "undefined" && commonjsGlobal.crypto) {
|
|
140
|
+
crypto2 = commonjsGlobal.crypto;
|
|
141
|
+
}
|
|
142
|
+
if (!crypto2 && typeof commonjsRequire === "function") {
|
|
143
|
+
try {
|
|
144
|
+
crypto2 = require$$0;
|
|
145
|
+
} catch (err) {
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
var cryptoSecureRandomInt = function() {
|
|
149
|
+
if (crypto2) {
|
|
150
|
+
if (typeof crypto2.getRandomValues === "function") {
|
|
151
|
+
try {
|
|
152
|
+
return crypto2.getRandomValues(new Uint32Array(1))[0];
|
|
153
|
+
} catch (err) {
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (typeof crypto2.randomBytes === "function") {
|
|
157
|
+
try {
|
|
158
|
+
return crypto2.randomBytes(4).readInt32LE();
|
|
159
|
+
} catch (err) {
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
throw new Error("Native crypto module could not be used to get secure random number.");
|
|
164
|
+
};
|
|
165
|
+
var create = Object.create || function() {
|
|
166
|
+
function F() {
|
|
167
|
+
}
|
|
168
|
+
return function(obj) {
|
|
169
|
+
var subtype;
|
|
170
|
+
F.prototype = obj;
|
|
171
|
+
subtype = new F();
|
|
172
|
+
F.prototype = null;
|
|
173
|
+
return subtype;
|
|
174
|
+
};
|
|
175
|
+
}();
|
|
176
|
+
var C = {};
|
|
177
|
+
var C_lib = C.lib = {};
|
|
178
|
+
var Base = C_lib.Base = function() {
|
|
179
|
+
return {
|
|
180
|
+
/**
|
|
181
|
+
* Creates a new object that inherits from this object.
|
|
182
|
+
*
|
|
183
|
+
* @param {Object} overrides Properties to copy into the new object.
|
|
184
|
+
*
|
|
185
|
+
* @return {Object} The new object.
|
|
186
|
+
*
|
|
187
|
+
* @static
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
*
|
|
191
|
+
* var MyType = CryptoJS.lib.Base.extend({
|
|
192
|
+
* field: 'value',
|
|
193
|
+
*
|
|
194
|
+
* method: function () {
|
|
195
|
+
* }
|
|
196
|
+
* });
|
|
197
|
+
*/
|
|
198
|
+
extend: function(overrides) {
|
|
199
|
+
var subtype = create(this);
|
|
200
|
+
if (overrides) {
|
|
201
|
+
subtype.mixIn(overrides);
|
|
202
|
+
}
|
|
203
|
+
if (!subtype.hasOwnProperty("init") || this.init === subtype.init) {
|
|
204
|
+
subtype.init = function() {
|
|
205
|
+
subtype.$super.init.apply(this, arguments);
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
subtype.init.prototype = subtype;
|
|
209
|
+
subtype.$super = this;
|
|
210
|
+
return subtype;
|
|
211
|
+
},
|
|
212
|
+
/**
|
|
213
|
+
* Extends this object and runs the init method.
|
|
214
|
+
* Arguments to create() will be passed to init().
|
|
215
|
+
*
|
|
216
|
+
* @return {Object} The new object.
|
|
217
|
+
*
|
|
218
|
+
* @static
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
*
|
|
222
|
+
* var instance = MyType.create();
|
|
223
|
+
*/
|
|
224
|
+
create: function() {
|
|
225
|
+
var instance = this.extend();
|
|
226
|
+
instance.init.apply(instance, arguments);
|
|
227
|
+
return instance;
|
|
228
|
+
},
|
|
229
|
+
/**
|
|
230
|
+
* Initializes a newly created object.
|
|
231
|
+
* Override this method to add some logic when your objects are created.
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
*
|
|
235
|
+
* var MyType = CryptoJS.lib.Base.extend({
|
|
236
|
+
* init: function () {
|
|
237
|
+
* // ...
|
|
238
|
+
* }
|
|
239
|
+
* });
|
|
240
|
+
*/
|
|
241
|
+
init: function() {
|
|
242
|
+
},
|
|
243
|
+
/**
|
|
244
|
+
* Copies properties into this object.
|
|
245
|
+
*
|
|
246
|
+
* @param {Object} properties The properties to mix in.
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
*
|
|
250
|
+
* MyType.mixIn({
|
|
251
|
+
* field: 'value'
|
|
252
|
+
* });
|
|
253
|
+
*/
|
|
254
|
+
mixIn: function(properties) {
|
|
255
|
+
for (var propertyName in properties) {
|
|
256
|
+
if (properties.hasOwnProperty(propertyName)) {
|
|
257
|
+
this[propertyName] = properties[propertyName];
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
if (properties.hasOwnProperty("toString")) {
|
|
261
|
+
this.toString = properties.toString;
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
/**
|
|
265
|
+
* Creates a copy of this object.
|
|
266
|
+
*
|
|
267
|
+
* @return {Object} The clone.
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
*
|
|
271
|
+
* var clone = instance.clone();
|
|
272
|
+
*/
|
|
273
|
+
clone: function() {
|
|
274
|
+
return this.init.prototype.extend(this);
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
}();
|
|
278
|
+
var WordArray = C_lib.WordArray = Base.extend({
|
|
279
|
+
/**
|
|
280
|
+
* Initializes a newly created word array.
|
|
281
|
+
*
|
|
282
|
+
* @param {Array} words (Optional) An array of 32-bit words.
|
|
283
|
+
* @param {number} sigBytes (Optional) The number of significant bytes in the words.
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
*
|
|
287
|
+
* var wordArray = CryptoJS.lib.WordArray.create();
|
|
288
|
+
* var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]);
|
|
289
|
+
* var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6);
|
|
290
|
+
*/
|
|
291
|
+
init: function(words, sigBytes) {
|
|
292
|
+
words = this.words = words || [];
|
|
293
|
+
if (sigBytes != undefined$1) {
|
|
294
|
+
this.sigBytes = sigBytes;
|
|
295
|
+
} else {
|
|
296
|
+
this.sigBytes = words.length * 4;
|
|
297
|
+
}
|
|
298
|
+
},
|
|
299
|
+
/**
|
|
300
|
+
* Converts this word array to a string.
|
|
301
|
+
*
|
|
302
|
+
* @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex
|
|
303
|
+
*
|
|
304
|
+
* @return {string} The stringified word array.
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
*
|
|
308
|
+
* var string = wordArray + '';
|
|
309
|
+
* var string = wordArray.toString();
|
|
310
|
+
* var string = wordArray.toString(CryptoJS.enc.Utf8);
|
|
311
|
+
*/
|
|
312
|
+
toString: function(encoder) {
|
|
313
|
+
return (encoder || Hex).stringify(this);
|
|
314
|
+
},
|
|
315
|
+
/**
|
|
316
|
+
* Concatenates a word array to this word array.
|
|
317
|
+
*
|
|
318
|
+
* @param {WordArray} wordArray The word array to append.
|
|
319
|
+
*
|
|
320
|
+
* @return {WordArray} This word array.
|
|
321
|
+
*
|
|
322
|
+
* @example
|
|
323
|
+
*
|
|
324
|
+
* wordArray1.concat(wordArray2);
|
|
325
|
+
*/
|
|
326
|
+
concat: function(wordArray) {
|
|
327
|
+
var thisWords = this.words;
|
|
328
|
+
var thatWords = wordArray.words;
|
|
329
|
+
var thisSigBytes = this.sigBytes;
|
|
330
|
+
var thatSigBytes = wordArray.sigBytes;
|
|
331
|
+
this.clamp();
|
|
332
|
+
if (thisSigBytes % 4) {
|
|
333
|
+
for (var i = 0; i < thatSigBytes; i++) {
|
|
334
|
+
var thatByte = thatWords[i >>> 2] >>> 24 - i % 4 * 8 & 255;
|
|
335
|
+
thisWords[thisSigBytes + i >>> 2] |= thatByte << 24 - (thisSigBytes + i) % 4 * 8;
|
|
336
|
+
}
|
|
337
|
+
} else {
|
|
338
|
+
for (var j = 0; j < thatSigBytes; j += 4) {
|
|
339
|
+
thisWords[thisSigBytes + j >>> 2] = thatWords[j >>> 2];
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
this.sigBytes += thatSigBytes;
|
|
343
|
+
return this;
|
|
344
|
+
},
|
|
345
|
+
/**
|
|
346
|
+
* Removes insignificant bits.
|
|
347
|
+
*
|
|
348
|
+
* @example
|
|
349
|
+
*
|
|
350
|
+
* wordArray.clamp();
|
|
351
|
+
*/
|
|
352
|
+
clamp: function() {
|
|
353
|
+
var words = this.words;
|
|
354
|
+
var sigBytes = this.sigBytes;
|
|
355
|
+
words[sigBytes >>> 2] &= 4294967295 << 32 - sigBytes % 4 * 8;
|
|
356
|
+
words.length = Math2.ceil(sigBytes / 4);
|
|
357
|
+
},
|
|
358
|
+
/**
|
|
359
|
+
* Creates a copy of this word array.
|
|
360
|
+
*
|
|
361
|
+
* @return {WordArray} The clone.
|
|
362
|
+
*
|
|
363
|
+
* @example
|
|
364
|
+
*
|
|
365
|
+
* var clone = wordArray.clone();
|
|
366
|
+
*/
|
|
367
|
+
clone: function() {
|
|
368
|
+
var clone = Base.clone.call(this);
|
|
369
|
+
clone.words = this.words.slice(0);
|
|
370
|
+
return clone;
|
|
371
|
+
},
|
|
372
|
+
/**
|
|
373
|
+
* Creates a word array filled with random bytes.
|
|
374
|
+
*
|
|
375
|
+
* @param {number} nBytes The number of random bytes to generate.
|
|
376
|
+
*
|
|
377
|
+
* @return {WordArray} The random word array.
|
|
378
|
+
*
|
|
379
|
+
* @static
|
|
380
|
+
*
|
|
381
|
+
* @example
|
|
382
|
+
*
|
|
383
|
+
* var wordArray = CryptoJS.lib.WordArray.random(16);
|
|
384
|
+
*/
|
|
385
|
+
random: function(nBytes) {
|
|
386
|
+
var words = [];
|
|
387
|
+
for (var i = 0; i < nBytes; i += 4) {
|
|
388
|
+
words.push(cryptoSecureRandomInt());
|
|
389
|
+
}
|
|
390
|
+
return new WordArray.init(words, nBytes);
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
var C_enc = C.enc = {};
|
|
394
|
+
var Hex = C_enc.Hex = {
|
|
395
|
+
/**
|
|
396
|
+
* Converts a word array to a hex string.
|
|
397
|
+
*
|
|
398
|
+
* @param {WordArray} wordArray The word array.
|
|
399
|
+
*
|
|
400
|
+
* @return {string} The hex string.
|
|
401
|
+
*
|
|
402
|
+
* @static
|
|
403
|
+
*
|
|
404
|
+
* @example
|
|
405
|
+
*
|
|
406
|
+
* var hexString = CryptoJS.enc.Hex.stringify(wordArray);
|
|
407
|
+
*/
|
|
408
|
+
stringify: function(wordArray) {
|
|
409
|
+
var words = wordArray.words;
|
|
410
|
+
var sigBytes = wordArray.sigBytes;
|
|
411
|
+
var hexChars = [];
|
|
412
|
+
for (var i = 0; i < sigBytes; i++) {
|
|
413
|
+
var bite = words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
|
|
414
|
+
hexChars.push((bite >>> 4).toString(16));
|
|
415
|
+
hexChars.push((bite & 15).toString(16));
|
|
416
|
+
}
|
|
417
|
+
return hexChars.join("");
|
|
418
|
+
},
|
|
419
|
+
/**
|
|
420
|
+
* Converts a hex string to a word array.
|
|
421
|
+
*
|
|
422
|
+
* @param {string} hexStr The hex string.
|
|
423
|
+
*
|
|
424
|
+
* @return {WordArray} The word array.
|
|
425
|
+
*
|
|
426
|
+
* @static
|
|
427
|
+
*
|
|
428
|
+
* @example
|
|
429
|
+
*
|
|
430
|
+
* var wordArray = CryptoJS.enc.Hex.parse(hexString);
|
|
431
|
+
*/
|
|
432
|
+
parse: function(hexStr) {
|
|
433
|
+
var hexStrLength = hexStr.length;
|
|
434
|
+
var words = [];
|
|
435
|
+
for (var i = 0; i < hexStrLength; i += 2) {
|
|
436
|
+
words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << 24 - i % 8 * 4;
|
|
437
|
+
}
|
|
438
|
+
return new WordArray.init(words, hexStrLength / 2);
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
var Latin1 = C_enc.Latin1 = {
|
|
442
|
+
/**
|
|
443
|
+
* Converts a word array to a Latin1 string.
|
|
444
|
+
*
|
|
445
|
+
* @param {WordArray} wordArray The word array.
|
|
446
|
+
*
|
|
447
|
+
* @return {string} The Latin1 string.
|
|
448
|
+
*
|
|
449
|
+
* @static
|
|
450
|
+
*
|
|
451
|
+
* @example
|
|
452
|
+
*
|
|
453
|
+
* var latin1String = CryptoJS.enc.Latin1.stringify(wordArray);
|
|
454
|
+
*/
|
|
455
|
+
stringify: function(wordArray) {
|
|
456
|
+
var words = wordArray.words;
|
|
457
|
+
var sigBytes = wordArray.sigBytes;
|
|
458
|
+
var latin1Chars = [];
|
|
459
|
+
for (var i = 0; i < sigBytes; i++) {
|
|
460
|
+
var bite = words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
|
|
461
|
+
latin1Chars.push(String.fromCharCode(bite));
|
|
462
|
+
}
|
|
463
|
+
return latin1Chars.join("");
|
|
464
|
+
},
|
|
465
|
+
/**
|
|
466
|
+
* Converts a Latin1 string to a word array.
|
|
467
|
+
*
|
|
468
|
+
* @param {string} latin1Str The Latin1 string.
|
|
469
|
+
*
|
|
470
|
+
* @return {WordArray} The word array.
|
|
471
|
+
*
|
|
472
|
+
* @static
|
|
473
|
+
*
|
|
474
|
+
* @example
|
|
475
|
+
*
|
|
476
|
+
* var wordArray = CryptoJS.enc.Latin1.parse(latin1String);
|
|
477
|
+
*/
|
|
478
|
+
parse: function(latin1Str) {
|
|
479
|
+
var latin1StrLength = latin1Str.length;
|
|
480
|
+
var words = [];
|
|
481
|
+
for (var i = 0; i < latin1StrLength; i++) {
|
|
482
|
+
words[i >>> 2] |= (latin1Str.charCodeAt(i) & 255) << 24 - i % 4 * 8;
|
|
483
|
+
}
|
|
484
|
+
return new WordArray.init(words, latin1StrLength);
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
var Utf8 = C_enc.Utf8 = {
|
|
488
|
+
/**
|
|
489
|
+
* Converts a word array to a UTF-8 string.
|
|
490
|
+
*
|
|
491
|
+
* @param {WordArray} wordArray The word array.
|
|
492
|
+
*
|
|
493
|
+
* @return {string} The UTF-8 string.
|
|
494
|
+
*
|
|
495
|
+
* @static
|
|
496
|
+
*
|
|
497
|
+
* @example
|
|
498
|
+
*
|
|
499
|
+
* var utf8String = CryptoJS.enc.Utf8.stringify(wordArray);
|
|
500
|
+
*/
|
|
501
|
+
stringify: function(wordArray) {
|
|
502
|
+
try {
|
|
503
|
+
return decodeURIComponent(escape(Latin1.stringify(wordArray)));
|
|
504
|
+
} catch (e2) {
|
|
505
|
+
throw new Error("Malformed UTF-8 data");
|
|
506
|
+
}
|
|
507
|
+
},
|
|
508
|
+
/**
|
|
509
|
+
* Converts a UTF-8 string to a word array.
|
|
510
|
+
*
|
|
511
|
+
* @param {string} utf8Str The UTF-8 string.
|
|
512
|
+
*
|
|
513
|
+
* @return {WordArray} The word array.
|
|
514
|
+
*
|
|
515
|
+
* @static
|
|
516
|
+
*
|
|
517
|
+
* @example
|
|
518
|
+
*
|
|
519
|
+
* var wordArray = CryptoJS.enc.Utf8.parse(utf8String);
|
|
520
|
+
*/
|
|
521
|
+
parse: function(utf8Str) {
|
|
522
|
+
return Latin1.parse(unescape(encodeURIComponent(utf8Str)));
|
|
523
|
+
}
|
|
524
|
+
};
|
|
525
|
+
var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({
|
|
526
|
+
/**
|
|
527
|
+
* Resets this block algorithm's data buffer to its initial state.
|
|
528
|
+
*
|
|
529
|
+
* @example
|
|
530
|
+
*
|
|
531
|
+
* bufferedBlockAlgorithm.reset();
|
|
532
|
+
*/
|
|
533
|
+
reset: function() {
|
|
534
|
+
this._data = new WordArray.init();
|
|
535
|
+
this._nDataBytes = 0;
|
|
536
|
+
},
|
|
537
|
+
/**
|
|
538
|
+
* Adds new data to this block algorithm's buffer.
|
|
539
|
+
*
|
|
540
|
+
* @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8.
|
|
541
|
+
*
|
|
542
|
+
* @example
|
|
543
|
+
*
|
|
544
|
+
* bufferedBlockAlgorithm._append('data');
|
|
545
|
+
* bufferedBlockAlgorithm._append(wordArray);
|
|
546
|
+
*/
|
|
547
|
+
_append: function(data) {
|
|
548
|
+
if (typeof data == "string") {
|
|
549
|
+
data = Utf8.parse(data);
|
|
550
|
+
}
|
|
551
|
+
this._data.concat(data);
|
|
552
|
+
this._nDataBytes += data.sigBytes;
|
|
553
|
+
},
|
|
554
|
+
/**
|
|
555
|
+
* Processes available data blocks.
|
|
556
|
+
*
|
|
557
|
+
* This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype.
|
|
558
|
+
*
|
|
559
|
+
* @param {boolean} doFlush Whether all blocks and partial blocks should be processed.
|
|
560
|
+
*
|
|
561
|
+
* @return {WordArray} The processed data.
|
|
562
|
+
*
|
|
563
|
+
* @example
|
|
564
|
+
*
|
|
565
|
+
* var processedData = bufferedBlockAlgorithm._process();
|
|
566
|
+
* var processedData = bufferedBlockAlgorithm._process(!!'flush');
|
|
567
|
+
*/
|
|
568
|
+
_process: function(doFlush) {
|
|
569
|
+
var processedWords;
|
|
570
|
+
var data = this._data;
|
|
571
|
+
var dataWords = data.words;
|
|
572
|
+
var dataSigBytes = data.sigBytes;
|
|
573
|
+
var blockSize = this.blockSize;
|
|
574
|
+
var blockSizeBytes = blockSize * 4;
|
|
575
|
+
var nBlocksReady = dataSigBytes / blockSizeBytes;
|
|
576
|
+
if (doFlush) {
|
|
577
|
+
nBlocksReady = Math2.ceil(nBlocksReady);
|
|
578
|
+
} else {
|
|
579
|
+
nBlocksReady = Math2.max((nBlocksReady | 0) - this._minBufferSize, 0);
|
|
580
|
+
}
|
|
581
|
+
var nWordsReady = nBlocksReady * blockSize;
|
|
582
|
+
var nBytesReady = Math2.min(nWordsReady * 4, dataSigBytes);
|
|
583
|
+
if (nWordsReady) {
|
|
584
|
+
for (var offset = 0; offset < nWordsReady; offset += blockSize) {
|
|
585
|
+
this._doProcessBlock(dataWords, offset);
|
|
586
|
+
}
|
|
587
|
+
processedWords = dataWords.splice(0, nWordsReady);
|
|
588
|
+
data.sigBytes -= nBytesReady;
|
|
589
|
+
}
|
|
590
|
+
return new WordArray.init(processedWords, nBytesReady);
|
|
591
|
+
},
|
|
592
|
+
/**
|
|
593
|
+
* Creates a copy of this object.
|
|
594
|
+
*
|
|
595
|
+
* @return {Object} The clone.
|
|
596
|
+
*
|
|
597
|
+
* @example
|
|
598
|
+
*
|
|
599
|
+
* var clone = bufferedBlockAlgorithm.clone();
|
|
600
|
+
*/
|
|
601
|
+
clone: function() {
|
|
602
|
+
var clone = Base.clone.call(this);
|
|
603
|
+
clone._data = this._data.clone();
|
|
604
|
+
return clone;
|
|
605
|
+
},
|
|
606
|
+
_minBufferSize: 0
|
|
607
|
+
});
|
|
608
|
+
C_lib.Hasher = BufferedBlockAlgorithm.extend({
|
|
609
|
+
/**
|
|
610
|
+
* Configuration options.
|
|
611
|
+
*/
|
|
612
|
+
cfg: Base.extend(),
|
|
613
|
+
/**
|
|
614
|
+
* Initializes a newly created hasher.
|
|
615
|
+
*
|
|
616
|
+
* @param {Object} cfg (Optional) The configuration options to use for this hash computation.
|
|
617
|
+
*
|
|
618
|
+
* @example
|
|
619
|
+
*
|
|
620
|
+
* var hasher = CryptoJS.algo.SHA256.create();
|
|
621
|
+
*/
|
|
622
|
+
init: function(cfg) {
|
|
623
|
+
this.cfg = this.cfg.extend(cfg);
|
|
624
|
+
this.reset();
|
|
625
|
+
},
|
|
626
|
+
/**
|
|
627
|
+
* Resets this hasher to its initial state.
|
|
628
|
+
*
|
|
629
|
+
* @example
|
|
630
|
+
*
|
|
631
|
+
* hasher.reset();
|
|
632
|
+
*/
|
|
633
|
+
reset: function() {
|
|
634
|
+
BufferedBlockAlgorithm.reset.call(this);
|
|
635
|
+
this._doReset();
|
|
636
|
+
},
|
|
637
|
+
/**
|
|
638
|
+
* Updates this hasher with a message.
|
|
639
|
+
*
|
|
640
|
+
* @param {WordArray|string} messageUpdate The message to append.
|
|
641
|
+
*
|
|
642
|
+
* @return {Hasher} This hasher.
|
|
643
|
+
*
|
|
644
|
+
* @example
|
|
645
|
+
*
|
|
646
|
+
* hasher.update('message');
|
|
647
|
+
* hasher.update(wordArray);
|
|
648
|
+
*/
|
|
649
|
+
update: function(messageUpdate) {
|
|
650
|
+
this._append(messageUpdate);
|
|
651
|
+
this._process();
|
|
652
|
+
return this;
|
|
653
|
+
},
|
|
654
|
+
/**
|
|
655
|
+
* Finalizes the hash computation.
|
|
656
|
+
* Note that the finalize operation is effectively a destructive, read-once operation.
|
|
657
|
+
*
|
|
658
|
+
* @param {WordArray|string} messageUpdate (Optional) A final message update.
|
|
659
|
+
*
|
|
660
|
+
* @return {WordArray} The hash.
|
|
661
|
+
*
|
|
662
|
+
* @example
|
|
663
|
+
*
|
|
664
|
+
* var hash = hasher.finalize();
|
|
665
|
+
* var hash = hasher.finalize('message');
|
|
666
|
+
* var hash = hasher.finalize(wordArray);
|
|
667
|
+
*/
|
|
668
|
+
finalize: function(messageUpdate) {
|
|
669
|
+
if (messageUpdate) {
|
|
670
|
+
this._append(messageUpdate);
|
|
671
|
+
}
|
|
672
|
+
var hash = this._doFinalize();
|
|
673
|
+
return hash;
|
|
674
|
+
},
|
|
675
|
+
blockSize: 512 / 32,
|
|
676
|
+
/**
|
|
677
|
+
* Creates a shortcut function to a hasher's object interface.
|
|
678
|
+
*
|
|
679
|
+
* @param {Hasher} hasher The hasher to create a helper for.
|
|
680
|
+
*
|
|
681
|
+
* @return {Function} The shortcut function.
|
|
682
|
+
*
|
|
683
|
+
* @static
|
|
684
|
+
*
|
|
685
|
+
* @example
|
|
686
|
+
*
|
|
687
|
+
* var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256);
|
|
688
|
+
*/
|
|
689
|
+
_createHelper: function(hasher) {
|
|
690
|
+
return function(message, cfg) {
|
|
691
|
+
return new hasher.init(cfg).finalize(message);
|
|
692
|
+
};
|
|
693
|
+
},
|
|
694
|
+
/**
|
|
695
|
+
* Creates a shortcut function to the HMAC's object interface.
|
|
696
|
+
*
|
|
697
|
+
* @param {Hasher} hasher The hasher to use in this HMAC helper.
|
|
698
|
+
*
|
|
699
|
+
* @return {Function} The shortcut function.
|
|
700
|
+
*
|
|
701
|
+
* @static
|
|
702
|
+
*
|
|
703
|
+
* @example
|
|
704
|
+
*
|
|
705
|
+
* var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256);
|
|
706
|
+
*/
|
|
707
|
+
_createHmacHelper: function(hasher) {
|
|
708
|
+
return function(message, key) {
|
|
709
|
+
return new C_algo.HMAC.init(hasher, key).finalize(message);
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
});
|
|
713
|
+
var C_algo = C.algo = {};
|
|
714
|
+
return C;
|
|
715
|
+
}(Math);
|
|
716
|
+
return CryptoJS;
|
|
717
|
+
});
|
|
718
|
+
})(core);
|
|
719
|
+
return coreExports;
|
|
720
|
+
}
|
|
721
|
+
(function(module2, exports3) {
|
|
722
|
+
(function(root, factory) {
|
|
723
|
+
{
|
|
724
|
+
module2.exports = factory(requireCore());
|
|
725
|
+
}
|
|
726
|
+
})(commonjsGlobal, function(CryptoJS) {
|
|
727
|
+
(function(Math2) {
|
|
728
|
+
var C = CryptoJS;
|
|
729
|
+
var C_lib = C.lib;
|
|
730
|
+
var WordArray = C_lib.WordArray;
|
|
731
|
+
var Hasher = C_lib.Hasher;
|
|
732
|
+
var C_algo = C.algo;
|
|
733
|
+
var H = [];
|
|
734
|
+
var K = [];
|
|
735
|
+
(function() {
|
|
736
|
+
function isPrime(n3) {
|
|
737
|
+
var sqrtN = Math2.sqrt(n3);
|
|
738
|
+
for (var factor = 2; factor <= sqrtN; factor++) {
|
|
739
|
+
if (!(n3 % factor)) {
|
|
740
|
+
return false;
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
return true;
|
|
744
|
+
}
|
|
745
|
+
function getFractionalBits(n3) {
|
|
746
|
+
return (n3 - (n3 | 0)) * 4294967296 | 0;
|
|
747
|
+
}
|
|
748
|
+
var n2 = 2;
|
|
749
|
+
var nPrime = 0;
|
|
750
|
+
while (nPrime < 64) {
|
|
751
|
+
if (isPrime(n2)) {
|
|
752
|
+
if (nPrime < 8) {
|
|
753
|
+
H[nPrime] = getFractionalBits(Math2.pow(n2, 1 / 2));
|
|
754
|
+
}
|
|
755
|
+
K[nPrime] = getFractionalBits(Math2.pow(n2, 1 / 3));
|
|
756
|
+
nPrime++;
|
|
757
|
+
}
|
|
758
|
+
n2++;
|
|
759
|
+
}
|
|
760
|
+
})();
|
|
761
|
+
var W = [];
|
|
762
|
+
var SHA256 = C_algo.SHA256 = Hasher.extend({
|
|
763
|
+
_doReset: function() {
|
|
764
|
+
this._hash = new WordArray.init(H.slice(0));
|
|
765
|
+
},
|
|
766
|
+
_doProcessBlock: function(M, offset) {
|
|
767
|
+
var H2 = this._hash.words;
|
|
768
|
+
var a = H2[0];
|
|
769
|
+
var b = H2[1];
|
|
770
|
+
var c = H2[2];
|
|
771
|
+
var d = H2[3];
|
|
772
|
+
var e2 = H2[4];
|
|
773
|
+
var f = H2[5];
|
|
774
|
+
var g = H2[6];
|
|
775
|
+
var h = H2[7];
|
|
776
|
+
for (var i = 0; i < 64; i++) {
|
|
777
|
+
if (i < 16) {
|
|
778
|
+
W[i] = M[offset + i] | 0;
|
|
779
|
+
} else {
|
|
780
|
+
var gamma0x = W[i - 15];
|
|
781
|
+
var gamma0 = (gamma0x << 25 | gamma0x >>> 7) ^ (gamma0x << 14 | gamma0x >>> 18) ^ gamma0x >>> 3;
|
|
782
|
+
var gamma1x = W[i - 2];
|
|
783
|
+
var gamma1 = (gamma1x << 15 | gamma1x >>> 17) ^ (gamma1x << 13 | gamma1x >>> 19) ^ gamma1x >>> 10;
|
|
784
|
+
W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16];
|
|
785
|
+
}
|
|
786
|
+
var ch = e2 & f ^ ~e2 & g;
|
|
787
|
+
var maj = a & b ^ a & c ^ b & c;
|
|
788
|
+
var sigma0 = (a << 30 | a >>> 2) ^ (a << 19 | a >>> 13) ^ (a << 10 | a >>> 22);
|
|
789
|
+
var sigma1 = (e2 << 26 | e2 >>> 6) ^ (e2 << 21 | e2 >>> 11) ^ (e2 << 7 | e2 >>> 25);
|
|
790
|
+
var t1 = h + sigma1 + ch + K[i] + W[i];
|
|
791
|
+
var t2 = sigma0 + maj;
|
|
792
|
+
h = g;
|
|
793
|
+
g = f;
|
|
794
|
+
f = e2;
|
|
795
|
+
e2 = d + t1 | 0;
|
|
796
|
+
d = c;
|
|
797
|
+
c = b;
|
|
798
|
+
b = a;
|
|
799
|
+
a = t1 + t2 | 0;
|
|
800
|
+
}
|
|
801
|
+
H2[0] = H2[0] + a | 0;
|
|
802
|
+
H2[1] = H2[1] + b | 0;
|
|
803
|
+
H2[2] = H2[2] + c | 0;
|
|
804
|
+
H2[3] = H2[3] + d | 0;
|
|
805
|
+
H2[4] = H2[4] + e2 | 0;
|
|
806
|
+
H2[5] = H2[5] + f | 0;
|
|
807
|
+
H2[6] = H2[6] + g | 0;
|
|
808
|
+
H2[7] = H2[7] + h | 0;
|
|
809
|
+
},
|
|
810
|
+
_doFinalize: function() {
|
|
811
|
+
var data = this._data;
|
|
812
|
+
var dataWords = data.words;
|
|
813
|
+
var nBitsTotal = this._nDataBytes * 8;
|
|
814
|
+
var nBitsLeft = data.sigBytes * 8;
|
|
815
|
+
dataWords[nBitsLeft >>> 5] |= 128 << 24 - nBitsLeft % 32;
|
|
816
|
+
dataWords[(nBitsLeft + 64 >>> 9 << 4) + 14] = Math2.floor(nBitsTotal / 4294967296);
|
|
817
|
+
dataWords[(nBitsLeft + 64 >>> 9 << 4) + 15] = nBitsTotal;
|
|
818
|
+
data.sigBytes = dataWords.length * 4;
|
|
819
|
+
this._process();
|
|
820
|
+
return this._hash;
|
|
821
|
+
},
|
|
822
|
+
clone: function() {
|
|
823
|
+
var clone = Hasher.clone.call(this);
|
|
824
|
+
clone._hash = this._hash.clone();
|
|
825
|
+
return clone;
|
|
826
|
+
}
|
|
827
|
+
});
|
|
828
|
+
C.SHA256 = Hasher._createHelper(SHA256);
|
|
829
|
+
C.HmacSHA256 = Hasher._createHmacHelper(SHA256);
|
|
830
|
+
})(Math);
|
|
831
|
+
return CryptoJS.SHA256;
|
|
832
|
+
});
|
|
833
|
+
})(sha256);
|
|
834
|
+
var encBase64Exports = {};
|
|
835
|
+
var encBase64 = {
|
|
836
|
+
get exports() {
|
|
837
|
+
return encBase64Exports;
|
|
838
|
+
},
|
|
839
|
+
set exports(v) {
|
|
840
|
+
encBase64Exports = v;
|
|
841
|
+
}
|
|
842
|
+
};
|
|
843
|
+
(function(module2, exports3) {
|
|
844
|
+
(function(root, factory) {
|
|
845
|
+
{
|
|
846
|
+
module2.exports = factory(requireCore());
|
|
847
|
+
}
|
|
848
|
+
})(commonjsGlobal, function(CryptoJS) {
|
|
849
|
+
(function() {
|
|
850
|
+
var C = CryptoJS;
|
|
851
|
+
var C_lib = C.lib;
|
|
852
|
+
var WordArray = C_lib.WordArray;
|
|
853
|
+
var C_enc = C.enc;
|
|
854
|
+
C_enc.Base64 = {
|
|
855
|
+
/**
|
|
856
|
+
* Converts a word array to a Base64 string.
|
|
857
|
+
*
|
|
858
|
+
* @param {WordArray} wordArray The word array.
|
|
859
|
+
*
|
|
860
|
+
* @return {string} The Base64 string.
|
|
861
|
+
*
|
|
862
|
+
* @static
|
|
863
|
+
*
|
|
864
|
+
* @example
|
|
865
|
+
*
|
|
866
|
+
* var base64String = CryptoJS.enc.Base64.stringify(wordArray);
|
|
867
|
+
*/
|
|
868
|
+
stringify: function(wordArray) {
|
|
869
|
+
var words = wordArray.words;
|
|
870
|
+
var sigBytes = wordArray.sigBytes;
|
|
871
|
+
var map = this._map;
|
|
872
|
+
wordArray.clamp();
|
|
873
|
+
var base64Chars = [];
|
|
874
|
+
for (var i = 0; i < sigBytes; i += 3) {
|
|
875
|
+
var byte1 = words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
|
|
876
|
+
var byte2 = words[i + 1 >>> 2] >>> 24 - (i + 1) % 4 * 8 & 255;
|
|
877
|
+
var byte3 = words[i + 2 >>> 2] >>> 24 - (i + 2) % 4 * 8 & 255;
|
|
878
|
+
var triplet = byte1 << 16 | byte2 << 8 | byte3;
|
|
879
|
+
for (var j = 0; j < 4 && i + j * 0.75 < sigBytes; j++) {
|
|
880
|
+
base64Chars.push(map.charAt(triplet >>> 6 * (3 - j) & 63));
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
var paddingChar = map.charAt(64);
|
|
884
|
+
if (paddingChar) {
|
|
885
|
+
while (base64Chars.length % 4) {
|
|
886
|
+
base64Chars.push(paddingChar);
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
return base64Chars.join("");
|
|
890
|
+
},
|
|
891
|
+
/**
|
|
892
|
+
* Converts a Base64 string to a word array.
|
|
893
|
+
*
|
|
894
|
+
* @param {string} base64Str The Base64 string.
|
|
895
|
+
*
|
|
896
|
+
* @return {WordArray} The word array.
|
|
897
|
+
*
|
|
898
|
+
* @static
|
|
899
|
+
*
|
|
900
|
+
* @example
|
|
901
|
+
*
|
|
902
|
+
* var wordArray = CryptoJS.enc.Base64.parse(base64String);
|
|
903
|
+
*/
|
|
904
|
+
parse: function(base64Str) {
|
|
905
|
+
var base64StrLength = base64Str.length;
|
|
906
|
+
var map = this._map;
|
|
907
|
+
var reverseMap = this._reverseMap;
|
|
908
|
+
if (!reverseMap) {
|
|
909
|
+
reverseMap = this._reverseMap = [];
|
|
910
|
+
for (var j = 0; j < map.length; j++) {
|
|
911
|
+
reverseMap[map.charCodeAt(j)] = j;
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
var paddingChar = map.charAt(64);
|
|
915
|
+
if (paddingChar) {
|
|
916
|
+
var paddingIndex = base64Str.indexOf(paddingChar);
|
|
917
|
+
if (paddingIndex !== -1) {
|
|
918
|
+
base64StrLength = paddingIndex;
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
return parseLoop(base64Str, base64StrLength, reverseMap);
|
|
922
|
+
},
|
|
923
|
+
_map: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
|
|
924
|
+
};
|
|
925
|
+
function parseLoop(base64Str, base64StrLength, reverseMap) {
|
|
926
|
+
var words = [];
|
|
927
|
+
var nBytes = 0;
|
|
928
|
+
for (var i = 0; i < base64StrLength; i++) {
|
|
929
|
+
if (i % 4) {
|
|
930
|
+
var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << i % 4 * 2;
|
|
931
|
+
var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> 6 - i % 4 * 2;
|
|
932
|
+
var bitsCombined = bits1 | bits2;
|
|
933
|
+
words[nBytes >>> 2] |= bitsCombined << 24 - nBytes % 4 * 8;
|
|
934
|
+
nBytes++;
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
return WordArray.create(words, nBytes);
|
|
938
|
+
}
|
|
939
|
+
})();
|
|
940
|
+
return CryptoJS.enc.Base64;
|
|
941
|
+
});
|
|
942
|
+
})(encBase64);
|
|
943
|
+
class CryptoUtils {
|
|
944
|
+
constructor() {
|
|
945
|
+
__privateAdd(this, _crypto, void 0);
|
|
946
|
+
__publicField(this, "DigestMessage", async function(message) {
|
|
947
|
+
const hashDigest = sha256Exports(message);
|
|
948
|
+
return encBase64Exports.stringify(hashDigest);
|
|
949
|
+
});
|
|
950
|
+
__publicField(this, "CreateRandomString", (size = 43) => {
|
|
951
|
+
const randomValues = Array.from(__privateGet(this, _crypto).getRandomValues(new Uint8Array(size)));
|
|
952
|
+
const b64 = btoa(String.fromCharCode(...randomValues));
|
|
953
|
+
return b64;
|
|
954
|
+
});
|
|
955
|
+
try {
|
|
956
|
+
__privateSet(this, _crypto, crypto);
|
|
957
|
+
} catch {
|
|
958
|
+
__privateSet(this, _crypto, require("crypto"));
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
_crypto = new WeakMap();
|
|
963
|
+
class QueryParams {
|
|
964
|
+
constructor() {
|
|
965
|
+
__publicField(this, "DecodeQueryParams", (params) => {
|
|
966
|
+
const retObj = {};
|
|
967
|
+
Object.keys(params).filter((k) => typeof params[k] !== "undefined").map((k) => {
|
|
968
|
+
retObj[decodeURIComponent(k)] = decodeURIComponent(params[k]);
|
|
969
|
+
});
|
|
970
|
+
return retObj;
|
|
971
|
+
});
|
|
972
|
+
__publicField(this, "CreateQueryParams", (params) => {
|
|
973
|
+
return Object.keys(params).filter((k) => typeof params[k] !== "undefined").map((k) => {
|
|
974
|
+
if (Array.isArray(params[k])) {
|
|
975
|
+
return encodeURIComponent(k) + "=" + encodeURIComponent(params[k].join(" "));
|
|
976
|
+
} else {
|
|
977
|
+
return encodeURIComponent(k) + "=" + encodeURIComponent(params[k]);
|
|
978
|
+
}
|
|
979
|
+
}).join("&");
|
|
980
|
+
});
|
|
981
|
+
__publicField(this, "_GetQueryParams", (param) => {
|
|
982
|
+
let retVal = {};
|
|
983
|
+
const uri = param.split("?");
|
|
984
|
+
if (uri.length == 2) {
|
|
985
|
+
const vars = uri[1].split("&");
|
|
986
|
+
const getVars = {};
|
|
987
|
+
let tmp;
|
|
988
|
+
vars.forEach(function(v) {
|
|
989
|
+
tmp = v.split("=");
|
|
990
|
+
if (tmp.length == 2)
|
|
991
|
+
getVars[tmp[0]] = tmp[1];
|
|
992
|
+
});
|
|
993
|
+
retVal = this.DecodeQueryParams(getVars);
|
|
994
|
+
}
|
|
995
|
+
return retVal;
|
|
996
|
+
});
|
|
997
|
+
__publicField(this, "GetQueryParams", () => {
|
|
998
|
+
return this._GetQueryParams(window.location.href);
|
|
999
|
+
});
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
var AuthorizeOptionsResponseType = /* @__PURE__ */ ((AuthorizeOptionsResponseType2) => {
|
|
1003
|
+
AuthorizeOptionsResponseType2["CODE"] = "code";
|
|
1004
|
+
AuthorizeOptionsResponseType2["ID_TOKEN"] = "id_token";
|
|
1005
|
+
AuthorizeOptionsResponseType2["TOKEN"] = "token";
|
|
1006
|
+
return AuthorizeOptionsResponseType2;
|
|
1007
|
+
})(AuthorizeOptionsResponseType || {});
|
|
1008
|
+
var AuthorizeOptionsResponseMode = /* @__PURE__ */ ((AuthorizeOptionsResponseMode2) => {
|
|
1009
|
+
AuthorizeOptionsResponseMode2["QUERY"] = "query";
|
|
1010
|
+
AuthorizeOptionsResponseMode2["FRAGMENT"] = "fragment";
|
|
1011
|
+
AuthorizeOptionsResponseMode2["FORM_POST"] = "form_post";
|
|
1012
|
+
return AuthorizeOptionsResponseMode2;
|
|
1013
|
+
})(AuthorizeOptionsResponseMode || {});
|
|
1014
|
+
var OAuthGrantTypes = /* @__PURE__ */ ((OAuthGrantTypes2) => {
|
|
1015
|
+
OAuthGrantTypes2["CLIENT_CREDENTIALS"] = "client_credentials";
|
|
1016
|
+
OAuthGrantTypes2["AUTHORIZATION_CODE"] = "authorization_code";
|
|
1017
|
+
OAuthGrantTypes2["REFRESH_TOKEN"] = "refresh_token";
|
|
1018
|
+
return OAuthGrantTypes2;
|
|
1019
|
+
})(OAuthGrantTypes || {});
|
|
1020
|
+
var IOauth2ListenerCommand = /* @__PURE__ */ ((IOauth2ListenerCommand2) => {
|
|
1021
|
+
IOauth2ListenerCommand2["RESTORE_SESSION"] = "RestoreSession";
|
|
1022
|
+
IOauth2ListenerCommand2["AUTHORIZE"] = "Authorize";
|
|
1023
|
+
IOauth2ListenerCommand2["HANDLE_REDIRECT"] = "HandleRedirect";
|
|
1024
|
+
IOauth2ListenerCommand2["LOGOUT"] = "Logout";
|
|
1025
|
+
IOauth2ListenerCommand2["AUTHENTICATE_EVENT"] = "AuthenticateEvent";
|
|
1026
|
+
IOauth2ListenerCommand2["ERROR"] = "Error";
|
|
1027
|
+
IOauth2ListenerCommand2["LOG"] = "__LOG";
|
|
1028
|
+
IOauth2ListenerCommand2["UPDATE_INSTRUMENT"] = "__UPDATE_INSTRUMENT";
|
|
1029
|
+
IOauth2ListenerCommand2["ID_TOKEN"] = "__ID_TOKEN";
|
|
1030
|
+
IOauth2ListenerCommand2["ACCESS_TOKEN"] = "__ACCESS_TOKEN";
|
|
1031
|
+
IOauth2ListenerCommand2["COOKIES"] = "__COOKIES";
|
|
1032
|
+
IOauth2ListenerCommand2["EXECUTE_REFRESH_TOKEN"] = "__EXECUTE_REFRESH_TOKEN";
|
|
1033
|
+
return IOauth2ListenerCommand2;
|
|
1034
|
+
})(IOauth2ListenerCommand || {});
|
|
1035
|
+
function e(e2) {
|
|
1036
|
+
this.message = e2;
|
|
1037
|
+
}
|
|
1038
|
+
e.prototype = new Error(), e.prototype.name = "InvalidCharacterError";
|
|
1039
|
+
var r = "undefined" != typeof window && window.atob && window.atob.bind(window) || function(r2) {
|
|
1040
|
+
var t2 = String(r2).replace(/=+$/, "");
|
|
1041
|
+
if (t2.length % 4 == 1)
|
|
1042
|
+
throw new e("'atob' failed: The string to be decoded is not correctly encoded.");
|
|
1043
|
+
for (var n2, o2, a = 0, i = 0, c = ""; o2 = t2.charAt(i++); ~o2 && (n2 = a % 4 ? 64 * n2 + o2 : o2, a++ % 4) ? c += String.fromCharCode(255 & n2 >> (-2 * a & 6)) : 0)
|
|
1044
|
+
o2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o2);
|
|
1045
|
+
return c;
|
|
1046
|
+
};
|
|
1047
|
+
function t(e2) {
|
|
1048
|
+
var t2 = e2.replace(/-/g, "+").replace(/_/g, "/");
|
|
1049
|
+
switch (t2.length % 4) {
|
|
1050
|
+
case 0:
|
|
1051
|
+
break;
|
|
1052
|
+
case 2:
|
|
1053
|
+
t2 += "==";
|
|
1054
|
+
break;
|
|
1055
|
+
case 3:
|
|
1056
|
+
t2 += "=";
|
|
1057
|
+
break;
|
|
1058
|
+
default:
|
|
1059
|
+
throw "Illegal base64url string!";
|
|
1060
|
+
}
|
|
1061
|
+
try {
|
|
1062
|
+
return function(e3) {
|
|
1063
|
+
return decodeURIComponent(r(e3).replace(/(.)/g, function(e4, r2) {
|
|
1064
|
+
var t3 = r2.charCodeAt(0).toString(16).toUpperCase();
|
|
1065
|
+
return t3.length < 2 && (t3 = "0" + t3), "%" + t3;
|
|
1066
|
+
}));
|
|
1067
|
+
}(t2);
|
|
1068
|
+
} catch (e3) {
|
|
1069
|
+
return r(t2);
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
function n(e2) {
|
|
1073
|
+
this.message = e2;
|
|
1074
|
+
}
|
|
1075
|
+
function o(e2, r2) {
|
|
1076
|
+
if ("string" != typeof e2)
|
|
1077
|
+
throw new n("Invalid token specified");
|
|
1078
|
+
var o2 = true === (r2 = r2 || {}).header ? 0 : 1;
|
|
1079
|
+
try {
|
|
1080
|
+
return JSON.parse(t(e2.split(".")[o2]));
|
|
1081
|
+
} catch (e3) {
|
|
1082
|
+
throw new n("Invalid token specified: " + e3.message);
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
n.prototype = new Error(), n.prototype.name = "InvalidTokenError";
|
|
1086
|
+
const STSOauth2Store = pinia.defineStore("__sts__STSOauth2Store", {
|
|
1087
|
+
state: () => {
|
|
1088
|
+
return {
|
|
1089
|
+
id_token: null,
|
|
1090
|
+
error: null
|
|
1091
|
+
};
|
|
1092
|
+
},
|
|
1093
|
+
actions: {
|
|
1094
|
+
UpdateIdToken(id_token) {
|
|
1095
|
+
this.id_token = id_token;
|
|
1096
|
+
},
|
|
1097
|
+
UpdateError(error) {
|
|
1098
|
+
if (this.error) {
|
|
1099
|
+
this.error.message = error;
|
|
1100
|
+
} else {
|
|
1101
|
+
this.error = {
|
|
1102
|
+
message: error
|
|
1103
|
+
};
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
},
|
|
1107
|
+
getters: {
|
|
1108
|
+
LoggedIn: (state) => {
|
|
1109
|
+
if (typeof state.id_token === "undefined") {
|
|
1110
|
+
return false;
|
|
1111
|
+
}
|
|
1112
|
+
if (state.id_token === null) {
|
|
1113
|
+
return false;
|
|
1114
|
+
}
|
|
1115
|
+
return true;
|
|
1116
|
+
},
|
|
1117
|
+
UserDetails: (state) => {
|
|
1118
|
+
if (state.id_token) {
|
|
1119
|
+
const id_token = state.id_token;
|
|
1120
|
+
const decodedIdToken = o(id_token);
|
|
1121
|
+
return decodedIdToken;
|
|
1122
|
+
} else {
|
|
1123
|
+
return null;
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
/*
|
|
1128
|
+
persist: {
|
|
1129
|
+
storage: globalThis.sessionStorage
|
|
1130
|
+
}
|
|
1131
|
+
*/
|
|
1132
|
+
});
|
|
1133
|
+
let debug$1;
|
|
1134
|
+
if (isNode) {
|
|
1135
|
+
debug$1 = Debug(`proc:${process.pid}:stsoauth2manager.ts`);
|
|
1136
|
+
} else {
|
|
1137
|
+
debug$1 = Debug(`proc:0:stsoauth2manager.ts`);
|
|
1138
|
+
}
|
|
1139
|
+
class STSOAuth2Manager {
|
|
1140
|
+
// ms
|
|
1141
|
+
constructor(app, options) {
|
|
1142
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1143
|
+
__privateAdd(this, _router, null);
|
|
1144
|
+
__privateAdd(this, _cUtils, new CryptoUtils());
|
|
1145
|
+
__privateAdd(this, _qParams, new QueryParams());
|
|
1146
|
+
__privateAdd(this, _STORAGE_AUTHORIZE_OPTIONS_KEY, "authorize_options.stsmda.com.au");
|
|
1147
|
+
__privateAdd(this, _STORAGE_SESSION_KEY, "session.stsmda.com.au");
|
|
1148
|
+
__privateAdd(this, _aic, null);
|
|
1149
|
+
__privateAdd(this, _options, void 0);
|
|
1150
|
+
__privateAdd(this, _messages, {});
|
|
1151
|
+
__privateAdd(this, _oauth2ManagerPort, void 0);
|
|
1152
|
+
__privateAdd(this, _messageId, 0);
|
|
1153
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1154
|
+
__privateAdd(this, _messageHandlers, {});
|
|
1155
|
+
// keyed by messageId
|
|
1156
|
+
__privateAdd(this, _messageTimeout, 1e4);
|
|
1157
|
+
__privateAdd(this, _worker, void 0);
|
|
1158
|
+
__privateAdd(this, _transactionStore, void 0);
|
|
1159
|
+
// Transient transaction data used to establish a session via OAuth2 authorize handshake
|
|
1160
|
+
__privateAdd(this, _operationSemaphore, false);
|
|
1161
|
+
__privateAdd(this, _maxSemaphoreRetries, 100);
|
|
1162
|
+
// 100 retries, i.e. allow 100 x 50 = 5000ms to unblock
|
|
1163
|
+
__privateAdd(this, _semaphoreRetrySleep, 50);
|
|
1164
|
+
__privateAdd(this, _ProcessMessageResponse, (data) => {
|
|
1165
|
+
const messageResponse = data;
|
|
1166
|
+
debug$1(`STSOAuth2Manager:#ProcessMessageResponse: message data = [${JSON.stringify(messageResponse)}]`.yellow);
|
|
1167
|
+
if (messageResponse.messageId === -1) {
|
|
1168
|
+
switch (messageResponse.command) {
|
|
1169
|
+
case IOauth2ListenerCommand.AUTHENTICATE_EVENT:
|
|
1170
|
+
__privateGet(this, _HandleAuthenticateEvent).call(this, messageResponse.payload);
|
|
1171
|
+
break;
|
|
1172
|
+
case IOauth2ListenerCommand.ERROR:
|
|
1173
|
+
__privateGet(this, _HandleErrorEvent).call(this, messageResponse.payload);
|
|
1174
|
+
break;
|
|
1175
|
+
case IOauth2ListenerCommand.LOG:
|
|
1176
|
+
__privateGet(this, _HandleLogEvent).call(this, messageResponse.payload);
|
|
1177
|
+
break;
|
|
1178
|
+
case IOauth2ListenerCommand.UPDATE_INSTRUMENT:
|
|
1179
|
+
__privateGet(this, _HandleUpdateInstrumentEvent).call(this, messageResponse.payload.instrumentName, messageResponse.payload.telemetry);
|
|
1180
|
+
break;
|
|
1181
|
+
default:
|
|
1182
|
+
throw new Error(`ProcessMessageResponse command [${messageResponse.command}] not valid.`);
|
|
1183
|
+
}
|
|
1184
|
+
} else {
|
|
1185
|
+
const callBack = __privateGet(this, _messageHandlers)[messageResponse.messageId];
|
|
1186
|
+
if (callBack) {
|
|
1187
|
+
callBack(messageResponse);
|
|
1188
|
+
} else {
|
|
1189
|
+
throw new Error(`Message: [${messageResponse.messageId}] does not exists in callBacks.`);
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
});
|
|
1193
|
+
__privateAdd(this, _PostMessage, (message) => {
|
|
1194
|
+
message.messageId = __privateWrapper(this, _messageId)._++;
|
|
1195
|
+
return new Promise((resolve, reject) => {
|
|
1196
|
+
const timeout = setTimeout(() => {
|
|
1197
|
+
delete __privateGet(this, _messageHandlers)[message.messageId];
|
|
1198
|
+
reject(`Message: [${message.messageId}] timeout error after: [${__privateGet(this, _messageTimeout)}] ms.`);
|
|
1199
|
+
}, __privateGet(this, _messageTimeout));
|
|
1200
|
+
__privateGet(this, _messageHandlers)[message.messageId] = (response) => {
|
|
1201
|
+
clearTimeout(timeout);
|
|
1202
|
+
delete __privateGet(this, _messageHandlers)[message.messageId];
|
|
1203
|
+
debug$1(`STSOAuth2Manager:#PostMessage: resolve callback response= [${JSON.stringify(response)}]`.yellow);
|
|
1204
|
+
resolve(response);
|
|
1205
|
+
};
|
|
1206
|
+
debug$1(`STSOAuth2Manager:#PostMessage: posting message = [${JSON.stringify(message)}]`.yellow);
|
|
1207
|
+
__privateGet(this, _oauth2ManagerPort).postMessage(message);
|
|
1208
|
+
});
|
|
1209
|
+
});
|
|
1210
|
+
__privateAdd(this, _HandleLogEvent, (message) => {
|
|
1211
|
+
if (__privateGet(this, _aic)) {
|
|
1212
|
+
__privateGet(this, _aic).LogEx(message);
|
|
1213
|
+
}
|
|
1214
|
+
debug$1(message);
|
|
1215
|
+
});
|
|
1216
|
+
// UpdateInstrument = (instrumentName: Gauge, telemetry: InstrumentBaseTelemetry): void => {
|
|
1217
|
+
__privateAdd(this, _HandleUpdateInstrumentEvent, (instrumentName, telemetry) => {
|
|
1218
|
+
if (__privateGet(this, _aic)) {
|
|
1219
|
+
__privateGet(this, _aic).UpdateInstrument(instrumentName, telemetry);
|
|
1220
|
+
}
|
|
1221
|
+
});
|
|
1222
|
+
__privateAdd(this, _GetStore, () => {
|
|
1223
|
+
return STSOauth2Store(__privateGet(this, _options).pinia);
|
|
1224
|
+
});
|
|
1225
|
+
// Will come from message channel
|
|
1226
|
+
__privateAdd(this, _HandleErrorEvent, (error) => {
|
|
1227
|
+
if (isNode)
|
|
1228
|
+
;
|
|
1229
|
+
else {
|
|
1230
|
+
__privateGet(this, _GetStore).call(this).UpdateError({
|
|
1231
|
+
// Authorize applications store
|
|
1232
|
+
message: error
|
|
1233
|
+
});
|
|
1234
|
+
setTimeout(() => {
|
|
1235
|
+
__privateGet(this, _router).replace("/error");
|
|
1236
|
+
}, 0);
|
|
1237
|
+
}
|
|
1238
|
+
});
|
|
1239
|
+
__privateAdd(this, _HandleAuthenticateEvent, (id_token) => {
|
|
1240
|
+
if (isNode)
|
|
1241
|
+
;
|
|
1242
|
+
else {
|
|
1243
|
+
if (__privateGet(this, _options).authenticateEvent) {
|
|
1244
|
+
__privateGet(this, _options).authenticateEvent(id_token);
|
|
1245
|
+
}
|
|
1246
|
+
__privateGet(this, _GetStore).call(this).UpdateIdToken(id_token);
|
|
1247
|
+
}
|
|
1248
|
+
});
|
|
1249
|
+
__privateAdd(this, _SetupRoute, (app, router) => {
|
|
1250
|
+
debug$1(`STSOAuth2Manager:#SetupRoute`.gray);
|
|
1251
|
+
router.beforeEach(async (to, from, next) => {
|
|
1252
|
+
const oAuth2Manager = app.config.globalProperties.$sts[STSOAuth2ManagerPluginKey];
|
|
1253
|
+
debug$1(`beforeEach: from: [${from.path}], to: [${to.path}]`.gray);
|
|
1254
|
+
if (__privateGet(this, _GetStore).call(this).LoggedIn === false) {
|
|
1255
|
+
console.log(`Not logged in`);
|
|
1256
|
+
if (to.path.localeCompare("/authorize") === 0) {
|
|
1257
|
+
console.log(`to = /authorize`);
|
|
1258
|
+
next();
|
|
1259
|
+
return;
|
|
1260
|
+
} else if (to.path.localeCompare("/consent") === 0) {
|
|
1261
|
+
if (__privateGet(this, _GetStore).call(this).id_token) {
|
|
1262
|
+
next();
|
|
1263
|
+
return;
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
if (to.path.localeCompare("/logout") === 0) {
|
|
1267
|
+
next();
|
|
1268
|
+
return;
|
|
1269
|
+
}
|
|
1270
|
+
if (to.path.localeCompare("/error") === 0) {
|
|
1271
|
+
next();
|
|
1272
|
+
return;
|
|
1273
|
+
}
|
|
1274
|
+
if (to.path.localeCompare("/config") === 0) {
|
|
1275
|
+
next();
|
|
1276
|
+
return;
|
|
1277
|
+
}
|
|
1278
|
+
if (to.path.localeCompare("/redirected") === 0) {
|
|
1279
|
+
next();
|
|
1280
|
+
return;
|
|
1281
|
+
}
|
|
1282
|
+
const str = to.query;
|
|
1283
|
+
if (str[stsutils.OAuth2ParameterType.CODE] || str[stsutils.OAuth2ParameterType.ERROR]) {
|
|
1284
|
+
debug$1(`STSOAuth2Manager:#SetupRoute:Processing redirect: [${JSON.stringify(str)}]`.magenta);
|
|
1285
|
+
const retVal = await oAuth2Manager.HandleRedirect(str);
|
|
1286
|
+
debug$1(`STSOAuth2Manager:#SetupRoute:Redirect result: [${retVal}]`.magenta);
|
|
1287
|
+
if (retVal) {
|
|
1288
|
+
next({
|
|
1289
|
+
path: "/",
|
|
1290
|
+
replace: true
|
|
1291
|
+
});
|
|
1292
|
+
return;
|
|
1293
|
+
} else {
|
|
1294
|
+
next({
|
|
1295
|
+
path: "/error",
|
|
1296
|
+
replace: true
|
|
1297
|
+
});
|
|
1298
|
+
return;
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
debug$1(`STSOAuth2Manager:#SetupRoute:Restoring session`);
|
|
1302
|
+
const sessionRestored = await oAuth2Manager.RestoreSession();
|
|
1303
|
+
debug$1(`STSOAuth2Manager:#SetupRoute:Session restored: [${sessionRestored}]`);
|
|
1304
|
+
if (sessionRestored !== true) {
|
|
1305
|
+
debug$1(`STSOAuth2Manager:#SetupRoute:Session not restored - need to authorize`);
|
|
1306
|
+
oAuth2Manager.Authorize();
|
|
1307
|
+
next();
|
|
1308
|
+
return;
|
|
1309
|
+
} else {
|
|
1310
|
+
next("/");
|
|
1311
|
+
return;
|
|
1312
|
+
}
|
|
1313
|
+
} else {
|
|
1314
|
+
if (to.path.localeCompare("/consent") === 0) {
|
|
1315
|
+
next("/");
|
|
1316
|
+
return;
|
|
1317
|
+
}
|
|
1318
|
+
if (to.path.localeCompare("/authorize") === 0) {
|
|
1319
|
+
next("/");
|
|
1320
|
+
return;
|
|
1321
|
+
}
|
|
1322
|
+
if (to.path.localeCompare("/logout") === 0) {
|
|
1323
|
+
next("/");
|
|
1324
|
+
return;
|
|
1325
|
+
}
|
|
1326
|
+
next();
|
|
1327
|
+
}
|
|
1328
|
+
});
|
|
1329
|
+
});
|
|
1330
|
+
//@@ this needs to be re-implemented so that access_token never leaves the auth worker
|
|
1331
|
+
__publicField(this, "GetAccessToken", async () => {
|
|
1332
|
+
const response = await __privateGet(this, _PostMessage).call(this, { command: IOauth2ListenerCommand.ACCESS_TOKEN });
|
|
1333
|
+
return response.payload;
|
|
1334
|
+
});
|
|
1335
|
+
// Update operation protected using operationSemaphore. This may occur when using workers and/or multiple async fetch operations.
|
|
1336
|
+
__publicField(this, "ExecuteRefreshToken", async (retryCount = 0) => {
|
|
1337
|
+
if (__privateGet(this, _operationSemaphore) === true) {
|
|
1338
|
+
if (retryCount > __privateGet(this, _maxSemaphoreRetries)) {
|
|
1339
|
+
throw new Error(`STSOAuth2Manager:ExecuteRefreshToken:maxSemaphoreRetries: [${__privateGet(this, _maxSemaphoreRetries)}] exceeded.`);
|
|
1340
|
+
}
|
|
1341
|
+
await stsutils.Sleep(__privateGet(this, _semaphoreRetrySleep));
|
|
1342
|
+
debug$1(`STSOAuth2Manager:ExecuteRefreshToken:locked by operationSemaphore, retry count: [${retryCount}]`.cyan);
|
|
1343
|
+
return await this.ExecuteRefreshToken(retryCount + 1);
|
|
1344
|
+
} else {
|
|
1345
|
+
__privateSet(this, _operationSemaphore, true);
|
|
1346
|
+
const response = await __privateGet(this, _PostMessage).call(this, { command: IOauth2ListenerCommand.EXECUTE_REFRESH_TOKEN });
|
|
1347
|
+
__privateSet(this, _operationSemaphore, false);
|
|
1348
|
+
return response.payload;
|
|
1349
|
+
}
|
|
1350
|
+
});
|
|
1351
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1352
|
+
__publicField(this, "GetCookies", async () => {
|
|
1353
|
+
const response = await __privateGet(this, _PostMessage).call(this, { command: IOauth2ListenerCommand.COOKIES });
|
|
1354
|
+
return response.payload;
|
|
1355
|
+
});
|
|
1356
|
+
__publicField(this, "RestoreSession", async () => {
|
|
1357
|
+
try {
|
|
1358
|
+
debug$1(`STSOAuth2Manager:RestoreSession:postMessage: [${IOauth2ListenerCommand.RESTORE_SESSION}]`);
|
|
1359
|
+
const response = await __privateGet(this, _PostMessage).call(this, { command: IOauth2ListenerCommand.RESTORE_SESSION });
|
|
1360
|
+
debug$1(`STSOAuth2Manager:RestoreSession:response: [${JSON.stringify(response.payload)}]`);
|
|
1361
|
+
return response.payload;
|
|
1362
|
+
} catch (error) {
|
|
1363
|
+
console.log(`RestoreSession Error: ${error}`);
|
|
1364
|
+
return false;
|
|
1365
|
+
}
|
|
1366
|
+
});
|
|
1367
|
+
__publicField(this, "Authorize", async () => {
|
|
1368
|
+
try {
|
|
1369
|
+
const response = await __privateGet(this, _PostMessage).call(this, { command: IOauth2ListenerCommand.AUTHORIZE });
|
|
1370
|
+
__privateGet(this, _transactionStore).set(__privateGet(this, _STORAGE_AUTHORIZE_OPTIONS_KEY), response.payload.authorizeOptions);
|
|
1371
|
+
const url = response.payload.url;
|
|
1372
|
+
if (!isNode) {
|
|
1373
|
+
window.location.replace(url);
|
|
1374
|
+
} else {
|
|
1375
|
+
return response.payload.authorizeOptionsClientCopy;
|
|
1376
|
+
}
|
|
1377
|
+
} catch (error) {
|
|
1378
|
+
console.log(`Authorize Error: ${error}`);
|
|
1379
|
+
}
|
|
1380
|
+
return {};
|
|
1381
|
+
});
|
|
1382
|
+
__publicField(this, "HandleRedirect", async (queryVars) => {
|
|
1383
|
+
try {
|
|
1384
|
+
debug$1(`STSOAuth2Manager:HandleRedirect`.magenta);
|
|
1385
|
+
let response = null;
|
|
1386
|
+
if (queryVars[stsutils.OAuth2ParameterType.CODE]) {
|
|
1387
|
+
const authorizeOptions = __privateGet(this, _transactionStore).get(__privateGet(this, _STORAGE_AUTHORIZE_OPTIONS_KEY));
|
|
1388
|
+
__privateGet(this, _transactionStore).remove(__privateGet(this, _STORAGE_AUTHORIZE_OPTIONS_KEY));
|
|
1389
|
+
debug$1(`STSOAuth2Manager:HandleRedirect: sending HANDLE_REDIRECT command`.magenta);
|
|
1390
|
+
response = await __privateGet(this, _PostMessage).call(this, { command: IOauth2ListenerCommand.HANDLE_REDIRECT, payload: {
|
|
1391
|
+
queryVars,
|
|
1392
|
+
authorizeOptions
|
|
1393
|
+
} });
|
|
1394
|
+
} else {
|
|
1395
|
+
response = await __privateGet(this, _PostMessage).call(this, { command: IOauth2ListenerCommand.HANDLE_REDIRECT, payload: queryVars });
|
|
1396
|
+
}
|
|
1397
|
+
debug$1(`STSOAuth2Manager:HandleRedirect: HANDLE_REDIRECT response: [${JSON.stringify(response)}]`.magenta);
|
|
1398
|
+
return response.payload;
|
|
1399
|
+
} catch (error) {
|
|
1400
|
+
console.log(`HandleRedirect Error: ${error}`);
|
|
1401
|
+
return false;
|
|
1402
|
+
}
|
|
1403
|
+
});
|
|
1404
|
+
__publicField(this, "Logout", async () => {
|
|
1405
|
+
try {
|
|
1406
|
+
const response = await __privateGet(this, _PostMessage).call(this, { command: IOauth2ListenerCommand.LOGOUT });
|
|
1407
|
+
return response.payload;
|
|
1408
|
+
} catch (error) {
|
|
1409
|
+
console.log(`Logout Error: ${error}`);
|
|
1410
|
+
return false;
|
|
1411
|
+
}
|
|
1412
|
+
});
|
|
1413
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1414
|
+
__publicField(this, "InvokeExternalAPI", async () => {
|
|
1415
|
+
try {
|
|
1416
|
+
const response = await __privateGet(this, _PostMessage).call(this, { command: IOauth2ListenerCommand.LOGOUT });
|
|
1417
|
+
return response.payload;
|
|
1418
|
+
} catch (error) {
|
|
1419
|
+
console.log(`InvokeExternalAPI Error: ${error}`);
|
|
1420
|
+
return null;
|
|
1421
|
+
}
|
|
1422
|
+
});
|
|
1423
|
+
__publicField(this, "LoggedIn", () => {
|
|
1424
|
+
try {
|
|
1425
|
+
return __privateGet(this, _GetStore).call(this).LoggedIn;
|
|
1426
|
+
} catch (error) {
|
|
1427
|
+
return false;
|
|
1428
|
+
}
|
|
1429
|
+
});
|
|
1430
|
+
__privateSet(this, _options, options);
|
|
1431
|
+
if (!isNode) {
|
|
1432
|
+
if (app.config.globalProperties.$sts[stspublisherserver.STSInstrumentControllerPluginKey]) {
|
|
1433
|
+
const STSInstrumentController = app.config.globalProperties.$sts[stspublisherserver.STSInstrumentControllerPluginKey];
|
|
1434
|
+
__privateSet(this, _aic, STSInstrumentController.PrimaryPublishInstrumentController);
|
|
1435
|
+
}
|
|
1436
|
+
__privateSet(this, _router, app.config.globalProperties.$router);
|
|
1437
|
+
}
|
|
1438
|
+
if (isNode) {
|
|
1439
|
+
__privateSet(this, _transactionStore, new stsvueutils.ClientStorageFactory({ clientStorageType: stsvueutils.ClientStorageType.MEMORY_STORAGE, usePrefix: false }).GetStorage());
|
|
1440
|
+
} else {
|
|
1441
|
+
__privateSet(this, _transactionStore, new stsvueutils.ClientStorageFactory({ clientStorageType: stsvueutils.ClientStorageType.SESSION_STORAGE, usePrefix: false }).GetStorage());
|
|
1442
|
+
}
|
|
1443
|
+
if (__privateGet(this, _options).workerFactory) {
|
|
1444
|
+
__privateSet(this, _worker, __privateGet(this, _options).workerFactory());
|
|
1445
|
+
} else {
|
|
1446
|
+
throw new Error(`STSOAuth2Manager:constructor: Cannot init STSOAuth2Manager - this.#options.workerFactory not specified`);
|
|
1447
|
+
}
|
|
1448
|
+
if (!isNode) {
|
|
1449
|
+
__privateGet(this, _worker).onmessage = (data) => {
|
|
1450
|
+
console.log(`this.#worker.onmessage = [${data}]`);
|
|
1451
|
+
};
|
|
1452
|
+
__privateGet(this, _worker).onerror = function(error) {
|
|
1453
|
+
console.log(`this.#worker.onerror = [${JSON.stringify(error)}]`);
|
|
1454
|
+
};
|
|
1455
|
+
}
|
|
1456
|
+
let workerMessage;
|
|
1457
|
+
if (isNode) {
|
|
1458
|
+
const {
|
|
1459
|
+
port1: oauth2ManagerPort,
|
|
1460
|
+
// this process port
|
|
1461
|
+
port2: oauth2WorkerPort
|
|
1462
|
+
// worker port
|
|
1463
|
+
} = new wt__namespace.MessageChannel();
|
|
1464
|
+
__privateSet(this, _oauth2ManagerPort, oauth2ManagerPort);
|
|
1465
|
+
workerMessage = {
|
|
1466
|
+
workerPort: oauth2WorkerPort,
|
|
1467
|
+
options: __privateGet(this, _options).workerOptions
|
|
1468
|
+
};
|
|
1469
|
+
__privateGet(this, _worker).postMessage(workerMessage, [oauth2WorkerPort]);
|
|
1470
|
+
__privateGet(this, _oauth2ManagerPort).on("message", (payload) => {
|
|
1471
|
+
__privateGet(this, _ProcessMessageResponse).call(this, payload);
|
|
1472
|
+
}).unref();
|
|
1473
|
+
} else {
|
|
1474
|
+
const {
|
|
1475
|
+
port1: oauth2ManagerPort,
|
|
1476
|
+
// this process port
|
|
1477
|
+
port2: oauth2WorkerPort
|
|
1478
|
+
// worker port
|
|
1479
|
+
} = new MessageChannel();
|
|
1480
|
+
__privateSet(this, _oauth2ManagerPort, oauth2ManagerPort);
|
|
1481
|
+
workerMessage = {
|
|
1482
|
+
workerPort: oauth2WorkerPort,
|
|
1483
|
+
options: __privateGet(this, _options).workerOptions
|
|
1484
|
+
};
|
|
1485
|
+
__privateGet(this, _worker).postMessage(workerMessage, [oauth2WorkerPort]);
|
|
1486
|
+
__privateGet(this, _oauth2ManagerPort).onmessage = (data) => {
|
|
1487
|
+
__privateGet(this, _ProcessMessageResponse).call(this, data.data);
|
|
1488
|
+
};
|
|
1489
|
+
__privateGet(this, _SetupRoute).call(this, app, __privateGet(this, _router));
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
/*
|
|
1493
|
+
GetIDToken = async (): Promise<string> => {
|
|
1494
|
+
try {
|
|
1495
|
+
const response: IOauth2ListenerMessageResponse = await this.#PostMessage({ command: IOauth2ListenerCommand.ID_TOKEN });
|
|
1496
|
+
return response.payload;
|
|
1497
|
+
} catch (error) {
|
|
1498
|
+
console.log(`Logout Error: ${error}`); // red
|
|
1499
|
+
return null;
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
*/
|
|
1503
|
+
}
|
|
1504
|
+
_router = new WeakMap();
|
|
1505
|
+
_cUtils = new WeakMap();
|
|
1506
|
+
_qParams = new WeakMap();
|
|
1507
|
+
_STORAGE_AUTHORIZE_OPTIONS_KEY = new WeakMap();
|
|
1508
|
+
_STORAGE_SESSION_KEY = new WeakMap();
|
|
1509
|
+
_aic = new WeakMap();
|
|
1510
|
+
_options = new WeakMap();
|
|
1511
|
+
_messages = new WeakMap();
|
|
1512
|
+
_oauth2ManagerPort = new WeakMap();
|
|
1513
|
+
_messageId = new WeakMap();
|
|
1514
|
+
_messageHandlers = new WeakMap();
|
|
1515
|
+
_messageTimeout = new WeakMap();
|
|
1516
|
+
_worker = new WeakMap();
|
|
1517
|
+
_transactionStore = new WeakMap();
|
|
1518
|
+
_operationSemaphore = new WeakMap();
|
|
1519
|
+
_maxSemaphoreRetries = new WeakMap();
|
|
1520
|
+
_semaphoreRetrySleep = new WeakMap();
|
|
1521
|
+
_ProcessMessageResponse = new WeakMap();
|
|
1522
|
+
_PostMessage = new WeakMap();
|
|
1523
|
+
_HandleLogEvent = new WeakMap();
|
|
1524
|
+
_HandleUpdateInstrumentEvent = new WeakMap();
|
|
1525
|
+
_GetStore = new WeakMap();
|
|
1526
|
+
_HandleErrorEvent = new WeakMap();
|
|
1527
|
+
_HandleAuthenticateEvent = new WeakMap();
|
|
1528
|
+
_SetupRoute = new WeakMap();
|
|
1529
|
+
var StatusCodes;
|
|
1530
|
+
(function(StatusCodes2) {
|
|
1531
|
+
StatusCodes2[StatusCodes2["ACCEPTED"] = 202] = "ACCEPTED";
|
|
1532
|
+
StatusCodes2[StatusCodes2["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
|
|
1533
|
+
StatusCodes2[StatusCodes2["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
|
1534
|
+
StatusCodes2[StatusCodes2["CONFLICT"] = 409] = "CONFLICT";
|
|
1535
|
+
StatusCodes2[StatusCodes2["CONTINUE"] = 100] = "CONTINUE";
|
|
1536
|
+
StatusCodes2[StatusCodes2["CREATED"] = 201] = "CREATED";
|
|
1537
|
+
StatusCodes2[StatusCodes2["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
|
|
1538
|
+
StatusCodes2[StatusCodes2["FAILED_DEPENDENCY"] = 424] = "FAILED_DEPENDENCY";
|
|
1539
|
+
StatusCodes2[StatusCodes2["FORBIDDEN"] = 403] = "FORBIDDEN";
|
|
1540
|
+
StatusCodes2[StatusCodes2["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
|
|
1541
|
+
StatusCodes2[StatusCodes2["GONE"] = 410] = "GONE";
|
|
1542
|
+
StatusCodes2[StatusCodes2["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
|
|
1543
|
+
StatusCodes2[StatusCodes2["IM_A_TEAPOT"] = 418] = "IM_A_TEAPOT";
|
|
1544
|
+
StatusCodes2[StatusCodes2["INSUFFICIENT_SPACE_ON_RESOURCE"] = 419] = "INSUFFICIENT_SPACE_ON_RESOURCE";
|
|
1545
|
+
StatusCodes2[StatusCodes2["INSUFFICIENT_STORAGE"] = 507] = "INSUFFICIENT_STORAGE";
|
|
1546
|
+
StatusCodes2[StatusCodes2["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
|
|
1547
|
+
StatusCodes2[StatusCodes2["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
|
|
1548
|
+
StatusCodes2[StatusCodes2["LOCKED"] = 423] = "LOCKED";
|
|
1549
|
+
StatusCodes2[StatusCodes2["METHOD_FAILURE"] = 420] = "METHOD_FAILURE";
|
|
1550
|
+
StatusCodes2[StatusCodes2["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
|
|
1551
|
+
StatusCodes2[StatusCodes2["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
|
|
1552
|
+
StatusCodes2[StatusCodes2["MOVED_TEMPORARILY"] = 302] = "MOVED_TEMPORARILY";
|
|
1553
|
+
StatusCodes2[StatusCodes2["MULTI_STATUS"] = 207] = "MULTI_STATUS";
|
|
1554
|
+
StatusCodes2[StatusCodes2["MULTIPLE_CHOICES"] = 300] = "MULTIPLE_CHOICES";
|
|
1555
|
+
StatusCodes2[StatusCodes2["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
|
|
1556
|
+
StatusCodes2[StatusCodes2["NO_CONTENT"] = 204] = "NO_CONTENT";
|
|
1557
|
+
StatusCodes2[StatusCodes2["NON_AUTHORITATIVE_INFORMATION"] = 203] = "NON_AUTHORITATIVE_INFORMATION";
|
|
1558
|
+
StatusCodes2[StatusCodes2["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
|
|
1559
|
+
StatusCodes2[StatusCodes2["NOT_FOUND"] = 404] = "NOT_FOUND";
|
|
1560
|
+
StatusCodes2[StatusCodes2["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
|
|
1561
|
+
StatusCodes2[StatusCodes2["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
|
|
1562
|
+
StatusCodes2[StatusCodes2["OK"] = 200] = "OK";
|
|
1563
|
+
StatusCodes2[StatusCodes2["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
|
|
1564
|
+
StatusCodes2[StatusCodes2["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
|
|
1565
|
+
StatusCodes2[StatusCodes2["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
|
|
1566
|
+
StatusCodes2[StatusCodes2["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
|
|
1567
|
+
StatusCodes2[StatusCodes2["PRECONDITION_REQUIRED"] = 428] = "PRECONDITION_REQUIRED";
|
|
1568
|
+
StatusCodes2[StatusCodes2["PROCESSING"] = 102] = "PROCESSING";
|
|
1569
|
+
StatusCodes2[StatusCodes2["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
|
|
1570
|
+
StatusCodes2[StatusCodes2["REQUEST_HEADER_FIELDS_TOO_LARGE"] = 431] = "REQUEST_HEADER_FIELDS_TOO_LARGE";
|
|
1571
|
+
StatusCodes2[StatusCodes2["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
|
|
1572
|
+
StatusCodes2[StatusCodes2["REQUEST_TOO_LONG"] = 413] = "REQUEST_TOO_LONG";
|
|
1573
|
+
StatusCodes2[StatusCodes2["REQUEST_URI_TOO_LONG"] = 414] = "REQUEST_URI_TOO_LONG";
|
|
1574
|
+
StatusCodes2[StatusCodes2["REQUESTED_RANGE_NOT_SATISFIABLE"] = 416] = "REQUESTED_RANGE_NOT_SATISFIABLE";
|
|
1575
|
+
StatusCodes2[StatusCodes2["RESET_CONTENT"] = 205] = "RESET_CONTENT";
|
|
1576
|
+
StatusCodes2[StatusCodes2["SEE_OTHER"] = 303] = "SEE_OTHER";
|
|
1577
|
+
StatusCodes2[StatusCodes2["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
|
|
1578
|
+
StatusCodes2[StatusCodes2["SWITCHING_PROTOCOLS"] = 101] = "SWITCHING_PROTOCOLS";
|
|
1579
|
+
StatusCodes2[StatusCodes2["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
|
|
1580
|
+
StatusCodes2[StatusCodes2["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
|
|
1581
|
+
StatusCodes2[StatusCodes2["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
|
|
1582
|
+
StatusCodes2[StatusCodes2["UNAVAILABLE_FOR_LEGAL_REASONS"] = 451] = "UNAVAILABLE_FOR_LEGAL_REASONS";
|
|
1583
|
+
StatusCodes2[StatusCodes2["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
|
|
1584
|
+
StatusCodes2[StatusCodes2["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
|
|
1585
|
+
StatusCodes2[StatusCodes2["USE_PROXY"] = 305] = "USE_PROXY";
|
|
1586
|
+
StatusCodes2[StatusCodes2["MISDIRECTED_REQUEST"] = 421] = "MISDIRECTED_REQUEST";
|
|
1587
|
+
})(StatusCodes || (StatusCodes = {}));
|
|
1588
|
+
let debug;
|
|
1589
|
+
if (isNode) {
|
|
1590
|
+
debug = Debug(`proc:${process.pid}:stsoauth2worker.ts`);
|
|
1591
|
+
} else {
|
|
1592
|
+
debug = Debug(`proc:0:stsoauth2worker.ts`);
|
|
1593
|
+
}
|
|
1594
|
+
class STSOAuth2Worker {
|
|
1595
|
+
constructor(workerPort, options) {
|
|
1596
|
+
//#storageManager = null;
|
|
1597
|
+
__privateAdd(this, _clientSessionStore, void 0);
|
|
1598
|
+
__privateAdd(this, _cUtils2, new CryptoUtils());
|
|
1599
|
+
__privateAdd(this, _qParams2, new QueryParams());
|
|
1600
|
+
__privateAdd(this, _STORAGE_SESSION_KEY2, "session.stsmda.com.au");
|
|
1601
|
+
//@@#aic = null;
|
|
1602
|
+
__privateAdd(this, _oauthWorkerPort, void 0);
|
|
1603
|
+
__privateAdd(this, _options2, void 0);
|
|
1604
|
+
__privateAdd(this, _httpsAgent, null);
|
|
1605
|
+
// Attempt to restore a previous session using the STSBroker
|
|
1606
|
+
/*
|
|
1607
|
+
{ parameterType: OAuth2ParameterType.CLIENT_ID, errorType: authErrorType.CLIENT_ID_MISMATCH },
|
|
1608
|
+
{ parameterType: OAuth2ParameterType.SCOPE, errorType: authErrorType.SCOPE_MISMATCH }
|
|
1609
|
+
{ parameterType: OAuth2ParameterType.REDIRECT_URI, errorType: authErrorType.REDIRECT_URI_MISMATCH },
|
|
1610
|
+
{ parameterType: OAuth2ParameterType.AUDIENCE, errorType: authErrorType.SCOPE_MISMATCH }
|
|
1611
|
+
|
|
1612
|
+
Successful Response
|
|
1613
|
+
{
|
|
1614
|
+
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ik5HVEZ2ZEstZnl0aEV1Q...",
|
|
1615
|
+
"token_type": "Bearer",
|
|
1616
|
+
"expires_in": 3599,
|
|
1617
|
+
"scope": "https%3A%2F%2Fgraph.microsoft.com%2Fmail.read",
|
|
1618
|
+
"refresh_token": "AwABAAAAvPM1KaPlrEqdFSBzjqfTGAMxZGUTdM0t4B4...",
|
|
1619
|
+
"id_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJhdWQiOiIyZDRkMTFhMi1mODE0LTQ2YTctOD...",
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1622
|
+
Error Response
|
|
1623
|
+
{
|
|
1624
|
+
"error": "invalid_scope",
|
|
1625
|
+
"error_description": "AADSTS70011: The provided value for the input parameter 'scope' is not valid. The scope https://foo.microsoft.com/mail.read is not valid.\r\nTrace ID: 255d1aef-8c98-452f-ac51-23d051240864\r\nCorrelation ID: fb3d2015-bc17-4bb9-bb85-30c5cf1aaaa7\r\nTimestamp: 2016-01-09 02:02:12Z",
|
|
1626
|
+
"error_codes": [
|
|
1627
|
+
70011
|
|
1628
|
+
],
|
|
1629
|
+
"timestamp": "2016-01-09 02:02:12Z",
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1632
|
+
*/
|
|
1633
|
+
__privateAdd(this, _HandleAuthenticateEvent2, (id_token) => {
|
|
1634
|
+
const message = {
|
|
1635
|
+
messageId: -1,
|
|
1636
|
+
// un-solicited message
|
|
1637
|
+
command: IOauth2ListenerCommand.AUTHENTICATE_EVENT
|
|
1638
|
+
};
|
|
1639
|
+
__privateGet(this, _ProcessCommand).call(this, message, id_token);
|
|
1640
|
+
});
|
|
1641
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1642
|
+
__privateAdd(this, _HandleErrorEvent2, (error) => {
|
|
1643
|
+
const message = {
|
|
1644
|
+
messageId: -1,
|
|
1645
|
+
// un-solicited message
|
|
1646
|
+
command: IOauth2ListenerCommand.ERROR
|
|
1647
|
+
};
|
|
1648
|
+
__privateGet(this, _ProcessCommand).call(this, message, error);
|
|
1649
|
+
});
|
|
1650
|
+
__privateAdd(this, _LogMessage, (messageToSend) => {
|
|
1651
|
+
const message = {
|
|
1652
|
+
messageId: -1,
|
|
1653
|
+
// un-solicited message
|
|
1654
|
+
command: IOauth2ListenerCommand.LOG
|
|
1655
|
+
};
|
|
1656
|
+
__privateGet(this, _ProcessCommand).call(this, message, messageToSend);
|
|
1657
|
+
});
|
|
1658
|
+
__privateAdd(this, _GetAccessToken, () => {
|
|
1659
|
+
const sessionData = __privateGet(this, _clientSessionStore).get(__privateGet(this, _STORAGE_SESSION_KEY2));
|
|
1660
|
+
if (sessionData) {
|
|
1661
|
+
const tokens = sessionData.tokenResponse;
|
|
1662
|
+
return tokens.access_token;
|
|
1663
|
+
} else {
|
|
1664
|
+
return null;
|
|
1665
|
+
}
|
|
1666
|
+
});
|
|
1667
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1668
|
+
__privateAdd(this, _GetCookies, () => {
|
|
1669
|
+
if (isNode) {
|
|
1670
|
+
const sessionData = __privateGet(this, _clientSessionStore).get(__privateGet(this, _STORAGE_SESSION_KEY2));
|
|
1671
|
+
if (sessionData) {
|
|
1672
|
+
return sessionData.brokerCookie;
|
|
1673
|
+
} else {
|
|
1674
|
+
return null;
|
|
1675
|
+
}
|
|
1676
|
+
} else {
|
|
1677
|
+
return null;
|
|
1678
|
+
}
|
|
1679
|
+
});
|
|
1680
|
+
__privateAdd(this, _UpdateInstrument, (instrumentName, telemetry) => {
|
|
1681
|
+
const message = {
|
|
1682
|
+
messageId: -1,
|
|
1683
|
+
// un-solicited message
|
|
1684
|
+
command: IOauth2ListenerCommand.UPDATE_INSTRUMENT
|
|
1685
|
+
};
|
|
1686
|
+
__privateGet(this, _ProcessCommand).call(this, message, {
|
|
1687
|
+
instrumentName,
|
|
1688
|
+
telemetry
|
|
1689
|
+
});
|
|
1690
|
+
});
|
|
1691
|
+
__publicField(this, "SetupListener", () => {
|
|
1692
|
+
__privateGet(this, _oauthWorkerPort).onmessage = async (data) => {
|
|
1693
|
+
const auth2ListenerMessage = data.data;
|
|
1694
|
+
debug(`STSOAuth2Worker:SetupListener:onmessage: [${auth2ListenerMessage.command}]`);
|
|
1695
|
+
switch (auth2ListenerMessage.command) {
|
|
1696
|
+
case IOauth2ListenerCommand.RESTORE_SESSION:
|
|
1697
|
+
__privateGet(this, _ProcessCommand).call(this, auth2ListenerMessage, await __privateGet(this, _RestoreSession).call(this));
|
|
1698
|
+
break;
|
|
1699
|
+
case IOauth2ListenerCommand.AUTHORIZE:
|
|
1700
|
+
__privateGet(this, _ProcessCommand).call(this, auth2ListenerMessage, await __privateGet(this, _Authorize).call(this));
|
|
1701
|
+
break;
|
|
1702
|
+
case IOauth2ListenerCommand.HANDLE_REDIRECT:
|
|
1703
|
+
__privateGet(this, _ProcessCommand).call(this, auth2ListenerMessage, await __privateGet(this, _HandleRedirect).call(this, auth2ListenerMessage.payload));
|
|
1704
|
+
break;
|
|
1705
|
+
case IOauth2ListenerCommand.LOGOUT:
|
|
1706
|
+
__privateGet(this, _ProcessCommand).call(this, auth2ListenerMessage, await __privateGet(this, _Logout).call(this));
|
|
1707
|
+
break;
|
|
1708
|
+
case IOauth2ListenerCommand.ACCESS_TOKEN:
|
|
1709
|
+
__privateGet(this, _ProcessCommand).call(this, auth2ListenerMessage, await __privateGet(this, _GetAccessToken).call(this));
|
|
1710
|
+
break;
|
|
1711
|
+
case IOauth2ListenerCommand.EXECUTE_REFRESH_TOKEN:
|
|
1712
|
+
__privateGet(this, _ProcessCommand).call(this, auth2ListenerMessage, await __privateGet(this, _RefreshToken).call(this));
|
|
1713
|
+
break;
|
|
1714
|
+
case IOauth2ListenerCommand.COOKIES:
|
|
1715
|
+
__privateGet(this, _ProcessCommand).call(this, auth2ListenerMessage, await __privateGet(this, _GetCookies).call(this));
|
|
1716
|
+
break;
|
|
1717
|
+
default:
|
|
1718
|
+
throw new Error(`Command: [${auth2ListenerMessage.command}'] not found.`);
|
|
1719
|
+
}
|
|
1720
|
+
};
|
|
1721
|
+
});
|
|
1722
|
+
/*
|
|
1723
|
+
#GetIDToken = async(): Promise<string> => {
|
|
1724
|
+
return '-- ID Token --';
|
|
1725
|
+
}
|
|
1726
|
+
*/
|
|
1727
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1728
|
+
__privateAdd(this, _ProcessCommand, async (auth2ListenerMessage, response) => {
|
|
1729
|
+
const messageResponse = {
|
|
1730
|
+
messageId: auth2ListenerMessage.messageId,
|
|
1731
|
+
command: auth2ListenerMessage.command,
|
|
1732
|
+
payload: response
|
|
1733
|
+
};
|
|
1734
|
+
__privateGet(this, _oauthWorkerPort).postMessage(messageResponse);
|
|
1735
|
+
});
|
|
1736
|
+
__privateAdd(this, _RestoreSession, async () => {
|
|
1737
|
+
let restoredSessionData = null;
|
|
1738
|
+
const sessionData = __privateGet(this, _clientSessionStore).get(__privateGet(this, _STORAGE_SESSION_KEY2));
|
|
1739
|
+
if (sessionData) {
|
|
1740
|
+
restoredSessionData = sessionData.tokenResponse;
|
|
1741
|
+
console.log("Session restored from client storage.");
|
|
1742
|
+
__privateGet(this, _LogMessage).call(this, "Session restored from client storage.");
|
|
1743
|
+
} else {
|
|
1744
|
+
const url = `${__privateGet(this, _options2).brokerendpoint}:${__privateGet(this, _options2).brokerport}${__privateGet(this, _options2).brokerapiroot}/session`;
|
|
1745
|
+
console.log("RestoreSession");
|
|
1746
|
+
console.log(url);
|
|
1747
|
+
__privateGet(this, _LogMessage).call(this, "RestoreSession.");
|
|
1748
|
+
__privateGet(this, _LogMessage).call(this, url);
|
|
1749
|
+
try {
|
|
1750
|
+
const rConfig = {
|
|
1751
|
+
method: "post",
|
|
1752
|
+
url,
|
|
1753
|
+
data: {
|
|
1754
|
+
[stsutils.OAuth2ParameterType.CLIENT_ID]: __privateGet(this, _options2).client_id,
|
|
1755
|
+
[stsutils.OAuth2ParameterType.SCOPE]: __privateGet(this, _options2).scope,
|
|
1756
|
+
[stsutils.OAuth2ParameterType.REDIRECT_URI]: __privateGet(this, _options2).redirect_uri,
|
|
1757
|
+
[stsutils.OAuth2ParameterType.AUDIENCE]: __privateGet(this, _options2).audience
|
|
1758
|
+
},
|
|
1759
|
+
withCredentials: true,
|
|
1760
|
+
// Ensure cookies are passed to the service
|
|
1761
|
+
timeout: __privateGet(this, _options2).timeout
|
|
1762
|
+
};
|
|
1763
|
+
debug(`#RestoreSession:session request detail: [${JSON.stringify(rConfig)}]`.magenta);
|
|
1764
|
+
if (isNode) {
|
|
1765
|
+
rConfig.httpsAgent = __privateGet(this, _httpsAgent);
|
|
1766
|
+
}
|
|
1767
|
+
const retVal = await axios(rConfig);
|
|
1768
|
+
if (retVal.data.status === StatusCodes.OK) {
|
|
1769
|
+
restoredSessionData = retVal.data.detail;
|
|
1770
|
+
if (restoredSessionData) {
|
|
1771
|
+
const newSessionData = {
|
|
1772
|
+
tokenResponse: restoredSessionData
|
|
1773
|
+
};
|
|
1774
|
+
if (isNode) {
|
|
1775
|
+
newSessionData.brokerCookie = retVal.headers["set-cookie"];
|
|
1776
|
+
}
|
|
1777
|
+
__privateGet(this, _clientSessionStore).set(__privateGet(this, _STORAGE_SESSION_KEY2), newSessionData);
|
|
1778
|
+
console.log("Session restored from server side cookie.");
|
|
1779
|
+
} else {
|
|
1780
|
+
console.log(`Could not restore previous session. No restoredSessionData available.`);
|
|
1781
|
+
console.log(JSON.stringify(retVal.data));
|
|
1782
|
+
}
|
|
1783
|
+
} else {
|
|
1784
|
+
console.log("Could not restore previous session:-");
|
|
1785
|
+
console.log(JSON.stringify(retVal.data));
|
|
1786
|
+
}
|
|
1787
|
+
} catch (error) {
|
|
1788
|
+
console.log("Could not restore previous session (error state):-");
|
|
1789
|
+
console.log(error);
|
|
1790
|
+
console.log(JSON.stringify(error));
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
if (restoredSessionData !== null) {
|
|
1794
|
+
__privateGet(this, _HandleAuthenticateEvent2).call(this, restoredSessionData.id_token);
|
|
1795
|
+
console.log("Refreshing tokens ...");
|
|
1796
|
+
return await __privateGet(this, _RefreshToken).call(this);
|
|
1797
|
+
} else {
|
|
1798
|
+
__privateGet(this, _HandleAuthenticateEvent2).call(this, null);
|
|
1799
|
+
return false;
|
|
1800
|
+
}
|
|
1801
|
+
});
|
|
1802
|
+
__privateAdd(this, _Authorize, async () => {
|
|
1803
|
+
console.log("Authorize ...");
|
|
1804
|
+
const client_id = __privateGet(this, _options2).client_id;
|
|
1805
|
+
const nonce = __privateGet(this, _cUtils2).CreateRandomString();
|
|
1806
|
+
const response_type = [AuthorizeOptionsResponseType.CODE];
|
|
1807
|
+
const redirect_uri = __privateGet(this, _options2).redirect_uri;
|
|
1808
|
+
const response_mode = AuthorizeOptionsResponseMode.QUERY;
|
|
1809
|
+
const scope = __privateGet(this, _options2).scope;
|
|
1810
|
+
const state = __privateGet(this, _cUtils2).CreateRandomString();
|
|
1811
|
+
const code_verifier = __privateGet(this, _cUtils2).CreateRandomString();
|
|
1812
|
+
const code_challenge = await __privateGet(this, _cUtils2).DigestMessage(code_verifier);
|
|
1813
|
+
const code_challenge_method = "S256";
|
|
1814
|
+
const authorizeOptions = {
|
|
1815
|
+
client_id,
|
|
1816
|
+
nonce,
|
|
1817
|
+
response_type,
|
|
1818
|
+
redirect_uri,
|
|
1819
|
+
response_mode,
|
|
1820
|
+
scope,
|
|
1821
|
+
state,
|
|
1822
|
+
code_challenge,
|
|
1823
|
+
code_challenge_method
|
|
1824
|
+
};
|
|
1825
|
+
const authorizeOptionsClientCopy = { ...authorizeOptions };
|
|
1826
|
+
const url = `${__privateGet(this, _options2).authorizeendpoint}:${__privateGet(this, _options2).authorizeport}${__privateGet(this, _options2).authorizeapiroot}${__privateGet(this, _options2).authorizeapi}?${__privateGet(this, _qParams2).CreateQueryParams(authorizeOptions)}`;
|
|
1827
|
+
console.log(url);
|
|
1828
|
+
authorizeOptions.code_verifier = code_verifier;
|
|
1829
|
+
console.log(`Authorize:authorizeOptions: [${JSON.stringify(authorizeOptions)}]`);
|
|
1830
|
+
return {
|
|
1831
|
+
url,
|
|
1832
|
+
authorizeOptions,
|
|
1833
|
+
authorizeOptionsClientCopy
|
|
1834
|
+
};
|
|
1835
|
+
});
|
|
1836
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1837
|
+
__privateAdd(this, _HandleRedirect, async (payload) => {
|
|
1838
|
+
const queryVars = payload.queryVars;
|
|
1839
|
+
const authorizeOptions = payload.authorizeOptions;
|
|
1840
|
+
debug(`#HandleRedirect: HandleRedirect`.magenta);
|
|
1841
|
+
debug(`#HandleRedirect: HandleRedirect:Query Vars: [${JSON.stringify(queryVars)}]`.magenta);
|
|
1842
|
+
if (queryVars[stsutils.OAuth2ParameterType.CODE]) {
|
|
1843
|
+
const response = queryVars;
|
|
1844
|
+
console.log(`authorizeOptions from transaction state: [${JSON.stringify(authorizeOptions)}]`);
|
|
1845
|
+
const redirectState = response.state;
|
|
1846
|
+
const authorizeOptionsState = authorizeOptions.state;
|
|
1847
|
+
if (authorizeOptionsState.localeCompare(redirectState) === 0) {
|
|
1848
|
+
console.log("redirected state (from queryVars) matched previously saved transaction authorizeOptions state");
|
|
1849
|
+
return await __privateGet(this, _GetToken).call(this, authorizeOptions, response);
|
|
1850
|
+
} else {
|
|
1851
|
+
console.log("redirected state (from queryVars) did NOT match previously saved transaction authorizeOptions state");
|
|
1852
|
+
console.log(`authorizeOptionsState: [${authorizeOptionsState}]`);
|
|
1853
|
+
console.log(`redirectState: [${redirectState}]`);
|
|
1854
|
+
__privateGet(this, _HandleErrorEvent2).call(this, { message: "State un-matched" });
|
|
1855
|
+
return false;
|
|
1856
|
+
}
|
|
1857
|
+
} else if (queryVars[stsutils.OAuth2ParameterType.ERROR]) {
|
|
1858
|
+
__privateGet(this, _HandleErrorEvent2).call(this, { message: "State un-matched" });
|
|
1859
|
+
return false;
|
|
1860
|
+
} else {
|
|
1861
|
+
__privateGet(this, _HandleErrorEvent2).call(this, { message: "State un-matched" });
|
|
1862
|
+
return false;
|
|
1863
|
+
}
|
|
1864
|
+
});
|
|
1865
|
+
/*
|
|
1866
|
+
client_id=6731de76-14a6-49ae-97bc-6eba6914391e
|
|
1867
|
+
&scope=https%3A%2F%2Fgraph.microsoft.com%2Fmail.read
|
|
1868
|
+
&code=OAAABAAAAiL9Kn2Z27UubvWFPbm0gLWQJVzCTE9UkP3pSx1aXxUjq3n8b2JRLk4OxVXr...
|
|
1869
|
+
&redirect_uri=http%3A%2F%2Flocalhost%2Fmyapp%2F
|
|
1870
|
+
&grant_type=authorization_code
|
|
1871
|
+
&code_verifier=ThisIsntRandomButItNeedsToBe43CharactersLong
|
|
1872
|
+
&client_secret=JqQX2PNo9bpM0uEihUPzyrh // NOTE: Only required for web apps. This secret needs to be URL-Encoded.
|
|
1873
|
+
|
|
1874
|
+
Successful Response
|
|
1875
|
+
{
|
|
1876
|
+
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ik5HVEZ2ZEstZnl0aEV1Q...",
|
|
1877
|
+
"token_type": "Bearer",
|
|
1878
|
+
"expires_in": 3599,
|
|
1879
|
+
"scope": "https%3A%2F%2Fgraph.microsoft.com%2Fmail.read",
|
|
1880
|
+
"refresh_token": "AwABAAAAvPM1KaPlrEqdFSBzjqfTGAMxZGUTdM0t4B4...",
|
|
1881
|
+
"id_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJhdWQiOiIyZDRkMTFhMi1mODE0LTQ2YTctOD...",
|
|
1882
|
+
}
|
|
1883
|
+
*/
|
|
1884
|
+
// Get access_token, refresh_token and id_token using OAuth2 Authorization Code Flow
|
|
1885
|
+
__privateAdd(this, _GetTokenFromBroker, async (authorizationCodeFlowParameters) => {
|
|
1886
|
+
debug(`#GetTokenFromBroker`.magenta);
|
|
1887
|
+
__privateGet(this, _clientSessionStore).remove(__privateGet(this, _STORAGE_SESSION_KEY2));
|
|
1888
|
+
const url = `${__privateGet(this, _options2).brokerendpoint}:${__privateGet(this, _options2).brokerport}${__privateGet(this, _options2).brokerapiroot}/token`;
|
|
1889
|
+
try {
|
|
1890
|
+
const rConfig = {
|
|
1891
|
+
method: "post",
|
|
1892
|
+
url,
|
|
1893
|
+
data: authorizationCodeFlowParameters,
|
|
1894
|
+
withCredentials: true,
|
|
1895
|
+
// Ensure cookies are passed to the service
|
|
1896
|
+
timeout: __privateGet(this, _options2).timeout
|
|
1897
|
+
};
|
|
1898
|
+
debug(`#GetTokenFromBroker: request config: [${JSON.stringify(rConfig)}]`.magenta);
|
|
1899
|
+
if (isNode) {
|
|
1900
|
+
rConfig.httpsAgent = __privateGet(this, _httpsAgent);
|
|
1901
|
+
}
|
|
1902
|
+
debug(`#GetTokenFromBroker: axios API call`.magenta);
|
|
1903
|
+
const retVal = await axios(rConfig);
|
|
1904
|
+
debug(`#GetTokenFromBroker: axios API call result: [${retVal.status}]`.magenta);
|
|
1905
|
+
if (retVal.status === StatusCodes.OK) {
|
|
1906
|
+
debug(`#GetTokenFromBroker: storing tokens`.magenta);
|
|
1907
|
+
const tokenResponse = retVal.data;
|
|
1908
|
+
__privateGet(this, _HandleAuthenticateEvent2).call(this, tokenResponse.id_token);
|
|
1909
|
+
const newSessionData = {
|
|
1910
|
+
tokenResponse
|
|
1911
|
+
};
|
|
1912
|
+
if (isNode) {
|
|
1913
|
+
newSessionData.brokerCookie = retVal.headers["set-cookie"];
|
|
1914
|
+
}
|
|
1915
|
+
__privateGet(this, _clientSessionStore).set(__privateGet(this, _STORAGE_SESSION_KEY2), newSessionData);
|
|
1916
|
+
return true;
|
|
1917
|
+
} else if (retVal.status === StatusCodes.UNAUTHORIZED) {
|
|
1918
|
+
debug(`#GetTokenFromBroker: NOT storing tokens, status: [${retVal.status}]`.magenta);
|
|
1919
|
+
__privateGet(this, _HandleAuthenticateEvent2).call(this, null);
|
|
1920
|
+
return false;
|
|
1921
|
+
} else {
|
|
1922
|
+
debug(`#GetTokenFromBroker: NOT storing tokens (general error 1), status: [${retVal.status}]`.magenta);
|
|
1923
|
+
__privateGet(this, _HandleAuthenticateEvent2).call(this, null);
|
|
1924
|
+
console.log("Could not obtain access_token from token end-point:-");
|
|
1925
|
+
console.log(JSON.stringify(retVal.data));
|
|
1926
|
+
return false;
|
|
1927
|
+
}
|
|
1928
|
+
} catch (error) {
|
|
1929
|
+
debug(`#GetTokenFromBroker: NOT storing tokens (general error 2), status: [${error}]`.red);
|
|
1930
|
+
__privateGet(this, _HandleAuthenticateEvent2).call(this, null);
|
|
1931
|
+
return false;
|
|
1932
|
+
}
|
|
1933
|
+
});
|
|
1934
|
+
// Get access_token, refresh_token and id_token using OAuth2 Authorization Code Flow
|
|
1935
|
+
__privateAdd(this, _GetToken, async (authorizeOptions, authorizeResponse) => {
|
|
1936
|
+
console.log("#GetToken");
|
|
1937
|
+
console.log(authorizeResponse);
|
|
1938
|
+
__privateGet(this, _clientSessionStore).remove(__privateGet(this, _STORAGE_SESSION_KEY2));
|
|
1939
|
+
const authorizationCodeFlowParameters = {
|
|
1940
|
+
client_id: __privateGet(this, _options2).client_id,
|
|
1941
|
+
scope: __privateGet(this, _options2).scope,
|
|
1942
|
+
code: authorizeResponse.code,
|
|
1943
|
+
redirect_uri: __privateGet(this, _options2).redirect_uri,
|
|
1944
|
+
grant_type: OAuthGrantTypes.AUTHORIZATION_CODE,
|
|
1945
|
+
code_verifier: authorizeOptions.code_verifier
|
|
1946
|
+
};
|
|
1947
|
+
return await __privateGet(this, _GetTokenFromBroker).call(this, authorizationCodeFlowParameters);
|
|
1948
|
+
});
|
|
1949
|
+
/*
|
|
1950
|
+
// Line breaks for legibility only
|
|
1951
|
+
|
|
1952
|
+
POST /{tenant}/oauth2/v2.0/token HTTP/1.1
|
|
1953
|
+
Host: https://login.microsoftonline.com
|
|
1954
|
+
Content-Type: application/x-www-form-urlencoded
|
|
1955
|
+
|
|
1956
|
+
client_id=535fb089-9ff3-47b6-9bfb-4f1264799865
|
|
1957
|
+
&scope=https%3A%2F%2Fgraph.microsoft.com%2Fmail.read
|
|
1958
|
+
&refresh_token=OAAABAAAAiL9Kn2Z27UubvWFPbm0gLWQJVzCTE9UkP3pSx1aXxUjq...
|
|
1959
|
+
&grant_type=refresh_token
|
|
1960
|
+
&client_secret=sampleCredentia1s // NOTE: Only required for web apps. This secret needs to be URL-Encoded
|
|
1961
|
+
|
|
1962
|
+
Error Response
|
|
1963
|
+
{
|
|
1964
|
+
"error": "invalid_scope",
|
|
1965
|
+
"error_description": "AADSTS70011: The provided value for the input parameter 'scope' is not valid. The scope https://foo.microsoft.com/mail.read is not valid.\r\nTrace ID: 255d1aef-8c98-452f-ac51-23d051240864\r\nCorrelation ID: fb3d2015-bc17-4bb9-bb85-30c5cf1aaaa7\r\nTimestamp: 2016-01-09 02:02:12Z",
|
|
1966
|
+
"error_codes": [
|
|
1967
|
+
70011
|
|
1968
|
+
],
|
|
1969
|
+
"timestamp": "2016-01-09 02:02:12Z",
|
|
1970
|
+
"trace_id": "255d1aef-8c98-452f-ac51-23d051240864",
|
|
1971
|
+
"correlation_id": "fb3d2015-bc17-4bb9-bb85-30c5cf1aaaa7"
|
|
1972
|
+
}
|
|
1973
|
+
*/
|
|
1974
|
+
__privateAdd(this, _RefreshToken, async () => {
|
|
1975
|
+
debug(`STSOAuth2Worker:#RefreshToken:start`.cyan);
|
|
1976
|
+
const sessionData = __privateGet(this, _clientSessionStore).get(__privateGet(this, _STORAGE_SESSION_KEY2));
|
|
1977
|
+
if (sessionData) {
|
|
1978
|
+
debug(`STSOAuth2Worker:#RefreshToken:sessionData: [${JSON.stringify(sessionData)}]`.cyan);
|
|
1979
|
+
const currentSessionData = sessionData.tokenResponse;
|
|
1980
|
+
const refreshFlowParameters = {
|
|
1981
|
+
client_id: __privateGet(this, _options2).client_id,
|
|
1982
|
+
scope: __privateGet(this, _options2).scope,
|
|
1983
|
+
refresh_token: currentSessionData.refresh_token,
|
|
1984
|
+
grant_type: OAuthGrantTypes.REFRESH_TOKEN
|
|
1985
|
+
};
|
|
1986
|
+
return await __privateGet(this, _GetTokenFromBroker).call(this, refreshFlowParameters);
|
|
1987
|
+
} else {
|
|
1988
|
+
debug(`STSOAuth2Worker:#RefreshToken:sessionData not found within clientSessionStore`.red);
|
|
1989
|
+
return false;
|
|
1990
|
+
}
|
|
1991
|
+
});
|
|
1992
|
+
// call broker to logout
|
|
1993
|
+
// broker to logout of server
|
|
1994
|
+
// delete cookie
|
|
1995
|
+
// clear session storage
|
|
1996
|
+
// clear all state from $store
|
|
1997
|
+
__privateAdd(this, _Logout, async () => {
|
|
1998
|
+
console.log("Logout");
|
|
1999
|
+
const url = `${__privateGet(this, _options2).brokerendpoint}:${__privateGet(this, _options2).brokerport}${__privateGet(this, _options2).brokerapiroot}/logout`;
|
|
2000
|
+
console.log(url);
|
|
2001
|
+
const sessionData = __privateGet(this, _clientSessionStore).get(__privateGet(this, _STORAGE_SESSION_KEY2));
|
|
2002
|
+
if (sessionData) {
|
|
2003
|
+
const currentSessionData = sessionData.tokenResponse;
|
|
2004
|
+
const refresh_token = currentSessionData.refresh_token;
|
|
2005
|
+
console.log(refresh_token);
|
|
2006
|
+
const decodedRefreshToken = o(refresh_token);
|
|
2007
|
+
console.log(decodedRefreshToken);
|
|
2008
|
+
const sessionId = decodedRefreshToken.sts_session;
|
|
2009
|
+
console.log(sessionId);
|
|
2010
|
+
__privateGet(this, _clientSessionStore).remove(__privateGet(this, _STORAGE_SESSION_KEY2));
|
|
2011
|
+
__privateGet(this, _HandleAuthenticateEvent2).call(this, null);
|
|
2012
|
+
try {
|
|
2013
|
+
const rConfig = {
|
|
2014
|
+
method: "post",
|
|
2015
|
+
url,
|
|
2016
|
+
data: {
|
|
2017
|
+
sessionId
|
|
2018
|
+
},
|
|
2019
|
+
withCredentials: true,
|
|
2020
|
+
// Ensure cookies are passed to the service
|
|
2021
|
+
timeout: __privateGet(this, _options2).timeout
|
|
2022
|
+
};
|
|
2023
|
+
debug(`#Logout: request config: [${rConfig}]`.magenta);
|
|
2024
|
+
if (isNode) {
|
|
2025
|
+
rConfig.httpsAgent = __privateGet(this, _httpsAgent);
|
|
2026
|
+
}
|
|
2027
|
+
const retVal = await axios(rConfig);
|
|
2028
|
+
if (retVal.data.status === StatusCodes.OK) {
|
|
2029
|
+
return true;
|
|
2030
|
+
} else {
|
|
2031
|
+
console.log("Error during logout (1: server side)");
|
|
2032
|
+
console.log(JSON.stringify(retVal.data));
|
|
2033
|
+
return false;
|
|
2034
|
+
}
|
|
2035
|
+
} catch (error) {
|
|
2036
|
+
console.log("Error during logout (2: server side)");
|
|
2037
|
+
console.log(error);
|
|
2038
|
+
console.log(JSON.stringify(error));
|
|
2039
|
+
return false;
|
|
2040
|
+
}
|
|
2041
|
+
} else {
|
|
2042
|
+
console.log("Error during logout. Could not restore session from session storage.");
|
|
2043
|
+
return false;
|
|
2044
|
+
}
|
|
2045
|
+
});
|
|
2046
|
+
Debug.enable("proc:*");
|
|
2047
|
+
__privateSet(this, _options2, options);
|
|
2048
|
+
debug(`STSOAuth2Worker:constructor:#options: [${JSON.stringify(__privateGet(this, _options2))}]`);
|
|
2049
|
+
__privateSet(this, _clientSessionStore, new stsvueutils.ClientStorageFactory({ clientStorageType: stsvueutils.ClientStorageType.MEMORY_STORAGE, usePrefix: false }).GetStorage());
|
|
2050
|
+
__privateSet(this, _oauthWorkerPort, workerPort);
|
|
2051
|
+
debug(`STSOAuth2Worker:constructor:#oauthWorkerPort: [${JSON.stringify(__privateGet(this, _oauthWorkerPort))}]`);
|
|
2052
|
+
if (isNode && __privateGet(this, _options2).agentOptions) {
|
|
2053
|
+
__privateSet(this, _httpsAgent, new https.Agent({
|
|
2054
|
+
keepAlive: __privateGet(this, _options2).agentOptions.keepAlive,
|
|
2055
|
+
maxSockets: __privateGet(this, _options2).agentOptions.maxSockets,
|
|
2056
|
+
maxTotalSockets: __privateGet(this, _options2).agentOptions.maxTotalSockets,
|
|
2057
|
+
maxFreeSockets: __privateGet(this, _options2).agentOptions.maxFreeSockets,
|
|
2058
|
+
timeout: __privateGet(this, _options2).timeout,
|
|
2059
|
+
rejectUnauthorized: __privateGet(this, _options2).agentOptions.rejectUnauthorized
|
|
2060
|
+
// Allows self-signed certificates if non-production
|
|
2061
|
+
}));
|
|
2062
|
+
}
|
|
2063
|
+
this.SetupListener();
|
|
2064
|
+
__privateGet(this, _UpdateInstrument).call(this, stsinstrumentation.Gauge.LOGGER, {
|
|
2065
|
+
LogMessage: `STSOauth2 Plugin - Successfully Loaded`
|
|
2066
|
+
});
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
_clientSessionStore = new WeakMap();
|
|
2070
|
+
_cUtils2 = new WeakMap();
|
|
2071
|
+
_qParams2 = new WeakMap();
|
|
2072
|
+
_STORAGE_SESSION_KEY2 = new WeakMap();
|
|
2073
|
+
_oauthWorkerPort = new WeakMap();
|
|
2074
|
+
_options2 = new WeakMap();
|
|
2075
|
+
_httpsAgent = new WeakMap();
|
|
2076
|
+
_HandleAuthenticateEvent2 = new WeakMap();
|
|
2077
|
+
_HandleErrorEvent2 = new WeakMap();
|
|
2078
|
+
_LogMessage = new WeakMap();
|
|
2079
|
+
_GetAccessToken = new WeakMap();
|
|
2080
|
+
_GetCookies = new WeakMap();
|
|
2081
|
+
_UpdateInstrument = new WeakMap();
|
|
2082
|
+
_ProcessCommand = new WeakMap();
|
|
2083
|
+
_RestoreSession = new WeakMap();
|
|
2084
|
+
_Authorize = new WeakMap();
|
|
2085
|
+
_HandleRedirect = new WeakMap();
|
|
2086
|
+
_GetTokenFromBroker = new WeakMap();
|
|
2087
|
+
_GetToken = new WeakMap();
|
|
2088
|
+
_RefreshToken = new WeakMap();
|
|
2089
|
+
_Logout = new WeakMap();
|
|
2090
|
+
const TestStore = pinia.defineStore("__sts__TestStore", {
|
|
2091
|
+
state: () => {
|
|
2092
|
+
return {
|
|
2093
|
+
count: 0
|
|
2094
|
+
};
|
|
2095
|
+
},
|
|
2096
|
+
actions: {
|
|
2097
|
+
UpdateCount() {
|
|
2098
|
+
this.count++;
|
|
2099
|
+
}
|
|
2100
|
+
},
|
|
2101
|
+
getters: {
|
|
2102
|
+
CountXX: (state) => {
|
|
2103
|
+
return state.count * 2;
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2106
|
+
/*
|
|
2107
|
+
persist: {
|
|
2108
|
+
storage: globalThis.sessionStorage
|
|
2109
|
+
}
|
|
2110
|
+
*/
|
|
2111
|
+
});
|
|
2112
|
+
const useSTSOAuth2ManagerPlugin = () => vue.inject(STSOAuth2ManagerPluginKey);
|
|
2113
|
+
const STSOAuth2ManagerPlugin = {
|
|
2114
|
+
install: (app, options) => {
|
|
2115
|
+
const om = new STSOAuth2Manager(app, options);
|
|
2116
|
+
if (!app.config.globalProperties.$sts) {
|
|
2117
|
+
app.config.globalProperties.$sts = {};
|
|
2118
|
+
}
|
|
2119
|
+
app.config.globalProperties.$sts[STSOAuth2ManagerPluginKey] = om;
|
|
2120
|
+
app.provide(STSOAuth2ManagerPluginKey, om);
|
|
2121
|
+
}
|
|
2122
|
+
};
|
|
2123
|
+
exports2.AuthorizeOptionsResponseMode = AuthorizeOptionsResponseMode;
|
|
2124
|
+
exports2.AuthorizeOptionsResponseType = AuthorizeOptionsResponseType;
|
|
2125
|
+
exports2.IOauth2ListenerCommand = IOauth2ListenerCommand;
|
|
2126
|
+
exports2.OAuthGrantTypes = OAuthGrantTypes;
|
|
2127
|
+
exports2.STSOAuth2Manager = STSOAuth2Manager;
|
|
2128
|
+
exports2.STSOAuth2ManagerPlugin = STSOAuth2ManagerPlugin;
|
|
2129
|
+
exports2.STSOAuth2ManagerPluginKey = STSOAuth2ManagerPluginKey;
|
|
2130
|
+
exports2.STSOAuth2Worker = STSOAuth2Worker;
|
|
2131
|
+
exports2.STSOauth2Store = STSOauth2Store;
|
|
2132
|
+
exports2.TestStore = TestStore;
|
|
2133
|
+
exports2.useSTSOAuth2ManagerPlugin = useSTSOAuth2ManagerPlugin;
|
|
2134
|
+
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
|
|
2135
|
+
});
|
|
2
2136
|
//# sourceMappingURL=stsoauth2plugin.umd.js.map
|