oiu-core1 0.1.16 → 0.1.18
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/auth/_type.d.ts +10 -1
- package/dist/auth/_type.d.ts.map +1 -1
- package/dist/index-DRS773v7.js +223 -0
- package/dist/main-CFABqmuT.js +4172 -0
- package/dist/main.js +1 -1
- package/package.json +2 -4
- package/dist/index-D5juBzHq.js +0 -2659
- package/dist/main-FWBSwGGL.js +0 -19770
package/dist/auth/_type.d.ts
CHANGED
|
@@ -71,6 +71,11 @@ export interface IAuthService {
|
|
|
71
71
|
* @param identity: if true, clear the identity information and remove the token from the storage
|
|
72
72
|
*/
|
|
73
73
|
clear(identity?: boolean): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Reload the identity information. This is use to refresh the token or get the user information.
|
|
76
|
+
* This method will trigger the subscribe callback with the event 'reload' and the new identity information
|
|
77
|
+
*/
|
|
78
|
+
reload(): Promise<Identity | undefined>;
|
|
74
79
|
/**
|
|
75
80
|
* Start the sign in process
|
|
76
81
|
* @param state state to be passed to the authentication provider
|
|
@@ -124,7 +129,6 @@ export declare abstract class AuthService implements IAuthService {
|
|
|
124
129
|
abstract getUnsafeInstance(): unknown;
|
|
125
130
|
abstract getIdentity(): Promise<Identity | undefined>;
|
|
126
131
|
abstract getUser(): Promise<unknown | null>;
|
|
127
|
-
abstract clear(identity?: boolean): Promise<void>;
|
|
128
132
|
abstract signIn(state?: unknown, args?: unknown, onFeedback?: (feedback: string) => void, explicit?: boolean): Promise<AuthResult>;
|
|
129
133
|
abstract completeSignIn(url?: string): Promise<AuthResult>;
|
|
130
134
|
abstract silentSignIn(state?: unknown, args?: unknown): Promise<AuthResult | undefined>;
|
|
@@ -132,11 +136,16 @@ export declare abstract class AuthService implements IAuthService {
|
|
|
132
136
|
abstract signOut(state?: unknown): Promise<AuthResult>;
|
|
133
137
|
abstract completeSignOut(url?: string): Promise<AuthResult>;
|
|
134
138
|
/** @inheritdoc */
|
|
139
|
+
clear(identity?: boolean): Promise<void>;
|
|
140
|
+
/** @inheritdoc */
|
|
141
|
+
reload(): Promise<Identity | undefined>;
|
|
142
|
+
/** @inheritdoc */
|
|
135
143
|
isAuthenticated(): Promise<boolean>;
|
|
136
144
|
/** @inheritdoc */
|
|
137
145
|
unsubscribe(subscriptionId: number): void;
|
|
138
146
|
/** @inheritdoc */
|
|
139
147
|
subscribe(callback: CallbackFn): number;
|
|
148
|
+
/** @inheritdoc */
|
|
140
149
|
protected _notifySubscribers(event: string, identity?: Identity): void;
|
|
141
150
|
}
|
|
142
151
|
/** Dummy authentication service for testing purposes */
|
package/dist/auth/_type.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_type.d.ts","sourceRoot":"","sources":["../../lib/auth/_type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAIvC,MAAM,MAAM,UAAU,GAAG;IACrB,aAAa;IACb,CAAC,EAAE,MAAM,CAAC;IACV,cAAc;IACd,CAAC,EAAE,MAAM,CAAC;IACV,4CAA4C;IAC5C,CAAC,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AACF,mCAAmC;AACnC,MAAM,MAAM,SAAS,GAAG;IACpB,EAAE,EAAE,IAAI,CAAC;IACT,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,EAAE,CAAC;CASnB,CAAC;AACF,2CAA2C;AAC3C,MAAM,MAAM,QAAQ,CAAC,CAAC,GAAG,SAAS,IAAI;IAClC,mDAAmD;IACnD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uEAAuE;IACvE,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,wDAAwD;IACxD,YAAY,CAA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,CAAC,cAAc,EAAE,MAAM;IAMzC,kBAAkB;IACX,SAAS,CAAC,QAAQ,EAAE,UAAU;IAMrC,kBAAkB;IAClB,SAAS,CAAC,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,QAAQ;CAMlE;AAED,wDAAwD;AACxD,qBAAa,gBAAiB,SAAQ,WAAW;gBACjC,QAAQ,CAAC,EAAE,QAAQ;IAI/B,iBAAiB,IAAI,OAAO;IAG5B,WAAW,IAAI,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC;IAG5C,OAAO,IAAI,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAGlC,KAAK,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxC,MAAM,IAAI,OAAO,CAAC,UAAU,CAAC;IAG7B,cAAc,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAGjD,YAAY,IAAI,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAG/C,oBAAoB,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAGvD,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC;IAG9B,eAAe,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;CAGrD"}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { WebStorageStateStore as g, UserManager as h } from "oidc-client-ts";
|
|
2
|
+
import { A as p, P as s, a as o, d as l } from "./main-CFABqmuT.js";
|
|
3
|
+
function w(c, e, t) {
|
|
4
|
+
return new _(c, e, t);
|
|
5
|
+
}
|
|
6
|
+
class _ extends p {
|
|
7
|
+
/**
|
|
8
|
+
* Initialize a new instance of the Auth service
|
|
9
|
+
* @param prefix
|
|
10
|
+
* @param settings
|
|
11
|
+
* @param store
|
|
12
|
+
* @param popupPolicy Popup policy to use for authentication. By default pop ups are disabled
|
|
13
|
+
* because they don't work properly on Edge. If you want to enable pop up authentication simply set this flag to false.
|
|
14
|
+
*/
|
|
15
|
+
constructor(e, t, r) {
|
|
16
|
+
super();
|
|
17
|
+
const { prefix: i, popupPolicy: a = s.Never, onIdentityCreated: n } = r, u = new g({ prefix: i, store: t });
|
|
18
|
+
this._userManager = new h({ ...e, userStore: u }), this._popUpPolicy = a, this._onIdentityCreated = n, this._userManager.events.addUserSignedOut(async () => {
|
|
19
|
+
console.warn("User SignedOut event triggger"), await this._userManager.removeUser(), this._updateState("signedout");
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/** @inheritdoc */
|
|
23
|
+
getUnsafeInstance() {
|
|
24
|
+
return this._userManager;
|
|
25
|
+
}
|
|
26
|
+
/** @inheritdoc */
|
|
27
|
+
getUser() {
|
|
28
|
+
return this._userManager.getUser();
|
|
29
|
+
}
|
|
30
|
+
/** @inheritdoc */
|
|
31
|
+
async getIdentity() {
|
|
32
|
+
if (this._identity) return this._identity;
|
|
33
|
+
const e = await this.getUser(), t = this._getIdentity(e);
|
|
34
|
+
return this._updateState("update", t), t;
|
|
35
|
+
}
|
|
36
|
+
/** @inheritdoc */
|
|
37
|
+
async clear(e) {
|
|
38
|
+
await this._userManager.clearStaleState(), e && (await this._userManager.removeUser(), this._updateState("update"));
|
|
39
|
+
}
|
|
40
|
+
/** @inheritdoc */
|
|
41
|
+
async signIn(e, t, r, i = !1) {
|
|
42
|
+
const a = this._createArguments(e, t);
|
|
43
|
+
if (!i) {
|
|
44
|
+
const n = await this.trySilentSignIn(e, a);
|
|
45
|
+
if (n) return n;
|
|
46
|
+
}
|
|
47
|
+
switch (this._popUpPolicy) {
|
|
48
|
+
case s.Always:
|
|
49
|
+
return await this.tryPopUpSignIn(e, a);
|
|
50
|
+
case s.Never:
|
|
51
|
+
return await this.tryRedirectSignIn(e, a);
|
|
52
|
+
case s.RedirectIfFails: {
|
|
53
|
+
const n = await this.tryPopUpSignIn(e, a);
|
|
54
|
+
return n && n.status !== o.Fail ? n : (r?.("Please authorize the pop up window."), await Promise.delay(5e3), await this.tryRedirectSignIn(e, a));
|
|
55
|
+
}
|
|
56
|
+
default:
|
|
57
|
+
throw new Error(`Invalid popup policy ${this._popUpPolicy}.`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** @inheritdoc */
|
|
61
|
+
async completeSignIn(e) {
|
|
62
|
+
try {
|
|
63
|
+
let t;
|
|
64
|
+
switch (this._popUpPolicy) {
|
|
65
|
+
case s.Always:
|
|
66
|
+
await this._userManager.signinPopupCallback(e);
|
|
67
|
+
break;
|
|
68
|
+
case s.Never:
|
|
69
|
+
t = await this._userManager.signinCallback(e);
|
|
70
|
+
break;
|
|
71
|
+
case s.RedirectIfFails:
|
|
72
|
+
try {
|
|
73
|
+
await this._userManager.signinPopupCallback(e);
|
|
74
|
+
} catch (i) {
|
|
75
|
+
console.warn("Popup is not authorized: ", i), t = await this._userManager.signinCallback(e);
|
|
76
|
+
}
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
t || (t = await this._userManager.getUser());
|
|
80
|
+
const r = this._getIdentity(t);
|
|
81
|
+
return this._updateState("signin", r), this._success(t && t.state);
|
|
82
|
+
} catch (t) {
|
|
83
|
+
return console.error("There was an error signing in: ", t), this._error("There was an error signing in.");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/** @inheritdoc */
|
|
87
|
+
async silentSignIn(e, t) {
|
|
88
|
+
const r = this._createArguments(e, t);
|
|
89
|
+
return await this.trySilentSignIn(e, r);
|
|
90
|
+
}
|
|
91
|
+
/** @inheritdoc */
|
|
92
|
+
async completeSilentSignin(e) {
|
|
93
|
+
try {
|
|
94
|
+
return await this._userManager.signinSilentCallback(e), this._success();
|
|
95
|
+
} catch (t) {
|
|
96
|
+
return console.error("There was an error signing in: ", t), this._error("There was an error signing in.");
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/** @inheritdoc */
|
|
100
|
+
async signOut(e) {
|
|
101
|
+
const t = this._createArguments(e);
|
|
102
|
+
switch (this._popUpPolicy) {
|
|
103
|
+
case s.Always:
|
|
104
|
+
return this.tryPopUpSignOut(e, t);
|
|
105
|
+
case s.Never:
|
|
106
|
+
return this.tryRedirectSignOut(e, t);
|
|
107
|
+
default:
|
|
108
|
+
case s.RedirectIfFails:
|
|
109
|
+
throw new Error("RedirectIfFails is not supported for sign out.");
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/** @inheritdoc */
|
|
113
|
+
async completeSignOut(e) {
|
|
114
|
+
try {
|
|
115
|
+
switch (this._popUpPolicy) {
|
|
116
|
+
case s.Always:
|
|
117
|
+
await this._userManager.signoutPopupCallback(e);
|
|
118
|
+
break;
|
|
119
|
+
case s.Never:
|
|
120
|
+
await this._userManager.signoutCallback(e);
|
|
121
|
+
break;
|
|
122
|
+
case s.RedirectIfFails:
|
|
123
|
+
throw new Error("RedirectIfFails is not supported for sign out.");
|
|
124
|
+
}
|
|
125
|
+
return this._updateState("signout"), this._success();
|
|
126
|
+
} catch (t) {
|
|
127
|
+
const r = t;
|
|
128
|
+
return console.error(`There was an error trying to log out '${t}'.`), this._error(r.message);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// #region ========================================= Protected =========================================
|
|
132
|
+
async trySilentSignIn(e, t) {
|
|
133
|
+
console.log("Try silent sign in");
|
|
134
|
+
try {
|
|
135
|
+
const r = await this._userManager.signinSilent({
|
|
136
|
+
extraQueryParams: t
|
|
137
|
+
}), i = this._getIdentity(r);
|
|
138
|
+
return this._updateState("silentSignIn", i), this._success(e);
|
|
139
|
+
} catch (r) {
|
|
140
|
+
console.warn("Silent authentication error: ", r);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
async tryRedirectSignIn(e, t) {
|
|
144
|
+
console.log("Try redirect sign in");
|
|
145
|
+
try {
|
|
146
|
+
return await this._userManager.signinRedirect(t), this._redirect(e);
|
|
147
|
+
} catch (r) {
|
|
148
|
+
return console.error("Redirect authentication error: ", r), this._error(r);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
async tryPopUpSignIn(e, t) {
|
|
152
|
+
console.log("Try popup sign in");
|
|
153
|
+
try {
|
|
154
|
+
const r = await this._userManager.signinPopup(t), i = this._getIdentity(r);
|
|
155
|
+
return this._updateState("popupSignIn", i), this._success(e);
|
|
156
|
+
} catch (r) {
|
|
157
|
+
const i = r;
|
|
158
|
+
return i.message.indexOf("closed") !== -1 && i.message.indexOf("user") ? this._error("The user closed the window.") : this._error("Something went wrong. Please try again later.");
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
async tryPopUpSignOut(e, t) {
|
|
162
|
+
try {
|
|
163
|
+
return await this._userManager.signoutPopup(t), this._updateState("popupSignOut", void 0), this._success(e);
|
|
164
|
+
} catch (r) {
|
|
165
|
+
return console.info("Popup signout error: ", r), this._error("Something went wrong. Try again later.");
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
async tryRedirectSignOut(e, t) {
|
|
169
|
+
try {
|
|
170
|
+
return await this._userManager.signoutRedirect(t), this._redirect(e);
|
|
171
|
+
} catch (r) {
|
|
172
|
+
const i = r;
|
|
173
|
+
return console.error("Redirect signout error: ", r), this._error(i.message);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
// #endregion
|
|
177
|
+
// #region ========================================= Private =========================================
|
|
178
|
+
_getIdentity(e) {
|
|
179
|
+
if (!e) return;
|
|
180
|
+
const t = {
|
|
181
|
+
id_token: e.id_token,
|
|
182
|
+
session_state: e.session_state,
|
|
183
|
+
access_token: e.access_token,
|
|
184
|
+
refresh_token: e.refresh_token,
|
|
185
|
+
token_type: e.token_type,
|
|
186
|
+
scope: e.scope,
|
|
187
|
+
expires_at: e.expires_at ?? 3600,
|
|
188
|
+
profile: {
|
|
189
|
+
id: e.profile.sub,
|
|
190
|
+
firstName: e.profile.given_name ?? "Unknown",
|
|
191
|
+
lastName: e.profile.family_name ?? "Unknown",
|
|
192
|
+
username: e.profile.preferred_username ?? "unknown",
|
|
193
|
+
roles: e.profile.role ?? []
|
|
194
|
+
}
|
|
195
|
+
}, r = l(e.access_token);
|
|
196
|
+
return t.profile.firstName = r.given_name, t.profile.lastName = r.family_name, t.profile.roles = r.role, t.profile.username = r.preferred_username, this._onIdentityCreated?.(t, e, r), t;
|
|
197
|
+
}
|
|
198
|
+
_createArguments(e, t) {
|
|
199
|
+
return {
|
|
200
|
+
// redirectMethod: 'replace',
|
|
201
|
+
// state: state,
|
|
202
|
+
useReplaceToNavigate: !0,
|
|
203
|
+
data: e,
|
|
204
|
+
extraQueryParams: t
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
_success(e) {
|
|
208
|
+
return { status: o.Success, state: e };
|
|
209
|
+
}
|
|
210
|
+
_error(e) {
|
|
211
|
+
return { status: o.Fail, message: e };
|
|
212
|
+
}
|
|
213
|
+
_redirect(e) {
|
|
214
|
+
return { status: o.Redirect, state: e };
|
|
215
|
+
}
|
|
216
|
+
_updateState(e, t) {
|
|
217
|
+
t !== this._identity && (this._identity = t, this._notifySubscribers(e, t));
|
|
218
|
+
}
|
|
219
|
+
// #endregion
|
|
220
|
+
}
|
|
221
|
+
export {
|
|
222
|
+
w as default
|
|
223
|
+
};
|