@functionalcms/svelte-components 2.19.0 → 2.19.1
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,5 +1,5 @@
|
|
|
1
1
|
import {} from '@sveltejs/kit';
|
|
2
|
-
import { createSession, getSession, deleteSession } from './
|
|
2
|
+
import { createSession, getSession, deleteSession } from './sessionstorage.js';
|
|
3
3
|
import { keycloak } from './authenticationProvider.js';
|
|
4
4
|
const authStateCookieName = `auth_state`;
|
|
5
5
|
const authSessionCookieName = `auth_session`;
|
|
@@ -10,7 +10,7 @@ const logout = (cookies, afterLogoutPath = '/') => {
|
|
|
10
10
|
cookies.delete('auth_session', { path: '/' });
|
|
11
11
|
const sid = cookies.get('auth_session');
|
|
12
12
|
deleteSession(sid);
|
|
13
|
-
headers.append('Set-Cookie',
|
|
13
|
+
headers.append('Set-Cookie', `${authSessionCookieName}=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT;`);
|
|
14
14
|
headers.append('Location', afterLogoutPath);
|
|
15
15
|
}
|
|
16
16
|
else {
|
|
@@ -21,21 +21,29 @@ const logout = (cookies, afterLogoutPath = '/') => {
|
|
|
21
21
|
const createUserSession = async (provider, event) => {
|
|
22
22
|
const token = await provider.getValidation(event);
|
|
23
23
|
const session = await provider.getUser(token);
|
|
24
|
-
const headers = new Headers();
|
|
25
|
-
headers.append('Location', '/');
|
|
26
|
-
headers.append('Set-Cookie', 'auth_state=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT;');
|
|
27
24
|
if (session !== undefined) {
|
|
28
25
|
session.userId = session.sub;
|
|
29
26
|
event.locals.session = session;
|
|
30
27
|
event.locals.accessToken = token.access_token;
|
|
31
28
|
const sessionId = createSession({ session, token }, token.expires_in);
|
|
32
|
-
headers
|
|
29
|
+
const headers = getHeadersWithCookie(sessionId, token.expires_in);
|
|
33
30
|
headers.append('Location', provider.redirectPath);
|
|
31
|
+
// headers.append(
|
|
32
|
+
// 'Set-Cookie',
|
|
33
|
+
// `${authStateCookieName}=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT;`);
|
|
34
|
+
return headers;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
const headers = new Headers();
|
|
38
|
+
headers.append('Location', '/');
|
|
39
|
+
// headers.append(
|
|
40
|
+
// 'Set-Cookie',
|
|
41
|
+
// `${authStateCookieName}=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT;`);
|
|
42
|
+
return headers;
|
|
34
43
|
}
|
|
35
|
-
return headers;
|
|
36
44
|
};
|
|
37
45
|
const loadUserFromSession = (cookies, locals) => {
|
|
38
|
-
const sid = cookies.get(
|
|
46
|
+
const sid = cookies.get(authSessionCookieName);
|
|
39
47
|
const session = getSession(sid);
|
|
40
48
|
if (session) {
|
|
41
49
|
locals.session = session.session;
|
|
@@ -45,6 +53,12 @@ const loadUserFromSession = (cookies, locals) => {
|
|
|
45
53
|
locals.username = "";
|
|
46
54
|
}
|
|
47
55
|
};
|
|
56
|
+
const getHeadersWithCookie = (sessionId, expiresIn) => {
|
|
57
|
+
const cookieHeader = `${authSessionCookieName}=${sessionId}; HttpOnly; Secure; SameSite=strict; Max-Age=${expiresIn}; Path=/`;
|
|
58
|
+
const headers = new Headers();
|
|
59
|
+
headers.append('Set-Cookie', cookieHeader);
|
|
60
|
+
return headers;
|
|
61
|
+
};
|
|
48
62
|
export const authenticationHandle = (issuer, clientId, scope = '', redirectPath = '/') => {
|
|
49
63
|
const provider = keycloak(issuer, clientId, scope, redirectPath);
|
|
50
64
|
return async ({ event, resolve }) => {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as o from "oauth4webapi";
|
|
2
|
-
const
|
|
2
|
+
const authStateCookieName = 'auth_state';
|
|
3
3
|
const stateIdGenerator = () => crypto.randomUUID();
|
|
4
4
|
const getKeycloakIdentity = async (issuer, client_id, scope, redirectUrl) => {
|
|
5
5
|
const state = stateIdGenerator();
|
|
6
|
-
const cookieHeader = `${
|
|
6
|
+
const cookieHeader = `${authStateCookieName}=${state}; HttpOnly; Secure; SameSite=strict; Max-Age=3600; Path=/`;
|
|
7
7
|
const code_challenge = await o.calculatePKCECodeChallenge(state);
|
|
8
8
|
const authorizationUrlSearchParams = new URLSearchParams({
|
|
9
9
|
client_id: client_id,
|
|
@@ -20,7 +20,7 @@ const getKeycloakIdentity = async (issuer, client_id, scope, redirectUrl) => {
|
|
|
20
20
|
return headers;
|
|
21
21
|
};
|
|
22
22
|
const getKeycloakValidation = async (issuer, client_id, scope, event, redirectUrl) => {
|
|
23
|
-
const storedState = event.cookies.get(
|
|
23
|
+
const storedState = event.cookies.get(authStateCookieName);
|
|
24
24
|
const state = event.url.searchParams.get("state");
|
|
25
25
|
if (!storedState || !state || storedState !== state) {
|
|
26
26
|
throw new Error('State not valid');
|
|
@@ -50,7 +50,6 @@ const getKeycloakValidation = async (issuer, client_id, scope, event, redirectUr
|
|
|
50
50
|
throw new Error('Token not validated.');
|
|
51
51
|
}
|
|
52
52
|
const token = await response.json();
|
|
53
|
-
event.cookies.delete(aurthStateCookieName, { path: '/' });
|
|
54
53
|
return token;
|
|
55
54
|
};
|
|
56
55
|
const getUser = async (issuer, token) => {
|
package/package.json
CHANGED
|
File without changes
|