@functionalcms/svelte-components 2.19.1 → 2.19.2
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.
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { type Handle } from '@sveltejs/kit';
|
|
2
|
-
export declare const authenticationHandle: (
|
|
2
|
+
export declare const authenticationHandle: (scope?: string, redirectPath?: string) => Handle;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AUTH_KEYCLOAK_ID, AUTH_KEYCLOAK_ISSUER } from '$env/static/private';
|
|
1
2
|
import {} from '@sveltejs/kit';
|
|
2
3
|
import { createSession, getSession, deleteSession } from './sessionstorage.js';
|
|
3
4
|
import { keycloak } from './authenticationProvider.js';
|
|
@@ -21,26 +22,19 @@ const logout = (cookies, afterLogoutPath = '/') => {
|
|
|
21
22
|
const createUserSession = async (provider, event) => {
|
|
22
23
|
const token = await provider.getValidation(event);
|
|
23
24
|
const session = await provider.getUser(token);
|
|
25
|
+
const headers = new Headers();
|
|
24
26
|
if (session !== undefined) {
|
|
25
27
|
session.userId = session.sub;
|
|
26
28
|
event.locals.session = session;
|
|
27
29
|
event.locals.accessToken = token.access_token;
|
|
28
30
|
const sessionId = createSession({ session, token }, token.expires_in);
|
|
29
|
-
const headers = getHeadersWithCookie(sessionId, token.expires_in);
|
|
30
31
|
headers.append('Location', provider.redirectPath);
|
|
31
|
-
|
|
32
|
-
// 'Set-Cookie',
|
|
33
|
-
// `${authStateCookieName}=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT;`);
|
|
34
|
-
return headers;
|
|
32
|
+
headers.append('Set-Cookie', `${authSessionCookieName}=${sessionId}; HttpOnly; Secure; SameSite=strict; Max-Age=${token.expires_in}; Path=/`);
|
|
35
33
|
}
|
|
36
34
|
else {
|
|
37
|
-
const headers = new Headers();
|
|
38
35
|
headers.append('Location', '/');
|
|
39
|
-
// headers.append(
|
|
40
|
-
// 'Set-Cookie',
|
|
41
|
-
// `${authStateCookieName}=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT;`);
|
|
42
|
-
return headers;
|
|
43
36
|
}
|
|
37
|
+
return headers;
|
|
44
38
|
};
|
|
45
39
|
const loadUserFromSession = (cookies, locals) => {
|
|
46
40
|
const sid = cookies.get(authSessionCookieName);
|
|
@@ -53,16 +47,10 @@ const loadUserFromSession = (cookies, locals) => {
|
|
|
53
47
|
locals.username = "";
|
|
54
48
|
}
|
|
55
49
|
};
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
const headers = new Headers();
|
|
59
|
-
headers.append('Set-Cookie', cookieHeader);
|
|
60
|
-
return headers;
|
|
61
|
-
};
|
|
62
|
-
export const authenticationHandle = (issuer, clientId, scope = '', redirectPath = '/') => {
|
|
63
|
-
const provider = keycloak(issuer, clientId, scope, redirectPath);
|
|
50
|
+
export const authenticationHandle = (scope = '', redirectPath = '/') => {
|
|
51
|
+
const provider = keycloak(AUTH_KEYCLOAK_ISSUER, AUTH_KEYCLOAK_ID, scope, redirectPath);
|
|
64
52
|
return async ({ event, resolve }) => {
|
|
65
|
-
//login user check
|
|
53
|
+
//login user check + refresh
|
|
66
54
|
if (event.url.pathname.startsWith('/')) {
|
|
67
55
|
loadUserFromSession(event.cookies, event.locals);
|
|
68
56
|
}
|