vuethenticate 0.1.4 → 0.1.5
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/README.md +75 -0
- package/dist/components/AuthCallback.vue.d.ts.map +1 -1
- package/dist/composables/useAuth.d.ts +3 -0
- package/dist/composables/useAuth.d.ts.map +1 -1
- package/dist/index.esm.js +111 -104
- package/dist/index.umd.js +1 -1
- package/dist/types/auth.d.ts +8 -4
- package/dist/types/auth.d.ts.map +1 -1
- package/dist/utils/configHelpers.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
@@ -98,6 +98,7 @@ function onError(error) {
|
|
98
98
|
// router.js
|
99
99
|
import { createRouter, createWebHistory } from 'vue-router'
|
100
100
|
import CallbackPage from './CallbackPage.vue'
|
101
|
+
import LogoutCallbackPage from './LogoutCallbackPage.vue'
|
101
102
|
import SilentCallbackPage from './SilentCallbackPage.vue'
|
102
103
|
|
103
104
|
const routes = [
|
@@ -105,6 +106,10 @@ const routes = [
|
|
105
106
|
path: '/auth/callback',
|
106
107
|
component: CallbackPage
|
107
108
|
},
|
109
|
+
{
|
110
|
+
path: '/auth/logout-callback',
|
111
|
+
component: LogoutCallbackPage
|
112
|
+
},
|
108
113
|
{
|
109
114
|
path: '/auth/silent-callback',
|
110
115
|
component: SilentCallbackPage
|
@@ -264,6 +269,76 @@ Component for handling OAuth callback. **Note**: This component requires `useAut
|
|
264
269
|
| `success` | `User, state?: TState` | Emitted on successful authentication with typed state |
|
265
270
|
| `error` | `Error` | Emitted on authentication error |
|
266
271
|
|
272
|
+
### `<LogoutCallback>`
|
273
|
+
|
274
|
+
Component for handling OAuth logout callback. **Note**: This component requires `useAuth()` to be called in a parent component first.
|
275
|
+
|
276
|
+
#### Props
|
277
|
+
|
278
|
+
| Property | Type | Required | Description |
|
279
|
+
|----------|------|----------|-------------|
|
280
|
+
| `onSuccess` | `(state?: TState) => void` | | Success callback with typed state |
|
281
|
+
| `onError` | `(error: Error) => void` | | Error callback |
|
282
|
+
|
283
|
+
#### Slots
|
284
|
+
|
285
|
+
| Slot | Props | Description |
|
286
|
+
|------|-------|-------------|
|
287
|
+
| `default` | - | Loading content |
|
288
|
+
| `error` | `{ error: Error }` | Error content |
|
289
|
+
| `success` | - | Success content |
|
290
|
+
|
291
|
+
#### Events
|
292
|
+
|
293
|
+
| Event | Payload | Description |
|
294
|
+
|-------|---------|-------------|
|
295
|
+
| `success` | `state?: TState` | Emitted on successful logout with typed state |
|
296
|
+
| `error` | `Error` | Emitted on logout error |
|
297
|
+
|
298
|
+
#### Usage
|
299
|
+
|
300
|
+
```vue
|
301
|
+
<!-- LogoutCallbackPage.vue -->
|
302
|
+
<script setup>
|
303
|
+
import { LogoutCallback } from 'vuethenticate'
|
304
|
+
|
305
|
+
function onSuccess(state) {
|
306
|
+
console.log('Logout successful:', state)
|
307
|
+
// Redirect to home or show success message
|
308
|
+
window.location.href = '/'
|
309
|
+
}
|
310
|
+
|
311
|
+
function onError(error) {
|
312
|
+
console.error('Logout failed:', error)
|
313
|
+
// Handle error - redirect or show error
|
314
|
+
window.location.href = '/error'
|
315
|
+
}
|
316
|
+
</script>
|
317
|
+
|
318
|
+
<template>
|
319
|
+
<LogoutCallback
|
320
|
+
:onSuccess="onSuccess"
|
321
|
+
:onError="onError"
|
322
|
+
>
|
323
|
+
<div>Processing logout...</div>
|
324
|
+
|
325
|
+
<template #error="{ error }">
|
326
|
+
<div>
|
327
|
+
<h2>Logout Failed</h2>
|
328
|
+
<p>{{ error.message }}</p>
|
329
|
+
</div>
|
330
|
+
</template>
|
331
|
+
|
332
|
+
<template #success>
|
333
|
+
<div>
|
334
|
+
<h2>Logout Successful</h2>
|
335
|
+
<p>You have been logged out successfully.</p>
|
336
|
+
</div>
|
337
|
+
</template>
|
338
|
+
</LogoutCallback>
|
339
|
+
</template>
|
340
|
+
```
|
341
|
+
|
267
342
|
### `<SilentCallback>`
|
268
343
|
|
269
344
|
Component for handling silent token renewal callbacks. This component should be mounted on a separate route (typically `/auth/silent-callback`) and is used internally by the library for automatic token refresh. **Note**: This component requires `useAuth()` to be called in a parent component first.
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"AuthCallback.vue.d.ts","sourceRoot":"","sources":["../../src/components/AuthCallback.vue"],"names":[],"mappings":"AAgBA;
|
1
|
+
{"version":3,"file":"AuthCallback.vue.d.ts","sourceRoot":"","sources":["../../src/components/AuthCallback.vue"],"names":[],"mappings":"AAgBA;AAyEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;yBAG1B,MAAM,GAAG,OAAO,EAChC,aAAa,WAAW,CAAC,OAAO,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,EAC9D,YAAY,mBAAmB,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC,EAC3G,eAAe,WAAW,CAAC,OAAO,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,EACjE;WAiHO,mBAAmB,CAAC;;;uLAAkE,CAAC,4BAA2B;oBACzG,OAAO,KAAK,EAAE,gBAAgB,CAAC,EAAE,CAAC,GAAG,IAAI;WAClD,GAAG;;yBAhCkB,GAAG;;;YACL,GAAG;;;EAmC1B,KACQ,OAAO,KAAK,EAAE,KAAK,GAAG;IAAE,KAAK,CAAC,EAAE,OAAO,CAAC,OAAO,WAAW,CAAC,CAAA;CAAE;AA5HzE,wBA4H4E;AAC5E,KAAK,mBAAmB,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAG,GAAG,EAAE,CAAC"}
|
@@ -17,6 +17,9 @@ export declare const useAuthCallbacks: <TState = unknown>() => {
|
|
17
17
|
user: User;
|
18
18
|
state?: TState;
|
19
19
|
}>;
|
20
|
+
processLogoutCallback: () => Promise<{
|
21
|
+
state?: TState;
|
22
|
+
}>;
|
20
23
|
processSilentCallback: () => Promise<void>;
|
21
24
|
isInitialized: Ref<boolean, boolean>;
|
22
25
|
isInitializing: Ref<boolean, boolean>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../../src/composables/useAuth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAoB,KAAK,GAAG,EAAwB,MAAM,KAAK,CAAC;AACvE,OAAO,EAAE,KAAK,IAAI,EAAe,MAAM,gBAAgB,CAAC;AAwNxD;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAAI,MAAM,GAAG,OAAO,EACpC,QAAQ,UAAU,KACnB,aAAa,CAAC,MAAM,CAsNtB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,GAAG,OAAO;2BAaX,OAAO,CAAC;QACtC,IAAI,EAAE,IAAI,CAAC;QACX,KAAK,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;
|
1
|
+
{"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../../src/composables/useAuth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAoB,KAAK,GAAG,EAAwB,MAAM,KAAK,CAAC;AACvE,OAAO,EAAE,KAAK,IAAI,EAAe,MAAM,gBAAgB,CAAC;AAwNxD;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAAI,MAAM,GAAG,OAAO,EACpC,QAAQ,UAAU,KACnB,aAAa,CAAC,MAAM,CAsNtB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,GAAG,OAAO;2BAaX,OAAO,CAAC;QACtC,IAAI,EAAE,IAAI,CAAC;QACX,KAAK,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;iCAkBsC,OAAO,CAAC;QAC5C,KAAK,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;iCAYsC,OAAO,CAAC,IAAI,CAAC;;;CAaxD,CAAC"}
|
package/dist/index.esm.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { ref as m, computed as I, watch as W, defineComponent as
|
1
|
+
import { ref as m, computed as I, watch as W, defineComponent as z, onMounted as R, createElementBlock as L, openBlock as _, Fragment as $, renderSlot as C, createCommentVNode as U, unref as F, createElementVNode as S, toDisplayString as P } from "vue";
|
2
2
|
import { WebStorageStateStore as j, UserManager as G } from "oidc-client-ts";
|
3
3
|
function H(e) {
|
4
4
|
const r = typeof window < "u" ? window.location.origin : "";
|
@@ -13,7 +13,7 @@ function H(e) {
|
|
13
13
|
userStore: e.storage ? new j({ store: J(e.storage) }) : void 0,
|
14
14
|
automaticSilentRenew: e.automaticSilentRenew ?? !0,
|
15
15
|
silent_redirect_uri: e.silentRedirectUri ?? `${r}/auth/silent-callback`,
|
16
|
-
post_logout_redirect_uri: e.postLogoutRedirectUri ?? r
|
16
|
+
post_logout_redirect_uri: e.postLogoutRedirectUri ?? `${r}/auth/logout-callback`,
|
17
17
|
includeIdTokenInSilentRenew: !0,
|
18
18
|
accessTokenExpiringNotificationTimeInSeconds: 60
|
19
19
|
};
|
@@ -45,7 +45,7 @@ function T() {
|
|
45
45
|
key: (r) => Array.from(e.keys())[r] ?? null
|
46
46
|
};
|
47
47
|
}
|
48
|
-
const
|
48
|
+
const E = /* @__PURE__ */ new Map(), Q = (e) => {
|
49
49
|
try {
|
50
50
|
const { userManager: r, eventCallbacks: t } = e;
|
51
51
|
t.userLoaded && r.events.removeUserLoaded(t.userLoaded), t.userUnloaded && r.events.removeUserUnloaded(t.userUnloaded), t.accessTokenExpired && r.events.removeAccessTokenExpired(
|
@@ -58,37 +58,37 @@ const h = /* @__PURE__ */ new Map(), Q = (e) => {
|
|
58
58
|
} catch (r) {
|
59
59
|
console.warn("Error during UserManager cleanup:", r);
|
60
60
|
}
|
61
|
-
}, K = (e) => `${e.authority}_${e.clientId}`, X = () =>
|
61
|
+
}, K = (e) => `${e.authority}_${e.clientId}`, X = () => E.size === 0 ? null : (E.size === 1 || console.warn(
|
62
62
|
"Multiple auth instances detected. Callback components may not work as expected. Consider using a single auth instance or specify config explicitly."
|
63
|
-
), Array.from(
|
64
|
-
const r = K(e), t =
|
63
|
+
), Array.from(E.values())[0] || null), Y = (e) => {
|
64
|
+
const r = K(e), t = E.get(r);
|
65
65
|
if (t)
|
66
66
|
return t;
|
67
|
-
const
|
68
|
-
var
|
69
|
-
return ((
|
70
|
-
}),
|
71
|
-
var
|
72
|
-
return !!((
|
67
|
+
const i = Z(e), n = m(!1), u = m(!1), a = m(null), s = m(!1), p = m(null), y = I(() => !!a.value && !a.value.expired), d = I(() => {
|
68
|
+
var h;
|
69
|
+
return ((h = a.value) == null ? void 0 : h.access_token) || null;
|
70
|
+
}), w = I(() => {
|
71
|
+
var h;
|
72
|
+
return !!((h = a.value) != null && h.expired);
|
73
73
|
}), k = {
|
74
|
-
userManager:
|
75
|
-
isInitialized:
|
74
|
+
userManager: i,
|
75
|
+
isInitialized: n,
|
76
76
|
isInitializing: u,
|
77
|
-
user:
|
78
|
-
isLoading:
|
77
|
+
user: a,
|
78
|
+
isLoading: s,
|
79
79
|
error: p,
|
80
80
|
isAuthenticated: y,
|
81
81
|
accessToken: d,
|
82
|
-
isExpired:
|
82
|
+
isExpired: w,
|
83
83
|
eventCallbacks: {}
|
84
84
|
};
|
85
|
-
return
|
85
|
+
return E.set(r, k), k;
|
86
86
|
}, Z = (e) => {
|
87
87
|
const r = H(e);
|
88
88
|
return new G(r);
|
89
|
-
}, f = (e, r, t,
|
90
|
-
const
|
91
|
-
return t.value =
|
89
|
+
}, f = (e, r, t, i) => {
|
90
|
+
const n = e instanceof Error ? e : new Error(r);
|
91
|
+
return t.value = n, i == null || i(n), n;
|
92
92
|
}, ee = (e) => {
|
93
93
|
var r, t;
|
94
94
|
if (!((r = e.authority) != null && r.trim()))
|
@@ -100,15 +100,15 @@ const h = /* @__PURE__ */ new Map(), Q = (e) => {
|
|
100
100
|
} catch {
|
101
101
|
throw new Error("AuthConfig: authority must be a valid URL");
|
102
102
|
}
|
103
|
-
},
|
103
|
+
}, x = async (e, r = 1e4) => {
|
104
104
|
if (!e.isInitialized.value)
|
105
|
-
return new Promise((t,
|
106
|
-
const
|
107
|
-
|
105
|
+
return new Promise((t, i) => {
|
106
|
+
const n = setTimeout(() => {
|
107
|
+
i(new Error("Authentication initialization timeout"));
|
108
108
|
}, r), u = W(
|
109
109
|
e.isInitialized,
|
110
|
-
(
|
111
|
-
|
110
|
+
(a) => {
|
111
|
+
a && (clearTimeout(n), u(), t());
|
112
112
|
},
|
113
113
|
{ immediate: !0 }
|
114
114
|
);
|
@@ -117,25 +117,25 @@ const h = /* @__PURE__ */ new Map(), Q = (e) => {
|
|
117
117
|
ee(e);
|
118
118
|
const r = Y(e), {
|
119
119
|
userManager: t,
|
120
|
-
isInitialized:
|
121
|
-
isInitializing:
|
120
|
+
isInitialized: i,
|
121
|
+
isInitializing: n,
|
122
122
|
user: u,
|
123
|
-
isLoading:
|
124
|
-
error:
|
123
|
+
isLoading: a,
|
124
|
+
error: s,
|
125
125
|
isAuthenticated: p,
|
126
126
|
accessToken: y,
|
127
127
|
isExpired: d
|
128
|
-
} = r,
|
129
|
-
if (!(
|
128
|
+
} = r, w = K(e), k = async () => {
|
129
|
+
if (!(n.value || i.value))
|
130
130
|
try {
|
131
|
-
|
131
|
+
n.value = !0, a.value = !0, s.value = null;
|
132
132
|
const o = await t.getUser();
|
133
133
|
if (o)
|
134
134
|
if (!o.expired)
|
135
135
|
u.value = o;
|
136
136
|
else if (e.automaticSilentRenew !== !1)
|
137
137
|
try {
|
138
|
-
await
|
138
|
+
await M();
|
139
139
|
} catch (l) {
|
140
140
|
console.warn(
|
141
141
|
"Silent renewal failed during initialization:",
|
@@ -148,67 +148,67 @@ const h = /* @__PURE__ */ new Map(), Q = (e) => {
|
|
148
148
|
f(
|
149
149
|
o,
|
150
150
|
"Failed to initialize authentication",
|
151
|
-
|
151
|
+
s,
|
152
152
|
e.onError
|
153
153
|
);
|
154
154
|
} finally {
|
155
|
-
|
155
|
+
a.value = !1, n.value = !1, i.value = !0;
|
156
156
|
}
|
157
|
-
},
|
157
|
+
}, h = async (o) => {
|
158
158
|
try {
|
159
|
-
|
159
|
+
a.value = !0, s.value = null, await t.signinRedirect({ state: o });
|
160
160
|
} catch (l) {
|
161
|
-
f(l, "Sign in failed",
|
161
|
+
f(l, "Sign in failed", s, e.onError);
|
162
162
|
} finally {
|
163
|
-
|
163
|
+
a.value = !1;
|
164
164
|
}
|
165
165
|
}, q = async (o) => {
|
166
166
|
try {
|
167
|
-
|
167
|
+
a.value = !0, s.value = null, u.value = null, await t.signoutRedirect({ state: o });
|
168
168
|
} catch (l) {
|
169
|
-
f(l, "Sign out failed",
|
169
|
+
f(l, "Sign out failed", s, e.onError);
|
170
170
|
} finally {
|
171
|
-
|
171
|
+
a.value = !1;
|
172
172
|
}
|
173
|
-
},
|
173
|
+
}, M = async () => {
|
174
174
|
try {
|
175
|
-
|
175
|
+
a.value = !0, s.value = null;
|
176
176
|
const o = await t.signinSilent();
|
177
177
|
u.value = o;
|
178
178
|
} catch (o) {
|
179
179
|
throw f(
|
180
180
|
o,
|
181
181
|
"Silent renewal failed",
|
182
|
-
|
182
|
+
s,
|
183
183
|
e.onError
|
184
184
|
);
|
185
185
|
} finally {
|
186
|
-
|
186
|
+
a.value = !1;
|
187
187
|
}
|
188
188
|
}, B = () => {
|
189
|
-
|
189
|
+
s.value = null;
|
190
190
|
}, O = (o, l) => {
|
191
|
-
const { userManager: g, user: A, error: D, eventCallbacks:
|
192
|
-
|
193
|
-
var
|
194
|
-
A.value = c, (
|
195
|
-
},
|
191
|
+
const { userManager: g, user: A, error: D, eventCallbacks: v } = o;
|
192
|
+
v.userLoaded = (c) => {
|
193
|
+
var b;
|
194
|
+
A.value = c, (b = l.onUserLoaded) == null || b.call(l, c);
|
195
|
+
}, v.userUnloaded = () => {
|
196
196
|
var c;
|
197
197
|
A.value = null, (c = l.onUserUnloaded) == null || c.call(l);
|
198
|
-
},
|
198
|
+
}, v.accessTokenExpired = () => {
|
199
199
|
var c;
|
200
200
|
(c = l.onAccessTokenExpired) == null || c.call(l);
|
201
|
-
},
|
201
|
+
}, v.accessTokenExpiring = () => {
|
202
202
|
var c;
|
203
203
|
(c = l.onAccessTokenExpiring) == null || c.call(l);
|
204
|
-
},
|
204
|
+
}, v.silentRenewError = async (c) => {
|
205
205
|
console.warn("Silent renewal failed:", c);
|
206
206
|
try {
|
207
207
|
await g.removeUser(), A.value = null;
|
208
|
-
} catch (
|
208
|
+
} catch (b) {
|
209
209
|
console.error(
|
210
210
|
"Failed to remove user after silent renewal error:",
|
211
|
-
|
211
|
+
b
|
212
212
|
);
|
213
213
|
}
|
214
214
|
f(
|
@@ -217,24 +217,24 @@ const h = /* @__PURE__ */ new Map(), Q = (e) => {
|
|
217
217
|
D,
|
218
218
|
l.onError
|
219
219
|
);
|
220
|
-
}, g.events.addUserLoaded(
|
221
|
-
|
220
|
+
}, g.events.addUserLoaded(v.userLoaded), g.events.addUserUnloaded(v.userUnloaded), g.events.addAccessTokenExpired(
|
221
|
+
v.accessTokenExpired
|
222
222
|
), g.events.addAccessTokenExpiring(
|
223
|
-
|
224
|
-
), g.events.addSilentRenewError(
|
223
|
+
v.accessTokenExpiring
|
224
|
+
), g.events.addSilentRenewError(v.silentRenewError);
|
225
225
|
}, V = () => {
|
226
|
-
Q(r),
|
226
|
+
Q(r), E.delete(w);
|
227
227
|
};
|
228
|
-
return !
|
228
|
+
return !i.value && !n.value && (k(), O(r, e)), {
|
229
229
|
user: u,
|
230
230
|
isAuthenticated: p,
|
231
|
-
isLoading:
|
232
|
-
error:
|
231
|
+
isLoading: a,
|
232
|
+
error: s,
|
233
233
|
accessToken: y,
|
234
234
|
isExpired: d,
|
235
|
-
signIn:
|
235
|
+
signIn: h,
|
236
236
|
signOut: q,
|
237
|
-
silentRenew:
|
237
|
+
silentRenew: M,
|
238
238
|
clearError: B,
|
239
239
|
cleanup: V
|
240
240
|
};
|
@@ -246,22 +246,29 @@ const h = /* @__PURE__ */ new Map(), Q = (e) => {
|
|
246
246
|
);
|
247
247
|
return {
|
248
248
|
processCallback: async () => {
|
249
|
-
await
|
250
|
-
const
|
251
|
-
if (!
|
249
|
+
await x(e);
|
250
|
+
const n = await e.userManager.signinCallback();
|
251
|
+
if (!n)
|
252
252
|
throw new Error("Authentication callback failed: no user returned");
|
253
253
|
return {
|
254
|
-
user:
|
255
|
-
state:
|
254
|
+
user: n,
|
255
|
+
state: n.state
|
256
|
+
};
|
257
|
+
},
|
258
|
+
processLogoutCallback: async () => {
|
259
|
+
await x(e);
|
260
|
+
const n = await e.userManager.signoutCallback();
|
261
|
+
return {
|
262
|
+
state: n == null ? void 0 : n.state
|
256
263
|
};
|
257
264
|
},
|
258
265
|
processSilentCallback: async () => {
|
259
|
-
await
|
266
|
+
await x(e), await e.userManager.signinCallback();
|
260
267
|
},
|
261
268
|
isInitialized: e.isInitialized,
|
262
269
|
isInitializing: e.isInitializing
|
263
270
|
};
|
264
|
-
}, ae = /* @__PURE__ */
|
271
|
+
}, ae = /* @__PURE__ */ z({
|
265
272
|
__name: "AuthCallback",
|
266
273
|
props: {
|
267
274
|
onSuccess: { type: Function },
|
@@ -269,62 +276,62 @@ const h = /* @__PURE__ */ new Map(), Q = (e) => {
|
|
269
276
|
},
|
270
277
|
emits: ["success", "error"],
|
271
278
|
setup(e, { emit: r }) {
|
272
|
-
const t = e,
|
279
|
+
const t = e, i = r, { processCallback: n, isInitializing: u } = N(), a = m(!0), s = m(null), p = async () => {
|
273
280
|
var y, d;
|
274
281
|
try {
|
275
|
-
const
|
276
|
-
(y = t.onSuccess) == null || y.call(t,
|
277
|
-
} catch (
|
278
|
-
const k =
|
279
|
-
|
282
|
+
const w = await n();
|
283
|
+
(y = t.onSuccess) == null || y.call(t, w.user, w.state), i("success", w.user, w.state);
|
284
|
+
} catch (w) {
|
285
|
+
const k = w instanceof Error ? w : new Error("Callback processing failed");
|
286
|
+
s.value = k, (d = t.onError) == null || d.call(t, k), i("error", k);
|
280
287
|
} finally {
|
281
|
-
|
288
|
+
a.value = !1;
|
282
289
|
}
|
283
290
|
};
|
284
291
|
return R(() => {
|
285
292
|
p();
|
286
|
-
}), (y, d) => (
|
287
|
-
(F(u) ||
|
293
|
+
}), (y, d) => (_(), L($, null, [
|
294
|
+
(F(u) || a.value) && !s.value ? C(y.$slots, "default", { key: 0 }, () => [
|
288
295
|
d[0] || (d[0] = S("p", null, "Processing authentication...", -1))
|
289
|
-
]) :
|
290
|
-
|
296
|
+
]) : U("", !0),
|
297
|
+
s.value ? C(y.$slots, "error", {
|
291
298
|
key: 1,
|
292
|
-
error:
|
299
|
+
error: s.value
|
293
300
|
}, () => [
|
294
301
|
S("div", null, [
|
295
302
|
d[1] || (d[1] = S("h2", null, "Authentication Error", -1)),
|
296
|
-
S("p", null, P(
|
303
|
+
S("p", null, P(s.value.message), 1)
|
297
304
|
])
|
298
|
-
]) :
|
305
|
+
]) : U("", !0)
|
299
306
|
], 64));
|
300
307
|
}
|
301
|
-
}), se = /* @__PURE__ */
|
308
|
+
}), se = /* @__PURE__ */ z({
|
302
309
|
__name: "SilentCallback",
|
303
310
|
props: {
|
304
311
|
onError: { type: Function }
|
305
312
|
},
|
306
313
|
setup(e) {
|
307
|
-
const r = e, { processSilentCallback: t, isInitializing:
|
308
|
-
var
|
314
|
+
const r = e, { processSilentCallback: t, isInitializing: i } = N(), n = m(null), u = async () => {
|
315
|
+
var a;
|
309
316
|
try {
|
310
317
|
await t();
|
311
|
-
} catch (
|
312
|
-
const p =
|
313
|
-
|
318
|
+
} catch (s) {
|
319
|
+
const p = s instanceof Error ? s : new Error("Silent callback processing failed");
|
320
|
+
n.value = p, (a = r.onError) == null || a.call(r, p), console.error("Silent callback error:", p);
|
314
321
|
}
|
315
322
|
};
|
316
323
|
return R(() => {
|
317
324
|
u();
|
318
|
-
}), (
|
319
|
-
F(
|
320
|
-
|
321
|
-
]) :
|
322
|
-
|
325
|
+
}), (a, s) => (_(), L($, null, [
|
326
|
+
F(i) && !n.value ? C(a.$slots, "default", { key: 0 }, () => [
|
327
|
+
s[0] || (s[0] = S("p", null, "Processing silent renewal...", -1))
|
328
|
+
]) : U("", !0),
|
329
|
+
n.value ? C(a.$slots, "error", {
|
323
330
|
key: 1,
|
324
|
-
error:
|
331
|
+
error: n.value
|
325
332
|
}, () => [
|
326
|
-
S("p", null, "Silent renewal error: " + P(
|
327
|
-
]) :
|
333
|
+
S("p", null, "Silent renewal error: " + P(n.value.message), 1)
|
334
|
+
]) : U("", !0)
|
328
335
|
], 64));
|
329
336
|
}
|
330
337
|
});
|
package/dist/index.umd.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
(function(m,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue"),require("oidc-client-ts")):typeof define=="function"&&define.amd?define(["exports","vue","oidc-client-ts"],t):(m=typeof globalThis<"u"?globalThis:m||self,t(m.Vuethenticate={},m.Vue,m.OidcClientTs))})(this,function(m,t,
|
1
|
+
(function(m,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue"),require("oidc-client-ts")):typeof define=="function"&&define.amd?define(["exports","vue","oidc-client-ts"],t):(m=typeof globalThis<"u"?globalThis:m||self,t(m.Vuethenticate={},m.Vue,m.OidcClientTs))})(this,function(m,t,A){"use strict";function z(e){const r=typeof window<"u"?window.location.origin:"";return{authority:e.authority,client_id:e.clientId,client_secret:e.clientSecret,client_authentication:e.clientAuthentication,redirect_uri:e.redirectUri??`${r}/auth/callback`,scope:e.scope??"openid profile",response_type:e.responseType??"code",userStore:e.storage?new A.WebStorageStateStore({store:R(e.storage)}):void 0,automaticSilentRenew:e.automaticSilentRenew??!0,silent_redirect_uri:e.silentRedirectUri??`${r}/auth/silent-callback`,post_logout_redirect_uri:e.postLogoutRedirectUri??`${r}/auth/logout-callback`,includeIdTokenInSilentRenew:!0,accessTokenExpiringNotificationTimeInSeconds:60}}function R(e){if(typeof window>"u")return T();switch(e){case"localStorage":return window.localStorage;case"sessionStorage":return window.sessionStorage;case"memory":return T();default:return window.localStorage}}function T(){const e=new Map;return{getItem:r=>e.get(r)??null,setItem:(r,n)=>e.set(r,n),removeItem:r=>e.delete(r),clear:()=>e.clear(),get length(){return e.size},key:r=>Array.from(e.keys())[r]??null}}const f=new Map,L=e=>{try{const{userManager:r,eventCallbacks:n}=e;n.userLoaded&&r.events.removeUserLoaded(n.userLoaded),n.userUnloaded&&r.events.removeUserUnloaded(n.userUnloaded),n.accessTokenExpired&&r.events.removeAccessTokenExpired(n.accessTokenExpired),n.accessTokenExpiring&&r.events.removeAccessTokenExpiring(n.accessTokenExpiring),n.silentRenewError&&r.events.removeSilentRenewError(n.silentRenewError),r.stopSilentRenew(),r.clearStaleState()}catch(r){console.warn("Error during UserManager cleanup:",r)}},I=e=>`${e.authority}_${e.clientId}`,_=()=>f.size===0?null:(f.size===1||console.warn("Multiple auth instances detected. Callback components may not work as expected. Consider using a single auth instance or specify config explicitly."),Array.from(f.values())[0]||null),V=e=>{const r=I(e),n=f.get(r);if(n)return n;const o=N(e),a=t.ref(!1),u=t.ref(!1),s=t.ref(null),i=t.ref(!1),k=t.ref(null),E=t.computed(()=>!!s.value&&!s.value.expired),w=t.computed(()=>{var g;return((g=s.value)==null?void 0:g.access_token)||null}),p=t.computed(()=>{var g;return!!((g=s.value)!=null&&g.expired)}),h={userManager:o,isInitialized:a,isInitializing:u,user:s,isLoading:i,error:k,isAuthenticated:E,accessToken:w,isExpired:p,eventCallbacks:{}};return f.set(r,h),h},N=e=>{const r=z(e);return new A.UserManager(r)},v=(e,r,n,o)=>{const a=e instanceof Error?e:new Error(r);return n.value=a,o==null||o(a),a},$=e=>{var r,n;if(!((r=e.authority)!=null&&r.trim()))throw new Error("AuthConfig: authority is required");if(!((n=e.clientId)!=null&&n.trim()))throw new Error("AuthConfig: clientId is required");try{new URL(e.authority)}catch{throw new Error("AuthConfig: authority must be a valid URL")}},b=async(e,r=1e4)=>{if(!e.isInitialized.value)return new Promise((n,o)=>{const a=setTimeout(()=>{o(new Error("Authentication initialization timeout"))},r),u=t.watch(e.isInitialized,s=>{s&&(clearTimeout(a),u(),n())},{immediate:!0})})},F=e=>{$(e);const r=V(e),{userManager:n,isInitialized:o,isInitializing:a,user:u,isLoading:s,error:i,isAuthenticated:k,accessToken:E,isExpired:w}=r,p=I(e),h=async()=>{if(!(a.value||o.value))try{a.value=!0,s.value=!0,i.value=null;const c=await n.getUser();if(c)if(!c.expired)u.value=c;else if(e.automaticSilentRenew!==!1)try{await x()}catch(l){console.warn("Silent renewal failed during initialization:",l),await n.removeUser(),u.value=null}else await n.removeUser(),u.value=null}catch(c){v(c,"Failed to initialize authentication",i,e.onError)}finally{s.value=!1,a.value=!1,o.value=!0}},g=async c=>{try{s.value=!0,i.value=null,await n.signinRedirect({state:c})}catch(l){v(l,"Sign in failed",i,e.onError)}finally{s.value=!1}},B=async c=>{try{s.value=!0,i.value=null,u.value=null,await n.signoutRedirect({state:c})}catch(l){v(l,"Sign out failed",i,e.onError)}finally{s.value=!1}},x=async()=>{try{s.value=!0,i.value=null;const c=await n.signinSilent();u.value=c}catch(c){throw v(c,"Silent renewal failed",i,e.onError)}finally{s.value=!1}},O=()=>{i.value=null},K=(c,l)=>{const{userManager:S,user:U,error:D,eventCallbacks:y}=c;y.userLoaded=d=>{var C;U.value=d,(C=l.onUserLoaded)==null||C.call(l,d)},y.userUnloaded=()=>{var d;U.value=null,(d=l.onUserUnloaded)==null||d.call(l)},y.accessTokenExpired=()=>{var d;(d=l.onAccessTokenExpired)==null||d.call(l)},y.accessTokenExpiring=()=>{var d;(d=l.onAccessTokenExpiring)==null||d.call(l)},y.silentRenewError=async d=>{console.warn("Silent renewal failed:",d);try{await S.removeUser(),U.value=null}catch(C){console.error("Failed to remove user after silent renewal error:",C)}v(d,"Silent renewal failed",D,l.onError)},S.events.addUserLoaded(y.userLoaded),S.events.addUserUnloaded(y.userUnloaded),S.events.addAccessTokenExpired(y.accessTokenExpired),S.events.addAccessTokenExpiring(y.accessTokenExpiring),S.events.addSilentRenewError(y.silentRenewError)},j=()=>{L(r),f.delete(p)};return!o.value&&!a.value&&(h(),K(r,e)),{user:u,isAuthenticated:k,isLoading:s,error:i,accessToken:E,isExpired:w,signIn:g,signOut:B,silentRenew:x,clearError:O,cleanup:j}},M=()=>{const e=_();if(!e)throw new Error("Authentication not initialized. Make sure useAuth() is called in a parent component first.");return{processCallback:async()=>{await b(e);const a=await e.userManager.signinCallback();if(!a)throw new Error("Authentication callback failed: no user returned");return{user:a,state:a.state}},processLogoutCallback:async()=>{await b(e);const a=await e.userManager.signoutCallback();return{state:a==null?void 0:a.state}},processSilentCallback:async()=>{await b(e),await e.userManager.signinCallback()},isInitialized:e.isInitialized,isInitializing:e.isInitializing}},P=t.defineComponent({__name:"AuthCallback",props:{onSuccess:{type:Function},onError:{type:Function}},emits:["success","error"],setup(e,{emit:r}){const n=e,o=r,{processCallback:a,isInitializing:u}=M(),s=t.ref(!0),i=t.ref(null),k=async()=>{var E,w;try{const p=await a();(E=n.onSuccess)==null||E.call(n,p.user,p.state),o("success",p.user,p.state)}catch(p){const h=p instanceof Error?p:new Error("Callback processing failed");i.value=h,(w=n.onError)==null||w.call(n,h),o("error",h)}finally{s.value=!1}};return t.onMounted(()=>{k()}),(E,w)=>(t.openBlock(),t.createElementBlock(t.Fragment,null,[(t.unref(u)||s.value)&&!i.value?t.renderSlot(E.$slots,"default",{key:0},()=>[w[0]||(w[0]=t.createElementVNode("p",null,"Processing authentication...",-1))]):t.createCommentVNode("",!0),i.value?t.renderSlot(E.$slots,"error",{key:1,error:i.value},()=>[t.createElementVNode("div",null,[w[1]||(w[1]=t.createElementVNode("h2",null,"Authentication Error",-1)),t.createElementVNode("p",null,t.toDisplayString(i.value.message),1)])]):t.createCommentVNode("",!0)],64))}}),q=t.defineComponent({__name:"SilentCallback",props:{onError:{type:Function}},setup(e){const r=e,{processSilentCallback:n,isInitializing:o}=M(),a=t.ref(null),u=async()=>{var s;try{await n()}catch(i){const k=i instanceof Error?i:new Error("Silent callback processing failed");a.value=k,(s=r.onError)==null||s.call(r,k),console.error("Silent callback error:",k)}};return t.onMounted(()=>{u()}),(s,i)=>(t.openBlock(),t.createElementBlock(t.Fragment,null,[t.unref(o)&&!a.value?t.renderSlot(s.$slots,"default",{key:0},()=>[i[0]||(i[0]=t.createElementVNode("p",null,"Processing silent renewal...",-1))]):t.createCommentVNode("",!0),a.value?t.renderSlot(s.$slots,"error",{key:1,error:a.value},()=>[t.createElementVNode("p",null,"Silent renewal error: "+t.toDisplayString(a.value.message),1)]):t.createCommentVNode("",!0)],64))}});m.AuthCallback=P,m.SilentCallback=q,m.useAuth=F,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
|
package/dist/types/auth.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Ref } from 'vue';
|
1
|
+
import { ComputedRef, Ref } from 'vue';
|
2
2
|
import { User } from 'oidc-client-ts';
|
3
3
|
export interface AuthConfig {
|
4
4
|
authority: string;
|
@@ -20,11 +20,11 @@ export interface AuthConfig {
|
|
20
20
|
}
|
21
21
|
export interface AuthState {
|
22
22
|
user: Ref<User | null>;
|
23
|
-
isAuthenticated: Ref<boolean>;
|
24
23
|
isLoading: Ref<boolean>;
|
25
24
|
error: Ref<Error | null>;
|
26
|
-
|
27
|
-
|
25
|
+
isAuthenticated: ComputedRef<boolean>;
|
26
|
+
accessToken: ComputedRef<string | null>;
|
27
|
+
isExpired: ComputedRef<boolean>;
|
28
28
|
}
|
29
29
|
export interface AuthMethods<TState = unknown> {
|
30
30
|
signIn: (state?: TState) => Promise<void>;
|
@@ -48,5 +48,9 @@ export interface AuthCallbackProps<TState = unknown> {
|
|
48
48
|
export interface SilentCallbackProps {
|
49
49
|
onError?: (error: Error) => void;
|
50
50
|
}
|
51
|
+
export interface SignoutCallbackProps<TState = unknown> {
|
52
|
+
onSuccess?: (state?: TState) => void;
|
53
|
+
onError?: (error: Error) => void;
|
54
|
+
}
|
51
55
|
export { User } from 'oidc-client-ts';
|
52
56
|
//# sourceMappingURL=auth.d.ts.map
|
package/dist/types/auth.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/types/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/types/auth.ts"],"names":[],"mappings":"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"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"configHelpers.d.ts","sourceRoot":"","sources":["../../src/utils/configHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAG1D;;;;GAIG;AACH,wBAAgB,yBAAyB,CACrC,MAAM,EAAE,UAAU,GACnB,mBAAmB,
|
1
|
+
{"version":3,"file":"configHelpers.d.ts","sourceRoot":"","sources":["../../src/utils/configHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAG1D;;;;GAIG;AACH,wBAAgB,yBAAyB,CACrC,MAAM,EAAE,UAAU,GACnB,mBAAmB,CAsBrB"}
|