vuethenticate 0.1.0
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/components/AuthCallback.vue.d.ts +24 -0
- package/dist/components/AuthCallback.vue.d.ts.map +1 -0
- package/dist/components/SilentCallback.vue.d.ts +22 -0
- package/dist/components/SilentCallback.vue.d.ts.map +1 -0
- package/dist/components/index.d.ts +3 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/composables/useAuth.d.ts +24 -0
- package/dist/composables/useAuth.d.ts.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.esm.js +315 -0
- package/dist/index.umd.js +1 -0
- package/dist/types/auth.d.ts +51 -0
- package/dist/types/auth.d.ts.map +1 -0
- package/dist/utils/configHelpers.d.ts +9 -0
- package/dist/utils/configHelpers.d.ts.map +1 -0
- package/package.json +59 -0
@@ -0,0 +1,24 @@
|
|
1
|
+
import { AuthCallbackProps } from '../types/auth';
|
2
|
+
import { User } from 'oidc-client-ts';
|
3
|
+
declare const _default: <TState = unknown>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
4
|
+
props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{
|
5
|
+
readonly onError?: ((error: Error) => any) | undefined;
|
6
|
+
readonly onSuccess?: ((user: User, state?: TState | undefined) => any) | undefined;
|
7
|
+
} & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps, never>, "onError" | "onSuccess"> & AuthCallbackProps<TState> & Partial<{}>> & import('vue').PublicProps;
|
8
|
+
expose(exposed: import('vue').ShallowUnwrapRef<{}>): void;
|
9
|
+
attrs: any;
|
10
|
+
slots: {
|
11
|
+
default?(_: {}): any;
|
12
|
+
error?(_: {
|
13
|
+
error: Error;
|
14
|
+
}): any;
|
15
|
+
};
|
16
|
+
emit: ((evt: "error", error: Error) => void) & ((evt: "success", user: User, state?: TState | undefined) => void);
|
17
|
+
}>) => import('vue').VNode & {
|
18
|
+
__ctx?: Awaited<typeof __VLS_setup>;
|
19
|
+
};
|
20
|
+
export default _default;
|
21
|
+
type __VLS_PrettifyLocal<T> = {
|
22
|
+
[K in keyof T]: T[K];
|
23
|
+
} & {};
|
24
|
+
//# sourceMappingURL=AuthCallback.vue.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"AuthCallback.vue.d.ts","sourceRoot":"","sources":["../../src/components/AuthCallback.vue"],"names":[],"mappings":"AAgBA;AA2EA,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"}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { SilentCallbackProps } from '../types/auth';
|
2
|
+
declare function __VLS_template(): {
|
3
|
+
attrs: Partial<{}>;
|
4
|
+
slots: {
|
5
|
+
default?(_: {}): any;
|
6
|
+
error?(_: {
|
7
|
+
error: Error;
|
8
|
+
}): any;
|
9
|
+
};
|
10
|
+
refs: {};
|
11
|
+
rootEl: any;
|
12
|
+
};
|
13
|
+
type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
|
14
|
+
declare const __VLS_component: import('vue').DefineComponent<SilentCallbackProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<SilentCallbackProps> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
15
|
+
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
|
16
|
+
export default _default;
|
17
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
18
|
+
new (): {
|
19
|
+
$slots: S;
|
20
|
+
};
|
21
|
+
};
|
22
|
+
//# sourceMappingURL=SilentCallback.vue.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"SilentCallback.vue.d.ts","sourceRoot":"","sources":["../../src/components/SilentCallback.vue"],"names":[],"mappings":"AAaA;AA6DA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AA6CzD,iBAAS,cAAc;WAiCT,OAAO,IAA6B;;yBAXrB,GAAG;;;YACL,GAAG;;;;EAe7B;AAUD,KAAK,oBAAoB,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AAC9D,QAAA,MAAM,eAAe,kTAMnB,CAAC;wBACkB,uBAAuB,CAAC,OAAO,eAAe,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC;AAAnG,wBAAoG;AAQpG,KAAK,uBAAuB,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IACxC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KAEV,CAAA;CACD,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,sBAAsB,CAAC"}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import { AuthConfig, UseAuthReturn } from '../types/auth';
|
2
|
+
import { Ref } from 'vue';
|
3
|
+
import { User } from 'oidc-client-ts';
|
4
|
+
/**
|
5
|
+
* Vue composable for authentication state management using OIDC
|
6
|
+
* @param config - Authentication configuration
|
7
|
+
* @returns Authentication state and methods
|
8
|
+
*/
|
9
|
+
export declare const useAuth: <TState = unknown>(config: AuthConfig) => UseAuthReturn<TState>;
|
10
|
+
/**
|
11
|
+
* Internal composable for callback components
|
12
|
+
* Automatically finds the active UserManager instance and waits for initialization
|
13
|
+
* @returns Callback processing methods and initialization state
|
14
|
+
*/
|
15
|
+
export declare const useAuthCallbacks: <TState = unknown>() => {
|
16
|
+
processCallback: (url?: string) => Promise<{
|
17
|
+
user: User;
|
18
|
+
state?: TState;
|
19
|
+
}>;
|
20
|
+
processSilentCallback: (url?: string) => Promise<void>;
|
21
|
+
isInitialized: Ref<boolean, boolean>;
|
22
|
+
isInitializing: Ref<boolean, boolean>;
|
23
|
+
};
|
24
|
+
//# sourceMappingURL=useAuth.d.ts.map
|
@@ -0,0 +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,EAEH,KAAK,GAAG,EAKX,MAAM,KAAK,CAAC;AACb,OAAO,EAAE,KAAK,IAAI,EAAe,MAAM,gBAAgB,CAAC;AA2KxD;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAAI,MAAM,GAAG,OAAO,EACpC,QAAQ,UAAU,KACnB,aAAa,CAAC,MAAM,CAgMtB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,GAAG,OAAO;4BAenC,MAAM,KACb,OAAO,CAAC;QAAE,IAAI,EAAE,IAAI,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;kCAiBC,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC;;;CAapE,CAAC"}
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,4 @@
|
|
1
|
+
export { useAuth } from './composables/useAuth';
|
2
|
+
export { AuthCallback, SilentCallback } from './components';
|
3
|
+
export type { AuthConfig, AuthState, AuthMethods, AuthCallbackMethods, UseAuthReturn, AuthCallbackProps, SilentCallbackProps, User, } from './types/auth';
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAG5D,YAAY,EACR,UAAU,EACV,SAAS,EACT,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,IAAI,GACP,MAAM,cAAc,CAAC"}
|
@@ -0,0 +1,315 @@
|
|
1
|
+
import { onUnmounted as K, ref as m, computed as f, watch as N, defineComponent as I, onMounted as U, createElementBlock as z, openBlock as M, Fragment as _, renderSlot as E, createCommentVNode as g, unref as R, createElementVNode as k, toDisplayString as x } from "vue";
|
2
|
+
import { WebStorageStateStore as q, UserManager as B } from "oidc-client-ts";
|
3
|
+
function O(e) {
|
4
|
+
const r = typeof window < "u" ? window.location.origin : "";
|
5
|
+
return {
|
6
|
+
authority: e.authority,
|
7
|
+
client_id: e.clientId,
|
8
|
+
client_secret: e.clientSecret,
|
9
|
+
client_authentication: e.clientAuthentication ?? "client_secret_basic",
|
10
|
+
redirect_uri: e.redirectUri ?? `${r}/auth/callback`,
|
11
|
+
scope: e.scope ?? "openid profile",
|
12
|
+
response_type: e.responseType ?? "code",
|
13
|
+
userStore: e.storage ? new q({ store: V(e.storage) }) : void 0,
|
14
|
+
automaticSilentRenew: e.automaticSilentRenew ?? !0,
|
15
|
+
silent_redirect_uri: e.silentRedirectUri ?? `${r}/auth/silent-callback`,
|
16
|
+
post_logout_redirect_uri: e.postLogoutRedirectUri ?? r,
|
17
|
+
includeIdTokenInSilentRenew: !0,
|
18
|
+
accessTokenExpiringNotificationTimeInSeconds: 60
|
19
|
+
};
|
20
|
+
}
|
21
|
+
function V(e) {
|
22
|
+
if (typeof window > "u")
|
23
|
+
return C();
|
24
|
+
switch (e) {
|
25
|
+
case "localStorage":
|
26
|
+
return window.localStorage;
|
27
|
+
case "sessionStorage":
|
28
|
+
return window.sessionStorage;
|
29
|
+
case "memory":
|
30
|
+
return C();
|
31
|
+
default:
|
32
|
+
return window.localStorage;
|
33
|
+
}
|
34
|
+
}
|
35
|
+
function C() {
|
36
|
+
const e = /* @__PURE__ */ new Map();
|
37
|
+
return {
|
38
|
+
getItem: (r) => e.get(r) ?? null,
|
39
|
+
setItem: (r, t) => e.set(r, t),
|
40
|
+
removeItem: (r) => e.delete(r),
|
41
|
+
clear: () => e.clear(),
|
42
|
+
get length() {
|
43
|
+
return e.size;
|
44
|
+
},
|
45
|
+
key: (r) => Array.from(e.keys())[r] ?? null
|
46
|
+
};
|
47
|
+
}
|
48
|
+
const p = /* @__PURE__ */ new Map(), T = (e) => `${e.authority}_${e.clientId}`, D = () => p.size === 0 ? null : (p.size === 1 || console.warn(
|
49
|
+
"Multiple auth instances detected. Callback components may not work as expected. Consider using a single auth instance or specify config explicitly."
|
50
|
+
), Array.from(p.values())[0] || null), W = (e) => {
|
51
|
+
const r = T(e), t = p.get(r);
|
52
|
+
if (t)
|
53
|
+
return t;
|
54
|
+
const s = j(e), i = m(!1), o = m(!1), a = m(null), l = m(!1), w = m(null), v = f(() => !!a.value && !a.value.expired), u = f(() => {
|
55
|
+
var h;
|
56
|
+
return ((h = a.value) == null ? void 0 : h.access_token) || null;
|
57
|
+
}), c = f(() => {
|
58
|
+
var h;
|
59
|
+
return !!((h = a.value) != null && h.expired);
|
60
|
+
}), y = {
|
61
|
+
userManager: s,
|
62
|
+
isInitialized: i,
|
63
|
+
isInitializing: o,
|
64
|
+
user: a,
|
65
|
+
isLoading: l,
|
66
|
+
error: w,
|
67
|
+
isAuthenticated: v,
|
68
|
+
accessToken: u,
|
69
|
+
isExpired: c
|
70
|
+
};
|
71
|
+
return p.set(r, y), y;
|
72
|
+
}, j = (e) => {
|
73
|
+
const r = O(e);
|
74
|
+
return new B(r);
|
75
|
+
}, S = (e, r, t, s) => {
|
76
|
+
const i = e instanceof Error ? e : new Error(r);
|
77
|
+
return t.value = i, s == null || s(i), i;
|
78
|
+
}, G = (e) => {
|
79
|
+
var r, t;
|
80
|
+
if (!((r = e.authority) != null && r.trim()))
|
81
|
+
throw new Error("AuthConfig: authority is required");
|
82
|
+
if (!((t = e.clientId) != null && t.trim()))
|
83
|
+
throw new Error("AuthConfig: clientId is required");
|
84
|
+
try {
|
85
|
+
new URL(e.authority);
|
86
|
+
} catch {
|
87
|
+
throw new Error("AuthConfig: authority must be a valid URL");
|
88
|
+
}
|
89
|
+
}, A = async (e, r = 1e4) => {
|
90
|
+
if (!e.isInitialized.value)
|
91
|
+
return new Promise((t, s) => {
|
92
|
+
const i = setTimeout(() => {
|
93
|
+
s(new Error("Authentication initialization timeout"));
|
94
|
+
}, r), o = N(
|
95
|
+
e.isInitialized,
|
96
|
+
(a) => {
|
97
|
+
a && (clearTimeout(i), o(), t());
|
98
|
+
},
|
99
|
+
{ immediate: !0 }
|
100
|
+
);
|
101
|
+
});
|
102
|
+
}, Q = (e) => {
|
103
|
+
G(e);
|
104
|
+
const r = W(e), {
|
105
|
+
userManager: t,
|
106
|
+
isInitialized: s,
|
107
|
+
isInitializing: i,
|
108
|
+
user: o,
|
109
|
+
isLoading: a,
|
110
|
+
error: l,
|
111
|
+
isAuthenticated: w,
|
112
|
+
accessToken: v,
|
113
|
+
isExpired: u
|
114
|
+
} = r, c = T(e), y = async () => {
|
115
|
+
if (!(i.value || s.value))
|
116
|
+
try {
|
117
|
+
i.value = !0, a.value = !0, l.value = null;
|
118
|
+
const n = await t.getUser();
|
119
|
+
if (n)
|
120
|
+
if (!n.expired)
|
121
|
+
o.value = n;
|
122
|
+
else if (e.automaticSilentRenew !== !1)
|
123
|
+
try {
|
124
|
+
await b();
|
125
|
+
} catch (d) {
|
126
|
+
console.warn(
|
127
|
+
"Silent renewal failed during initialization:",
|
128
|
+
d
|
129
|
+
), await t.removeUser(), o.value = null;
|
130
|
+
}
|
131
|
+
else
|
132
|
+
await t.removeUser(), o.value = null;
|
133
|
+
} catch (n) {
|
134
|
+
S(
|
135
|
+
n,
|
136
|
+
"Failed to initialize authentication",
|
137
|
+
l,
|
138
|
+
e.onError
|
139
|
+
);
|
140
|
+
} finally {
|
141
|
+
a.value = !1, i.value = !1, s.value = !0;
|
142
|
+
}
|
143
|
+
}, h = async (n) => {
|
144
|
+
try {
|
145
|
+
a.value = !0, l.value = null, await t.signinRedirect({ state: n });
|
146
|
+
} catch (d) {
|
147
|
+
S(d, "Sign in failed", l, e.onError);
|
148
|
+
} finally {
|
149
|
+
a.value = !1;
|
150
|
+
}
|
151
|
+
}, L = async (n) => {
|
152
|
+
try {
|
153
|
+
a.value = !0, l.value = null, o.value = null, await t.signoutRedirect({ state: n });
|
154
|
+
} catch (d) {
|
155
|
+
S(d, "Sign out failed", l, e.onError);
|
156
|
+
} finally {
|
157
|
+
a.value = !1;
|
158
|
+
}
|
159
|
+
}, b = async () => {
|
160
|
+
try {
|
161
|
+
a.value = !0, l.value = null;
|
162
|
+
const n = await t.signinSilent();
|
163
|
+
o.value = n;
|
164
|
+
} catch (n) {
|
165
|
+
throw S(
|
166
|
+
n,
|
167
|
+
"Silent renewal failed",
|
168
|
+
l,
|
169
|
+
e.onError
|
170
|
+
);
|
171
|
+
} finally {
|
172
|
+
a.value = !1;
|
173
|
+
}
|
174
|
+
}, F = () => {
|
175
|
+
l.value = null;
|
176
|
+
}, P = () => {
|
177
|
+
t.events.addUserLoaded((n) => {
|
178
|
+
var d;
|
179
|
+
o.value = n, (d = e.onUserLoaded) == null || d.call(e, n);
|
180
|
+
}), t.events.addUserUnloaded(() => {
|
181
|
+
var n;
|
182
|
+
o.value = null, (n = e.onUserUnloaded) == null || n.call(e);
|
183
|
+
}), t.events.addAccessTokenExpired(() => {
|
184
|
+
var n;
|
185
|
+
(n = e.onAccessTokenExpired) == null || n.call(e);
|
186
|
+
}), t.events.addAccessTokenExpiring(() => {
|
187
|
+
var n;
|
188
|
+
(n = e.onAccessTokenExpiring) == null || n.call(e);
|
189
|
+
}), t.events.addSilentRenewError(async (n) => {
|
190
|
+
console.warn("Silent renewal failed:", n);
|
191
|
+
try {
|
192
|
+
await t.removeUser(), o.value = null;
|
193
|
+
} catch (d) {
|
194
|
+
console.error(
|
195
|
+
"Failed to remove user after silent renewal error:",
|
196
|
+
d
|
197
|
+
);
|
198
|
+
}
|
199
|
+
S(
|
200
|
+
n,
|
201
|
+
"Silent renewal failed",
|
202
|
+
l,
|
203
|
+
e.onError
|
204
|
+
);
|
205
|
+
});
|
206
|
+
};
|
207
|
+
return !s.value && !i.value && (y(), P()), K(() => {
|
208
|
+
p.delete(c);
|
209
|
+
}), {
|
210
|
+
user: o,
|
211
|
+
isAuthenticated: w,
|
212
|
+
isLoading: a,
|
213
|
+
error: l,
|
214
|
+
accessToken: v,
|
215
|
+
isExpired: u,
|
216
|
+
signIn: h,
|
217
|
+
signOut: L,
|
218
|
+
silentRenew: b,
|
219
|
+
clearError: F
|
220
|
+
};
|
221
|
+
}, $ = () => {
|
222
|
+
const e = D();
|
223
|
+
if (!e)
|
224
|
+
throw new Error(
|
225
|
+
"Authentication not initialized. Make sure useAuth() is called in a parent component first."
|
226
|
+
);
|
227
|
+
return {
|
228
|
+
processCallback: async (s) => {
|
229
|
+
await A(e);
|
230
|
+
const i = s || window.location.href, o = await e.userManager.signinRedirectCallback(i);
|
231
|
+
return {
|
232
|
+
user: o,
|
233
|
+
state: o.state
|
234
|
+
};
|
235
|
+
},
|
236
|
+
processSilentCallback: async (s) => {
|
237
|
+
await A(e);
|
238
|
+
const i = s || window.location.href;
|
239
|
+
await e.userManager.signinSilentCallback(i);
|
240
|
+
},
|
241
|
+
isInitialized: e.isInitialized,
|
242
|
+
isInitializing: e.isInitializing
|
243
|
+
};
|
244
|
+
}, X = /* @__PURE__ */ I({
|
245
|
+
__name: "AuthCallback",
|
246
|
+
props: {
|
247
|
+
onSuccess: { type: Function },
|
248
|
+
onError: { type: Function }
|
249
|
+
},
|
250
|
+
emits: ["success", "error"],
|
251
|
+
setup(e, { emit: r }) {
|
252
|
+
const t = e, s = r, { processCallback: i, isInitializing: o } = $(), a = m(!0), l = m(null), w = async () => {
|
253
|
+
var v, u;
|
254
|
+
try {
|
255
|
+
const c = await i();
|
256
|
+
(v = t.onSuccess) == null || v.call(t, c.user, c.state), s("success", c.user, c.state);
|
257
|
+
} catch (c) {
|
258
|
+
const y = c instanceof Error ? c : new Error("Callback processing failed");
|
259
|
+
l.value = y, (u = t.onError) == null || u.call(t, y), s("error", y);
|
260
|
+
} finally {
|
261
|
+
a.value = !1;
|
262
|
+
}
|
263
|
+
};
|
264
|
+
return U(() => {
|
265
|
+
w();
|
266
|
+
}), (v, u) => (M(), z(_, null, [
|
267
|
+
(R(o) || a.value) && !l.value ? E(v.$slots, "default", { key: 0 }, () => [
|
268
|
+
u[0] || (u[0] = k("p", null, "Processing authentication...", -1))
|
269
|
+
]) : g("", !0),
|
270
|
+
l.value ? E(v.$slots, "error", {
|
271
|
+
key: 1,
|
272
|
+
error: l.value
|
273
|
+
}, () => [
|
274
|
+
k("div", null, [
|
275
|
+
u[1] || (u[1] = k("h2", null, "Authentication Error", -1)),
|
276
|
+
k("p", null, x(l.value.message), 1)
|
277
|
+
])
|
278
|
+
]) : g("", !0)
|
279
|
+
], 64));
|
280
|
+
}
|
281
|
+
}), Y = /* @__PURE__ */ I({
|
282
|
+
__name: "SilentCallback",
|
283
|
+
props: {
|
284
|
+
onError: { type: Function }
|
285
|
+
},
|
286
|
+
setup(e) {
|
287
|
+
const r = e, { processSilentCallback: t, isInitializing: s } = $(), i = m(null), o = async () => {
|
288
|
+
var a;
|
289
|
+
try {
|
290
|
+
await t();
|
291
|
+
} catch (l) {
|
292
|
+
const w = l instanceof Error ? l : new Error("Silent callback processing failed");
|
293
|
+
i.value = w, (a = r.onError) == null || a.call(r, w), console.error("Silent callback error:", w);
|
294
|
+
}
|
295
|
+
};
|
296
|
+
return U(() => {
|
297
|
+
o();
|
298
|
+
}), (a, l) => (M(), z(_, null, [
|
299
|
+
R(s) && !i.value ? E(a.$slots, "default", { key: 0 }, () => [
|
300
|
+
l[0] || (l[0] = k("p", null, "Processing silent renewal...", -1))
|
301
|
+
]) : g("", !0),
|
302
|
+
i.value ? E(a.$slots, "error", {
|
303
|
+
key: 1,
|
304
|
+
error: i.value
|
305
|
+
}, () => [
|
306
|
+
k("p", null, "Silent renewal error: " + x(i.value.message), 1)
|
307
|
+
]) : g("", !0)
|
308
|
+
], 64));
|
309
|
+
}
|
310
|
+
});
|
311
|
+
export {
|
312
|
+
X as AuthCallback,
|
313
|
+
Y as SilentCallback,
|
314
|
+
Q as useAuth
|
315
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
(function(w,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):(w=typeof globalThis<"u"?globalThis:w||self,t(w.Vuethenticate={},w.Vue,w.OidcClientTs))})(this,function(w,t,E){"use strict";function I(e){const n=typeof window<"u"?window.location.origin:"";return{authority:e.authority,client_id:e.clientId,client_secret:e.clientSecret,client_authentication:e.clientAuthentication??"client_secret_basic",redirect_uri:e.redirectUri??`${n}/auth/callback`,scope:e.scope??"openid profile",response_type:e.responseType??"code",userStore:e.storage?new E.WebStorageStateStore({store:U(e.storage)}):void 0,automaticSilentRenew:e.automaticSilentRenew??!0,silent_redirect_uri:e.silentRedirectUri??`${n}/auth/silent-callback`,post_logout_redirect_uri:e.postLogoutRedirectUri??n,includeIdTokenInSilentRenew:!0,accessTokenExpiringNotificationTimeInSeconds:60}}function U(e){if(typeof window>"u")return g();switch(e){case"localStorage":return window.localStorage;case"sessionStorage":return window.sessionStorage;case"memory":return g();default:return window.localStorage}}function g(){const e=new Map;return{getItem:n=>e.get(n)??null,setItem:(n,r)=>e.set(n,r),removeItem:n=>e.delete(n),clear:()=>e.clear(),get length(){return e.size},key:n=>Array.from(e.keys())[n]??null}}const f=new Map,C=e=>`${e.authority}_${e.clientId}`,z=()=>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),M=e=>{const n=C(e),r=f.get(n);if(r)return r;const o=_(e),s=t.ref(!1),c=t.ref(!1),i=t.ref(null),l=t.ref(!1),y=t.ref(null),p=t.computed(()=>!!i.value&&!i.value.expired),u=t.computed(()=>{var k;return((k=i.value)==null?void 0:k.access_token)||null}),d=t.computed(()=>{var k;return!!((k=i.value)!=null&&k.expired)}),h={userManager:o,isInitialized:s,isInitializing:c,user:i,isLoading:l,error:y,isAuthenticated:p,accessToken:u,isExpired:d};return f.set(n,h),h},_=e=>{const n=I(e);return new E.UserManager(n)},S=(e,n,r,o)=>{const s=e instanceof Error?e:new Error(n);return r.value=s,o==null||o(s),s},T=e=>{var n,r;if(!((n=e.authority)!=null&&n.trim()))throw new Error("AuthConfig: authority is required");if(!((r=e.clientId)!=null&&r.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,n=1e4)=>{if(!e.isInitialized.value)return new Promise((r,o)=>{const s=setTimeout(()=>{o(new Error("Authentication initialization timeout"))},n),c=t.watch(e.isInitialized,i=>{i&&(clearTimeout(s),c(),r())},{immediate:!0})})},R=e=>{T(e);const n=M(e),{userManager:r,isInitialized:o,isInitializing:s,user:c,isLoading:i,error:l,isAuthenticated:y,accessToken:p,isExpired:u}=n,d=C(e),h=async()=>{if(!(s.value||o.value))try{s.value=!0,i.value=!0,l.value=null;const a=await r.getUser();if(a)if(!a.expired)c.value=a;else if(e.automaticSilentRenew!==!1)try{await A()}catch(m){console.warn("Silent renewal failed during initialization:",m),await r.removeUser(),c.value=null}else await r.removeUser(),c.value=null}catch(a){S(a,"Failed to initialize authentication",l,e.onError)}finally{i.value=!1,s.value=!1,o.value=!0}},k=async a=>{try{i.value=!0,l.value=null,await r.signinRedirect({state:a})}catch(m){S(m,"Sign in failed",l,e.onError)}finally{i.value=!1}},N=async a=>{try{i.value=!0,l.value=null,c.value=null,await r.signoutRedirect({state:a})}catch(m){S(m,"Sign out failed",l,e.onError)}finally{i.value=!1}},A=async()=>{try{i.value=!0,l.value=null;const a=await r.signinSilent();c.value=a}catch(a){throw S(a,"Silent renewal failed",l,e.onError)}finally{i.value=!1}},$=()=>{l.value=null},F=()=>{r.events.addUserLoaded(a=>{var m;c.value=a,(m=e.onUserLoaded)==null||m.call(e,a)}),r.events.addUserUnloaded(()=>{var a;c.value=null,(a=e.onUserUnloaded)==null||a.call(e)}),r.events.addAccessTokenExpired(()=>{var a;(a=e.onAccessTokenExpired)==null||a.call(e)}),r.events.addAccessTokenExpiring(()=>{var a;(a=e.onAccessTokenExpiring)==null||a.call(e)}),r.events.addSilentRenewError(async a=>{console.warn("Silent renewal failed:",a);try{await r.removeUser(),c.value=null}catch(m){console.error("Failed to remove user after silent renewal error:",m)}S(a,"Silent renewal failed",l,e.onError)})};return!o.value&&!s.value&&(h(),F()),t.onUnmounted(()=>{f.delete(d)}),{user:c,isAuthenticated:y,isLoading:i,error:l,accessToken:p,isExpired:u,signIn:k,signOut:N,silentRenew:A,clearError:$}},v=()=>{const e=z();if(!e)throw new Error("Authentication not initialized. Make sure useAuth() is called in a parent component first.");return{processCallback:async o=>{await b(e);const s=o||window.location.href,c=await e.userManager.signinRedirectCallback(s);return{user:c,state:c.state}},processSilentCallback:async o=>{await b(e);const s=o||window.location.href;await e.userManager.signinSilentCallback(s)},isInitialized:e.isInitialized,isInitializing:e.isInitializing}},V=t.defineComponent({__name:"AuthCallback",props:{onSuccess:{type:Function},onError:{type:Function}},emits:["success","error"],setup(e,{emit:n}){const r=e,o=n,{processCallback:s,isInitializing:c}=v(),i=t.ref(!0),l=t.ref(null),y=async()=>{var p,u;try{const d=await s();(p=r.onSuccess)==null||p.call(r,d.user,d.state),o("success",d.user,d.state)}catch(d){const h=d instanceof Error?d:new Error("Callback processing failed");l.value=h,(u=r.onError)==null||u.call(r,h),o("error",h)}finally{i.value=!1}};return t.onMounted(()=>{y()}),(p,u)=>(t.openBlock(),t.createElementBlock(t.Fragment,null,[(t.unref(c)||i.value)&&!l.value?t.renderSlot(p.$slots,"default",{key:0},()=>[u[0]||(u[0]=t.createElementVNode("p",null,"Processing authentication...",-1))]):t.createCommentVNode("",!0),l.value?t.renderSlot(p.$slots,"error",{key:1,error:l.value},()=>[t.createElementVNode("div",null,[u[1]||(u[1]=t.createElementVNode("h2",null,"Authentication Error",-1)),t.createElementVNode("p",null,t.toDisplayString(l.value.message),1)])]):t.createCommentVNode("",!0)],64))}}),x=t.defineComponent({__name:"SilentCallback",props:{onError:{type:Function}},setup(e){const n=e,{processSilentCallback:r,isInitializing:o}=v(),s=t.ref(null),c=async()=>{var i;try{await r()}catch(l){const y=l instanceof Error?l:new Error("Silent callback processing failed");s.value=y,(i=n.onError)==null||i.call(n,y),console.error("Silent callback error:",y)}};return t.onMounted(()=>{c()}),(i,l)=>(t.openBlock(),t.createElementBlock(t.Fragment,null,[t.unref(o)&&!s.value?t.renderSlot(i.$slots,"default",{key:0},()=>[l[0]||(l[0]=t.createElementVNode("p",null,"Processing silent renewal...",-1))]):t.createCommentVNode("",!0),s.value?t.renderSlot(i.$slots,"error",{key:1,error:s.value},()=>[t.createElementVNode("p",null,"Silent renewal error: "+t.toDisplayString(s.value.message),1)]):t.createCommentVNode("",!0)],64))}});w.AuthCallback=V,w.SilentCallback=x,w.useAuth=R,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
|
@@ -0,0 +1,51 @@
|
|
1
|
+
import { Ref } from 'vue';
|
2
|
+
import { User } from 'oidc-client-ts';
|
3
|
+
export interface AuthConfig {
|
4
|
+
authority: string;
|
5
|
+
clientId: string;
|
6
|
+
clientSecret?: string;
|
7
|
+
clientAuthentication?: 'client_secret_basic' | 'client_secret_post';
|
8
|
+
redirectUri?: string;
|
9
|
+
scope?: string;
|
10
|
+
responseType?: string;
|
11
|
+
storage?: 'localStorage' | 'sessionStorage' | 'memory';
|
12
|
+
automaticSilentRenew?: boolean;
|
13
|
+
silentRedirectUri?: string;
|
14
|
+
postLogoutRedirectUri?: string;
|
15
|
+
onError?: (error: Error) => void;
|
16
|
+
onUserLoaded?: (user: User) => void;
|
17
|
+
onUserUnloaded?: () => void;
|
18
|
+
onAccessTokenExpired?: () => void;
|
19
|
+
onAccessTokenExpiring?: () => void;
|
20
|
+
}
|
21
|
+
export interface AuthState {
|
22
|
+
user: Ref<User | null>;
|
23
|
+
isAuthenticated: Ref<boolean>;
|
24
|
+
isLoading: Ref<boolean>;
|
25
|
+
error: Ref<Error | null>;
|
26
|
+
accessToken: Ref<string | null>;
|
27
|
+
isExpired: Ref<boolean>;
|
28
|
+
}
|
29
|
+
export interface AuthMethods<TState = unknown> {
|
30
|
+
signIn: (state?: TState) => Promise<void>;
|
31
|
+
signOut: (state?: TState) => Promise<void>;
|
32
|
+
silentRenew: () => Promise<void>;
|
33
|
+
clearError: () => void;
|
34
|
+
}
|
35
|
+
export interface AuthCallbackMethods<TState = unknown> {
|
36
|
+
processCallback: (url?: string) => Promise<{
|
37
|
+
user: User;
|
38
|
+
state?: TState;
|
39
|
+
}>;
|
40
|
+
processSilentCallback: (url?: string) => Promise<void>;
|
41
|
+
}
|
42
|
+
export type UseAuthReturn<TState = unknown> = AuthState & AuthMethods<TState>;
|
43
|
+
export interface AuthCallbackProps<TState = unknown> {
|
44
|
+
onSuccess?: (user: User, state?: TState) => void;
|
45
|
+
onError?: (error: Error) => void;
|
46
|
+
}
|
47
|
+
export interface SilentCallbackProps {
|
48
|
+
onError?: (error: Error) => void;
|
49
|
+
}
|
50
|
+
export { User } from 'oidc-client-ts';
|
51
|
+
//# sourceMappingURL=auth.d.ts.map
|
@@ -0,0 +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;AAC/B,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,WAAW,UAAU;IAEvB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oBAAoB,CAAC,EAAE,qBAAqB,GAAG,oBAAoB,CAAC;IAEpE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,OAAO,CAAC,EAAE,cAAc,GAAG,gBAAgB,GAAG,QAAQ,CAAC;IACvD,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAE/B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IACpC,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;IAC5B,oBAAoB,CAAC,EAAE,MAAM,IAAI,CAAC;IAClC,qBAAqB,CAAC,EAAE,MAAM,IAAI,CAAC;CACtC;AAED,MAAM,WAAW,SAAS;IACtB,IAAI,EAAE,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;IACvB,eAAe,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IAC9B,SAAS,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IACxB,KAAK,EAAE,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;IACzB,WAAW,EAAE,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAChC,SAAS,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;CAC3B;AAED,MAAM,WAAW,WAAW,CAAC,MAAM,GAAG,OAAO;IACzC,MAAM,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1C,OAAO,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,WAAW,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,UAAU,EAAE,MAAM,IAAI,CAAC;CAC1B;AAED,MAAM,WAAW,mBAAmB,CAAC,MAAM,GAAG,OAAO;IACjD,eAAe,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,IAAI,EAAE,IAAI,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC3E,qBAAqB,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1D;AAED,MAAM,MAAM,aAAa,CAAC,MAAM,GAAG,OAAO,IAAI,SAAS,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;AAE9E,MAAM,WAAW,iBAAiB,CAAC,MAAM,GAAG,OAAO;IAC/C,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACjD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CACpC;AAED,MAAM,WAAW,mBAAmB;IAChC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CACpC;AAED,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC"}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { AuthConfig } from '../types/auth';
|
2
|
+
import { UserManagerSettings } from 'oidc-client-ts';
|
3
|
+
/**
|
4
|
+
* Creates UserManager settings from auth configuration
|
5
|
+
* @param config - The authentication configuration
|
6
|
+
* @returns UserManager settings object
|
7
|
+
*/
|
8
|
+
export declare function createUserManagerSettings(config: AuthConfig): UserManagerSettings;
|
9
|
+
//# sourceMappingURL=configHelpers.d.ts.map
|
@@ -0,0 +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,CAsBrB"}
|
package/package.json
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
{
|
2
|
+
"name": "vuethenticate",
|
3
|
+
"version": "0.1.0",
|
4
|
+
"description": "A Vue 3 authentication state management library using oidc-client-ts",
|
5
|
+
"keywords": [
|
6
|
+
"vue",
|
7
|
+
"authentication",
|
8
|
+
"reactive",
|
9
|
+
"user",
|
10
|
+
"management",
|
11
|
+
"oidc",
|
12
|
+
"oidc-client-ts",
|
13
|
+
"vue3",
|
14
|
+
"composable"
|
15
|
+
],
|
16
|
+
"homepage": "https://github.com/JulianCissen/vuethenticate",
|
17
|
+
"bugs": "https://github.com/JulianCissen/vuethenticate/issues",
|
18
|
+
"repository": "github:JulianCissen/vuethenticate",
|
19
|
+
"license": "MIT",
|
20
|
+
"author": "Julian Cissen",
|
21
|
+
"files": [
|
22
|
+
"dist/**/*",
|
23
|
+
"README.md",
|
24
|
+
"LICENSE.md"
|
25
|
+
],
|
26
|
+
"umd": "dist/index.umd.js",
|
27
|
+
"module": "dist/index.esm.js",
|
28
|
+
"types": "dist/index.d.ts",
|
29
|
+
"scripts": {
|
30
|
+
"build": "vite build",
|
31
|
+
"dev": "vite build --watch",
|
32
|
+
"type-check": "vue-tsc --noEmit",
|
33
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
34
|
+
},
|
35
|
+
"peerDependencies": {
|
36
|
+
"vue": "^3.0.0"
|
37
|
+
},
|
38
|
+
"dependencies": {
|
39
|
+
"oidc-client-ts": "^3.2.1"
|
40
|
+
},
|
41
|
+
"devDependencies": {
|
42
|
+
"@types/eslint": "^9.6.1",
|
43
|
+
"@types/node": "^22.15.21",
|
44
|
+
"@vitejs/plugin-vue": "^5.2.4",
|
45
|
+
"eslint": "^9.27.0",
|
46
|
+
"eslint-config-prettier": "^10.1.5",
|
47
|
+
"eslint-plugin-jsdoc": "^50.6.17",
|
48
|
+
"eslint-plugin-prettier": "^5.4.0",
|
49
|
+
"eslint-plugin-vue": "^10.0.0",
|
50
|
+
"globals": "^16.2.0",
|
51
|
+
"prettier": "^3.5.3",
|
52
|
+
"typescript": "^5.8.3",
|
53
|
+
"typescript-eslint": "^8.32.1",
|
54
|
+
"vite": "^6.3.5",
|
55
|
+
"vite-plugin-dts": "^4.5.4",
|
56
|
+
"vue": "^3.5.15",
|
57
|
+
"vue-tsc": "^2.2.10"
|
58
|
+
}
|
59
|
+
}
|