@alien_org/sso-sdk-core 1.0.22 → 1.0.23
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/index.cjs +1 -1
- package/dist/index.esm.js +25 -27
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var h=(
|
|
1
|
+
"use strict";var h=(u,e,o)=>new Promise((r,s)=>{var a=l=>{try{c(o.next(l))}catch(S){s(S)}},n=l=>{try{c(o.throw(l))}catch(S){s(S)}},c=l=>l.done?r(l.value):Promise.resolve(l.value).then(a,n);c((o=o.apply(u,e)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("zod/v4-mini"),I=require("js-sha256"),y=t.z.object({deep_link:t.z.string(),polling_code:t.z.string(),expired_at:t.z.number()}),T=t.z.object({polling_code:t.z.string()}),j=["pending","authorized","rejected","expired"],x=t.z.enum(j),z=t.z.object({status:x,authorization_code:t.z.optional(t.z.string())}),m=t.z.object({access_token:t.z.string(),token_type:t.z.string(),expires_in:t.z.number(),id_token:t.z.optional(t.z.string()),refresh_token:t.z.string()}),R=t.z.object({sub:t.z.string()}),A=t.z.object({iss:t.z.string(),sub:t.z.string(),aud:t.z.union([t.z.string(),t.z.array(t.z.string())]),exp:t.z.number(),iat:t.z.number(),nonce:t.z.optional(t.z.string()),auth_time:t.z.optional(t.z.number())}),E=m;function _(u){return btoa(u).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function w(u){let e=u.replace(/-/g,"+").replace(/_/g,"/");for(;e.length%4;)e+="=";return atob(e)}const v="https://sso.alien.com",P=5e3,i="alien-sso_",g=i+"refresh_token",p=i+"token_expiry",f=(u,e)=>new URL(e,u).toString(),b=t.z.object({ssoBaseUrl:t.z.url(),providerAddress:t.z.string(),pollingInterval:t.z.optional(t.z.number())}),d=class d{constructor(e){this.config=b.parse(e),this.ssoBaseUrl=this.config.ssoBaseUrl||v,this.providerAddress=this.config.providerAddress,this.pollingInterval=this.config.pollingInterval||P}generateCodeVerifier(e=128){let o;const r=typeof window!="undefined"&&window.crypto;if(r&&r.getRandomValues)o=new Uint8Array(e),r.getRandomValues(o);else{o=new Uint8Array(e);for(let a=0;a<e;a++)o[a]=Math.floor(Math.random()*256)}let s="";for(let a=0;a<o.length;a++)s+=String.fromCharCode(o[a]);return _(s)}generateCodeChallenge(e){const o=I.sha256.array(e),r=String.fromCharCode(...o);return _(r)}generateDeeplink(){return h(this,null,function*(){const e=this.generateCodeVerifier(),o=this.generateCodeChallenge(e);sessionStorage.setItem(i+"code_verifier",e);const r=new URLSearchParams({response_type:"code",response_mode:"json",client_id:this.providerAddress,scope:"openid",code_challenge:o,code_challenge_method:"S256"}),s=`${this.config.ssoBaseUrl}/oauth/authorize?${r.toString()}`,a=yield fetch(s,{method:"GET"});if(!a.ok){const c=yield a.json().catch(()=>({error:a.statusText}));throw new Error(`Authorize failed: ${c.error_description||c.error||a.statusText}`)}const n=yield a.json();return y.parse(n)})}pollAuth(e){return h(this,null,function*(){const o={polling_code:e};T.parse(o);const r=yield fetch(f(this.config.ssoBaseUrl,"/oauth/poll"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});if(!r.ok)throw new Error(`Poll failed: ${r.statusText}`);const s=yield r.json();return z.parse(s)})}exchangeToken(e){return h(this,null,function*(){const o=sessionStorage.getItem(i+"code_verifier");if(!o)throw new Error("Missing code verifier.");const r=new URLSearchParams({grant_type:"authorization_code",code:e,client_id:this.providerAddress,code_verifier:o}),s=yield fetch(f(this.config.ssoBaseUrl,"/oauth/token"),{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:r.toString()});if(!s.ok){const l=yield s.json().catch(()=>({error:s.statusText}));throw new Error(`Token exchange failed: ${l.error_description||l.error||s.statusText}`)}const a=yield s.json(),n=m.parse(a);localStorage.setItem(i+"access_token",n.access_token),n.id_token&&localStorage.setItem(i+"id_token",n.id_token),localStorage.setItem(g,n.refresh_token);const c=Date.now()+n.expires_in*1e3;return localStorage.setItem(p,c.toString()),sessionStorage.removeItem(i+"code_verifier"),n})}verifyAuth(){return h(this,null,function*(){return this.withAutoRefresh(()=>h(this,null,function*(){const e=this.getAccessToken();if(!e)return null;const o=yield fetch(f(this.config.ssoBaseUrl,"/oauth/userinfo"),{method:"GET",headers:{Authorization:`Bearer ${e}`}});if(!o.ok){if(o.status===401){const s=new Error("Unauthorized");throw s.response={status:401},s}return null}const r=yield o.json();return R.parse(r)}))})}getAccessToken(){return localStorage.getItem(i+"access_token")}getIdToken(){return localStorage.getItem(i+"id_token")}getAuthData(){const e=this.getIdToken()||this.getAccessToken();if(!e)return null;const o=e.split(".");if(o.length!==3)return null;let r;try{const n=w(o[0]);r=JSON.parse(n)}catch(n){return null}if(r.alg!=="RS256"||r.typ!=="JWT")return null;let s;try{const n=JSON.parse(w(o[1]));s=A.parse(n)}catch(n){return null}return(Array.isArray(s.aud)?s.aud:[s.aud]).includes(this.providerAddress)?s:null}getSubject(){const e=this.getAuthData();return(e==null?void 0:e.sub)||null}isTokenExpired(){const e=this.getAuthData();return e?Date.now()/1e3>e.exp:!0}logout(){localStorage.removeItem(i+"access_token"),localStorage.removeItem(i+"id_token"),localStorage.removeItem(g),localStorage.removeItem(p),sessionStorage.removeItem(i+"code_verifier")}getRefreshToken(){return localStorage.getItem(g)}hasRefreshToken(){return!!this.getRefreshToken()}isAccessTokenExpired(){const e=localStorage.getItem(p);if(!e)return!0;const o=parseInt(e,10),r=Date.now(),s=300*1e3;return r>=o-s}refreshAccessToken(){return h(this,null,function*(){return d.refreshPromise||(d.refreshPromise=this.doRefreshAccessToken().finally(()=>{d.refreshPromise=null})),d.refreshPromise})}doRefreshAccessToken(){return h(this,null,function*(){const e=this.getRefreshToken();if(!e)throw new Error("No refresh token available");const o=new URLSearchParams({grant_type:"refresh_token",refresh_token:e,client_id:this.providerAddress}),r=yield fetch(f(this.config.ssoBaseUrl,"/oauth/token"),{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:o.toString()});if(!r.ok){const c=yield r.json().catch(()=>({error:r.statusText}));throw this.logout(),new Error(`Token refresh failed: ${c.error_description||c.error||r.statusText}`)}const s=yield r.json(),a=m.parse(s);localStorage.setItem(i+"access_token",a.access_token),a.id_token&&localStorage.setItem(i+"id_token",a.id_token),localStorage.setItem(g,a.refresh_token);const n=Date.now()+a.expires_in*1e3;return localStorage.setItem(p,n.toString()),a})}withAutoRefresh(e,o=1){return h(this,null,function*(){var r,s,a;try{return yield e()}catch(n){if((((r=n==null?void 0:n.response)==null?void 0:r.status)===401||((s=n==null?void 0:n.message)==null?void 0:s.includes("401"))||((a=n==null?void 0:n.message)==null?void 0:a.includes("Unauthorized")))&&o>0&&this.hasRefreshToken())try{return yield this.refreshAccessToken(),yield e()}catch(l){throw n}throw n}})}};d.refreshPromise=null;let k=d;exports.AlienSsoClient=k;exports.AlienSsoClientSchema=b;exports.AuthorizeResponseSchema=y;exports.ExchangeCodeResponseSchema=E;exports.PollRequestSchema=T;exports.PollResponseSchema=z;exports.TokenInfoSchema=A;exports.TokenResponseSchema=m;exports.UserInfoResponseSchema=R;
|
package/dist/index.esm.js
CHANGED
|
@@ -20,10 +20,10 @@ const T = t.object({
|
|
|
20
20
|
deep_link: t.string(),
|
|
21
21
|
polling_code: t.string(),
|
|
22
22
|
expired_at: t.number()
|
|
23
|
-
}),
|
|
23
|
+
}), b = t.object({
|
|
24
24
|
polling_code: t.string()
|
|
25
|
-
}),
|
|
26
|
-
status:
|
|
25
|
+
}), A = ["pending", "authorized", "rejected", "expired"], I = t.enum(A), R = t.object({
|
|
26
|
+
status: I,
|
|
27
27
|
authorization_code: t.optional(t.string())
|
|
28
28
|
}), k = t.object({
|
|
29
29
|
access_token: t.string(),
|
|
@@ -32,9 +32,9 @@ const T = t.object({
|
|
|
32
32
|
id_token: t.optional(t.string()),
|
|
33
33
|
// Optional - not returned on refresh_token grant
|
|
34
34
|
refresh_token: t.string()
|
|
35
|
-
}), j = t.object({
|
|
36
|
-
sub: t.string()
|
|
37
35
|
}), x = t.object({
|
|
36
|
+
sub: t.string()
|
|
37
|
+
}), j = t.object({
|
|
38
38
|
iss: t.string(),
|
|
39
39
|
sub: t.string(),
|
|
40
40
|
aud: t.union([t.string(), t.array(t.string())]),
|
|
@@ -43,10 +43,10 @@ const T = t.object({
|
|
|
43
43
|
nonce: t.optional(t.string()),
|
|
44
44
|
auth_time: t.optional(t.number())
|
|
45
45
|
}), z = k;
|
|
46
|
-
function
|
|
46
|
+
function _(u) {
|
|
47
47
|
return btoa(u).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
48
48
|
}
|
|
49
|
-
function
|
|
49
|
+
function w(u) {
|
|
50
50
|
let e = u.replace(/-/g, "+").replace(/_/g, "/");
|
|
51
51
|
for (; e.length % 4; )
|
|
52
52
|
e += "=";
|
|
@@ -73,11 +73,11 @@ const E = "https://sso.alien.com", v = 5e3, i = "alien-sso_", g = i + "refresh_t
|
|
|
73
73
|
let s = "";
|
|
74
74
|
for (let a = 0; a < o.length; a++)
|
|
75
75
|
s += String.fromCharCode(o[a]);
|
|
76
|
-
return
|
|
76
|
+
return _(s);
|
|
77
77
|
}
|
|
78
78
|
generateCodeChallenge(e) {
|
|
79
79
|
const o = y.array(e), r = String.fromCharCode(...o);
|
|
80
|
-
return
|
|
80
|
+
return _(r);
|
|
81
81
|
}
|
|
82
82
|
/**
|
|
83
83
|
* Initiates OAuth2 authorization flow with response_mode=json for SPA
|
|
@@ -114,7 +114,7 @@ const E = "https://sso.alien.com", v = 5e3, i = "alien-sso_", g = i + "refresh_t
|
|
|
114
114
|
const o = {
|
|
115
115
|
polling_code: e
|
|
116
116
|
};
|
|
117
|
-
|
|
117
|
+
b.parse(o);
|
|
118
118
|
const r = yield fetch(f(this.config.ssoBaseUrl, "/oauth/poll"), {
|
|
119
119
|
method: "POST",
|
|
120
120
|
headers: {
|
|
@@ -125,7 +125,7 @@ const E = "https://sso.alien.com", v = 5e3, i = "alien-sso_", g = i + "refresh_t
|
|
|
125
125
|
if (!r.ok)
|
|
126
126
|
throw new Error(`Poll failed: ${r.statusText}`);
|
|
127
127
|
const s = yield r.json();
|
|
128
|
-
return
|
|
128
|
+
return R.parse(s);
|
|
129
129
|
});
|
|
130
130
|
}
|
|
131
131
|
/**
|
|
@@ -190,7 +190,7 @@ const E = "https://sso.alien.com", v = 5e3, i = "alien-sso_", g = i + "refresh_t
|
|
|
190
190
|
return null;
|
|
191
191
|
}
|
|
192
192
|
const r = yield o.json();
|
|
193
|
-
return
|
|
193
|
+
return x.parse(r);
|
|
194
194
|
}));
|
|
195
195
|
});
|
|
196
196
|
}
|
|
@@ -218,7 +218,7 @@ const E = "https://sso.alien.com", v = 5e3, i = "alien-sso_", g = i + "refresh_t
|
|
|
218
218
|
return null;
|
|
219
219
|
let r;
|
|
220
220
|
try {
|
|
221
|
-
const n =
|
|
221
|
+
const n = w(o[0]);
|
|
222
222
|
r = JSON.parse(n);
|
|
223
223
|
} catch (n) {
|
|
224
224
|
return null;
|
|
@@ -227,8 +227,8 @@ const E = "https://sso.alien.com", v = 5e3, i = "alien-sso_", g = i + "refresh_t
|
|
|
227
227
|
return null;
|
|
228
228
|
let s;
|
|
229
229
|
try {
|
|
230
|
-
const n = JSON.parse(
|
|
231
|
-
s =
|
|
230
|
+
const n = JSON.parse(w(o[1]));
|
|
231
|
+
s = j.parse(n);
|
|
232
232
|
} catch (n) {
|
|
233
233
|
return null;
|
|
234
234
|
}
|
|
@@ -293,7 +293,7 @@ const E = "https://sso.alien.com", v = 5e3, i = "alien-sso_", g = i + "refresh_t
|
|
|
293
293
|
doRefreshAccessToken() {
|
|
294
294
|
return h(this, null, function* () {
|
|
295
295
|
const e = this.getRefreshToken();
|
|
296
|
-
if (
|
|
296
|
+
if (!e)
|
|
297
297
|
throw new Error("No refresh token available");
|
|
298
298
|
const o = new URLSearchParams({
|
|
299
299
|
grant_type: "refresh_token",
|
|
@@ -309,13 +309,11 @@ const E = "https://sso.alien.com", v = 5e3, i = "alien-sso_", g = i + "refresh_t
|
|
|
309
309
|
body: o.toString()
|
|
310
310
|
}
|
|
311
311
|
);
|
|
312
|
-
if (
|
|
312
|
+
if (!r.ok) {
|
|
313
313
|
const c = yield r.json().catch(() => ({ error: r.statusText }));
|
|
314
|
-
throw
|
|
314
|
+
throw this.logout(), new Error(`Token refresh failed: ${c.error_description || c.error || r.statusText}`);
|
|
315
315
|
}
|
|
316
|
-
const s = yield r.json();
|
|
317
|
-
console.log("[AlienSsoClient] /oauth/token json keys:", Object.keys(s));
|
|
318
|
-
const a = k.parse(s);
|
|
316
|
+
const s = yield r.json(), a = k.parse(s);
|
|
319
317
|
localStorage.setItem(i + "access_token", a.access_token), a.id_token && localStorage.setItem(i + "id_token", a.id_token), localStorage.setItem(g, a.refresh_token);
|
|
320
318
|
const n = Date.now() + a.expires_in * 1e3;
|
|
321
319
|
return localStorage.setItem(p, n.toString()), a;
|
|
@@ -343,15 +341,15 @@ const E = "https://sso.alien.com", v = 5e3, i = "alien-sso_", g = i + "refresh_t
|
|
|
343
341
|
}
|
|
344
342
|
};
|
|
345
343
|
d.refreshPromise = null;
|
|
346
|
-
let
|
|
344
|
+
let S = d;
|
|
347
345
|
export {
|
|
348
|
-
|
|
346
|
+
S as AlienSsoClient,
|
|
349
347
|
U as AlienSsoClientSchema,
|
|
350
348
|
T as AuthorizeResponseSchema,
|
|
351
349
|
z as ExchangeCodeResponseSchema,
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
350
|
+
b as PollRequestSchema,
|
|
351
|
+
R as PollResponseSchema,
|
|
352
|
+
j as TokenInfoSchema,
|
|
355
353
|
k as TokenResponseSchema,
|
|
356
|
-
|
|
354
|
+
x as UserInfoResponseSchema
|
|
357
355
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(c,
|
|
1
|
+
(function(c,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("zod/v4-mini"),require("js-sha256")):typeof define=="function"&&define.amd?define(["exports","zod/v4-mini","js-sha256"],e):(c=typeof globalThis!="undefined"?globalThis:c||self,e(c.AlienSsoCore={},c.Zod,c.jsSha256))})(this,(function(c,e,f){"use strict";var h=(c,e,f)=>new Promise((k,m)=>{var T=l=>{try{g(f.next(l))}catch(p){m(p)}},z=l=>{try{g(f.throw(l))}catch(p){m(p)}},g=l=>l.done?k(l.value):Promise.resolve(l.value).then(T,z);g((f=f.apply(c,e)).next())});const k=e.z.object({deep_link:e.z.string(),polling_code:e.z.string(),expired_at:e.z.number()}),m=e.z.object({polling_code:e.z.string()}),T=["pending","authorized","rejected","expired"],z=e.z.enum(T),g=e.z.object({status:z,authorization_code:e.z.optional(e.z.string())}),l=e.z.object({access_token:e.z.string(),token_type:e.z.string(),expires_in:e.z.number(),id_token:e.z.optional(e.z.string()),refresh_token:e.z.string()}),p=e.z.object({sub:e.z.string()}),b=e.z.object({iss:e.z.string(),sub:e.z.string(),aud:e.z.union([e.z.string(),e.z.array(e.z.string())]),exp:e.z.number(),iat:e.z.number(),nonce:e.z.optional(e.z.string()),auth_time:e.z.optional(e.z.number())}),P=l;function I(S){return btoa(S).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function j(S){let t=S.replace(/-/g,"+").replace(/_/g,"/");for(;t.length%4;)t+="=";return atob(t)}const x="https://sso.alien.com",U=5e3,i="alien-sso_",_=i+"refresh_token",w=i+"token_expiry",y=(S,t)=>new URL(t,S).toString(),E=e.z.object({ssoBaseUrl:e.z.url(),providerAddress:e.z.string(),pollingInterval:e.z.optional(e.z.number())}),d=class d{constructor(t){this.config=E.parse(t),this.ssoBaseUrl=this.config.ssoBaseUrl||x,this.providerAddress=this.config.providerAddress,this.pollingInterval=this.config.pollingInterval||U}generateCodeVerifier(t=128){let o;const r=typeof window!="undefined"&&window.crypto;if(r&&r.getRandomValues)o=new Uint8Array(t),r.getRandomValues(o);else{o=new Uint8Array(t);for(let a=0;a<t;a++)o[a]=Math.floor(Math.random()*256)}let s="";for(let a=0;a<o.length;a++)s+=String.fromCharCode(o[a]);return I(s)}generateCodeChallenge(t){const o=f.sha256.array(t),r=String.fromCharCode(...o);return I(r)}generateDeeplink(){return h(this,null,function*(){const t=this.generateCodeVerifier(),o=this.generateCodeChallenge(t);sessionStorage.setItem(i+"code_verifier",t);const r=new URLSearchParams({response_type:"code",response_mode:"json",client_id:this.providerAddress,scope:"openid",code_challenge:o,code_challenge_method:"S256"}),s=`${this.config.ssoBaseUrl}/oauth/authorize?${r.toString()}`,a=yield fetch(s,{method:"GET"});if(!a.ok){const u=yield a.json().catch(()=>({error:a.statusText}));throw new Error(`Authorize failed: ${u.error_description||u.error||a.statusText}`)}const n=yield a.json();return k.parse(n)})}pollAuth(t){return h(this,null,function*(){const o={polling_code:t};m.parse(o);const r=yield fetch(y(this.config.ssoBaseUrl,"/oauth/poll"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});if(!r.ok)throw new Error(`Poll failed: ${r.statusText}`);const s=yield r.json();return g.parse(s)})}exchangeToken(t){return h(this,null,function*(){const o=sessionStorage.getItem(i+"code_verifier");if(!o)throw new Error("Missing code verifier.");const r=new URLSearchParams({grant_type:"authorization_code",code:t,client_id:this.providerAddress,code_verifier:o}),s=yield fetch(y(this.config.ssoBaseUrl,"/oauth/token"),{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:r.toString()});if(!s.ok){const R=yield s.json().catch(()=>({error:s.statusText}));throw new Error(`Token exchange failed: ${R.error_description||R.error||s.statusText}`)}const a=yield s.json(),n=l.parse(a);localStorage.setItem(i+"access_token",n.access_token),n.id_token&&localStorage.setItem(i+"id_token",n.id_token),localStorage.setItem(_,n.refresh_token);const u=Date.now()+n.expires_in*1e3;return localStorage.setItem(w,u.toString()),sessionStorage.removeItem(i+"code_verifier"),n})}verifyAuth(){return h(this,null,function*(){return this.withAutoRefresh(()=>h(this,null,function*(){const t=this.getAccessToken();if(!t)return null;const o=yield fetch(y(this.config.ssoBaseUrl,"/oauth/userinfo"),{method:"GET",headers:{Authorization:`Bearer ${t}`}});if(!o.ok){if(o.status===401){const s=new Error("Unauthorized");throw s.response={status:401},s}return null}const r=yield o.json();return p.parse(r)}))})}getAccessToken(){return localStorage.getItem(i+"access_token")}getIdToken(){return localStorage.getItem(i+"id_token")}getAuthData(){const t=this.getIdToken()||this.getAccessToken();if(!t)return null;const o=t.split(".");if(o.length!==3)return null;let r;try{const n=j(o[0]);r=JSON.parse(n)}catch(n){return null}if(r.alg!=="RS256"||r.typ!=="JWT")return null;let s;try{const n=JSON.parse(j(o[1]));s=b.parse(n)}catch(n){return null}return(Array.isArray(s.aud)?s.aud:[s.aud]).includes(this.providerAddress)?s:null}getSubject(){const t=this.getAuthData();return(t==null?void 0:t.sub)||null}isTokenExpired(){const t=this.getAuthData();return t?Date.now()/1e3>t.exp:!0}logout(){localStorage.removeItem(i+"access_token"),localStorage.removeItem(i+"id_token"),localStorage.removeItem(_),localStorage.removeItem(w),sessionStorage.removeItem(i+"code_verifier")}getRefreshToken(){return localStorage.getItem(_)}hasRefreshToken(){return!!this.getRefreshToken()}isAccessTokenExpired(){const t=localStorage.getItem(w);if(!t)return!0;const o=parseInt(t,10),r=Date.now(),s=300*1e3;return r>=o-s}refreshAccessToken(){return h(this,null,function*(){return d.refreshPromise||(d.refreshPromise=this.doRefreshAccessToken().finally(()=>{d.refreshPromise=null})),d.refreshPromise})}doRefreshAccessToken(){return h(this,null,function*(){const t=this.getRefreshToken();if(!t)throw new Error("No refresh token available");const o=new URLSearchParams({grant_type:"refresh_token",refresh_token:t,client_id:this.providerAddress}),r=yield fetch(y(this.config.ssoBaseUrl,"/oauth/token"),{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:o.toString()});if(!r.ok){const u=yield r.json().catch(()=>({error:r.statusText}));throw this.logout(),new Error(`Token refresh failed: ${u.error_description||u.error||r.statusText}`)}const s=yield r.json(),a=l.parse(s);localStorage.setItem(i+"access_token",a.access_token),a.id_token&&localStorage.setItem(i+"id_token",a.id_token),localStorage.setItem(_,a.refresh_token);const n=Date.now()+a.expires_in*1e3;return localStorage.setItem(w,n.toString()),a})}withAutoRefresh(t,o=1){return h(this,null,function*(){var r,s,a;try{return yield t()}catch(n){if((((r=n==null?void 0:n.response)==null?void 0:r.status)===401||((s=n==null?void 0:n.message)==null?void 0:s.includes("401"))||((a=n==null?void 0:n.message)==null?void 0:a.includes("Unauthorized")))&&o>0&&this.hasRefreshToken())try{return yield this.refreshAccessToken(),yield t()}catch(R){throw n}throw n}})}};d.refreshPromise=null;let A=d;c.AlienSsoClient=A,c.AlienSsoClientSchema=E,c.AuthorizeResponseSchema=k,c.ExchangeCodeResponseSchema=P,c.PollRequestSchema=m,c.PollResponseSchema=g,c.TokenInfoSchema=b,c.TokenResponseSchema=l,c.UserInfoResponseSchema=p,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})}));
|