@functionalcms/svelte-components 2.18.3 → 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.
- package/dist/auth/authenticationHandle.js +22 -8
- package/dist/auth/authenticationProvider.js +3 -4
- package/dist/components/Link.svelte +1 -0
- package/dist/index-server.d.ts +2 -1
- package/dist/index-server.js +2 -1
- package/dist/server-side/getServices.d.ts +5 -0
- package/dist/server-side/getServices.js +30 -0
- package/package.json +1 -1
- /package/dist/auth/{sessionStorage.d.ts → sessionstorage.d.ts} +0 -0
|
@@ -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/dist/index-server.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { authenticationHandle } from './auth/authenticationHandle.js';
|
|
2
2
|
import authorizationHandle from './auth/authorizationHandle.js';
|
|
3
3
|
import errorHandler from './auth/errorHandle.js';
|
|
4
|
-
|
|
4
|
+
import { getBlobService, getCommunicationService, getDataService, getTemplateService, getWebsiteService } from './server-side/getServices.js';
|
|
5
|
+
export { authenticationHandle, authorizationHandle, errorHandler, getDataService, getCommunicationService, getWebsiteService, getTemplateService, getBlobService };
|
package/dist/index-server.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { authenticationHandle } from './auth/authenticationHandle.js';
|
|
2
2
|
import authorizationHandle from './auth/authorizationHandle.js';
|
|
3
3
|
import errorHandler from './auth/errorHandle.js';
|
|
4
|
-
|
|
4
|
+
import { getBlobService, getCommunicationService, getDataService, getTemplateService, getWebsiteService } from './server-side/getServices.js';
|
|
5
|
+
export { authenticationHandle, authorizationHandle, errorHandler, getDataService, getCommunicationService, getWebsiteService, getTemplateService, getBlobService };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const getDataService: (locals: any) => any;
|
|
2
|
+
export declare const getCommunicationService: (locals: any) => any;
|
|
3
|
+
export declare const getWebsiteService: (locals: any) => any;
|
|
4
|
+
export declare const getTemplateService: (locals: any) => any;
|
|
5
|
+
export declare const getBlobService: (locals: any) => any;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { DOMAIN, ENDPOINT } from "$env/static/private";
|
|
2
|
+
import { CommunicationService, DataService, TemplateService, WebsitesService, BlobService } from "@functionalcms/services";
|
|
3
|
+
const getAccessToken = (locals) => {
|
|
4
|
+
return locals.token.access_token;
|
|
5
|
+
};
|
|
6
|
+
export const getDataService = (locals) => {
|
|
7
|
+
const accessToken = getAccessToken(locals);
|
|
8
|
+
const service = new DataService(accessToken, DOMAIN, ENDPOINT);
|
|
9
|
+
return service;
|
|
10
|
+
};
|
|
11
|
+
export const getCommunicationService = (locals) => {
|
|
12
|
+
const accessToken = getAccessToken(locals);
|
|
13
|
+
const service = new CommunicationService(accessToken, DOMAIN, ENDPOINT);
|
|
14
|
+
return service;
|
|
15
|
+
};
|
|
16
|
+
export const getWebsiteService = (locals) => {
|
|
17
|
+
const accessToken = getAccessToken(locals);
|
|
18
|
+
const service = new WebsitesService(accessToken, DOMAIN, ENDPOINT);
|
|
19
|
+
return service;
|
|
20
|
+
};
|
|
21
|
+
export const getTemplateService = (locals) => {
|
|
22
|
+
const accessToken = getAccessToken(locals);
|
|
23
|
+
const service = new TemplateService(accessToken, DOMAIN, ENDPOINT);
|
|
24
|
+
return service;
|
|
25
|
+
};
|
|
26
|
+
export const getBlobService = (locals) => {
|
|
27
|
+
const accessToken = getAccessToken(locals);
|
|
28
|
+
const service = new BlobService(accessToken, DOMAIN, ENDPOINT);
|
|
29
|
+
return service;
|
|
30
|
+
};
|
package/package.json
CHANGED
|
File without changes
|