@functionalcms/svelte-components 5.3.0 → 5.3.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,2 +1,2 @@
|
|
|
1
1
|
import type { Handle } from "@sveltejs/kit";
|
|
2
|
-
export declare const machineAuthenticationHandle: (serverUrl: string, clientId: string, clientSecret: string) => Handle;
|
|
2
|
+
export declare const machineAuthenticationHandle: (secret: string, serverUrl: string, clientId: string, clientSecret: string) => Handle;
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { deleteCookie, loadCookie, saveCookie } from "../cookies";
|
|
2
2
|
import { userAuthenticationProvider } from "./userAuthenticationProvider";
|
|
3
|
+
import { encrypt } from "../crypto";
|
|
3
4
|
const accessTokenCookie = "functionalcms_access_token";
|
|
4
5
|
const idTokenCookie = "functionalcms_id_token";
|
|
5
6
|
const refreshTokenCookie = "functionalcms_refresh_token";
|
|
6
|
-
export const machineAuthenticationHandle = (serverUrl, clientId, clientSecret) => {
|
|
7
|
+
export const machineAuthenticationHandle = (secret, serverUrl, clientId, clientSecret) => {
|
|
7
8
|
const provider = userAuthenticationProvider(serverUrl, clientId);
|
|
8
9
|
return async ({ event, resolve }) => {
|
|
9
10
|
try {
|
|
10
11
|
const hasCookie = event.cookies.get(accessTokenCookie);
|
|
11
12
|
if (!hasCookie) {
|
|
12
13
|
const tokens = await login(serverUrl, clientId, clientSecret);
|
|
13
|
-
|
|
14
|
+
const encryptedAccessToken = await encrypt(secret, tokens.access_token);
|
|
15
|
+
event.cookies.set(accessTokenCookie, encryptedAccessToken, { path: "/" });
|
|
14
16
|
if (tokens.refresh_token) {
|
|
15
|
-
|
|
17
|
+
const encryptedRefreshToken = await encrypt(secret, tokens.refresh_token);
|
|
18
|
+
event.cookies.set(refreshTokenCookie, encryptedRefreshToken, { path: "/" });
|
|
16
19
|
}
|
|
17
20
|
}
|
|
18
21
|
}
|