@functionalcms/svelte-components 5.2.5 → 5.3.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/index-server.d.ts +2 -2
- package/dist/index-server.js +2 -2
- package/dist/server-side/auth/machine_authentication.d.ts +2 -0
- package/dist/server-side/auth/machine_authentication.js +42 -0
- package/dist/server-side/auth/userAuthenticationProvider.d.ts +1 -1
- package/dist/server-side/auth/{authentication.d.ts → user_authentication.d.ts} +1 -1
- package/dist/server-side/auth/{authentication.js → user_authentication.js} +3 -1
- package/package.json +1 -1
- package/dist/server-side/auth/machineAuthenticationProvider.d.ts +0 -2
- package/dist/server-side/auth/machineAuthenticationProvider.js +0 -32
package/dist/index-server.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { default as authorizationHandle } from './server-side/auth/authorizationHandle.js';
|
|
2
2
|
export { default as errorHandler } from './server-side/auth/errorHandle.js';
|
|
3
|
-
export { authenticationHandle } from './server-side/auth/
|
|
4
|
-
export {
|
|
3
|
+
export { authenticationHandle } from './server-side/auth/user_authentication.js';
|
|
4
|
+
export { machineAuthenticationHandle } from './server-side/auth/machine_authentication.js';
|
|
5
5
|
export { userAuthenticationProvider } from './server-side/auth/userAuthenticationProvider.js';
|
|
6
6
|
export { hookSequence } from './server-side/functionalSequence.js';
|
|
7
7
|
export { sessionStorageHandler } from './server-side/handlers/sessionStorageHandler.js';
|
package/dist/index-server.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { default as authorizationHandle } from './server-side/auth/authorizationHandle.js';
|
|
2
2
|
export { default as errorHandler } from './server-side/auth/errorHandle.js';
|
|
3
|
-
export { authenticationHandle } from './server-side/auth/
|
|
4
|
-
export {
|
|
3
|
+
export { authenticationHandle } from './server-side/auth/user_authentication.js';
|
|
4
|
+
export { machineAuthenticationHandle } from './server-side/auth/machine_authentication.js';
|
|
5
5
|
export { userAuthenticationProvider } from './server-side/auth/userAuthenticationProvider.js';
|
|
6
6
|
export { hookSequence } from './server-side/functionalSequence.js';
|
|
7
7
|
export { sessionStorageHandler } from './server-side/handlers/sessionStorageHandler.js';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { deleteCookie, loadCookie, saveCookie } from "../cookies";
|
|
2
|
+
import { userAuthenticationProvider } from "./userAuthenticationProvider";
|
|
3
|
+
const accessTokenCookie = "functionalcms_access_token";
|
|
4
|
+
const idTokenCookie = "functionalcms_id_token";
|
|
5
|
+
const refreshTokenCookie = "functionalcms_refresh_token";
|
|
6
|
+
export const machineAuthenticationHandle = (serverUrl, clientId, clientSecret) => {
|
|
7
|
+
const provider = userAuthenticationProvider(serverUrl, clientId);
|
|
8
|
+
return async ({ event, resolve }) => {
|
|
9
|
+
try {
|
|
10
|
+
const hasCookie = event.cookies.get(accessTokenCookie);
|
|
11
|
+
if (!hasCookie) {
|
|
12
|
+
const tokens = await login(serverUrl, clientId, clientSecret);
|
|
13
|
+
event.cookies.set(accessTokenCookie, tokens.access_token, { path: "/" });
|
|
14
|
+
if (tokens.refresh_token) {
|
|
15
|
+
event.cookies.set(refreshTokenCookie, tokens.refresh_token, { path: "/" });
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
console.error("Authentication error:", error);
|
|
21
|
+
}
|
|
22
|
+
return resolve(event);
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
const login = async (serverUrl, clientId, clientSecret) => {
|
|
26
|
+
const tokenRes = await fetch(`${serverUrl}/api/login/oauth/access_token`, {
|
|
27
|
+
method: "POST",
|
|
28
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
29
|
+
body: new URLSearchParams({
|
|
30
|
+
grant_type: "client_credentials",
|
|
31
|
+
client_id: clientId,
|
|
32
|
+
client_secret: clientSecret,
|
|
33
|
+
scope: "profile openid email offline_access"
|
|
34
|
+
})
|
|
35
|
+
});
|
|
36
|
+
const tokens = await tokenRes.json();
|
|
37
|
+
return {
|
|
38
|
+
access_token: tokens.access_token,
|
|
39
|
+
id_token: tokens.id_token,
|
|
40
|
+
refresh_token: tokens.refresh_token,
|
|
41
|
+
};
|
|
42
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { AuthenticationProvider } from "./
|
|
1
|
+
import type { AuthenticationProvider } from "./user_authentication";
|
|
2
2
|
export declare const userAuthenticationProvider: (serverUrl: string, clientId: string) => AuthenticationProvider;
|
|
@@ -13,4 +13,4 @@ export type AuthenticationProvider = {
|
|
|
13
13
|
handleLogin(callbackUrl: URL): Promise<SigninResponse>;
|
|
14
14
|
handleCallback: (state: string, codeVerifier: string, eventUrl: URL) => Promise<CallbackResponse>;
|
|
15
15
|
};
|
|
16
|
-
export declare const authenticationHandle: (secret: string,
|
|
16
|
+
export declare const authenticationHandle: (secret: string, serverUrl: string, clientId: string) => Handle;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { deleteCookie, loadCookie, saveCookie } from "../cookies";
|
|
2
|
+
import { userAuthenticationProvider } from "./userAuthenticationProvider";
|
|
2
3
|
const pkceCookieName = "functionalcms_pkce";
|
|
3
4
|
const stateCookieName = "functionalcms_state";
|
|
4
5
|
const accessTokenCookie = "functionalcms_access_token";
|
|
5
6
|
const idTokenCookie = "functionalcms_id_token";
|
|
6
7
|
const refreshTokenCookie = "functionalcms_refresh_token";
|
|
7
|
-
export const authenticationHandle = (secret,
|
|
8
|
+
export const authenticationHandle = (secret, serverUrl, clientId) => {
|
|
9
|
+
const provider = userAuthenticationProvider(serverUrl, clientId);
|
|
8
10
|
return async ({ event, resolve }) => {
|
|
9
11
|
try {
|
|
10
12
|
if (event.url.pathname === '/auth/callback') {
|
package/package.json
CHANGED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
export const machineAuthenticationProvider = (serverUrl, clientId, clientSecret) => {
|
|
2
|
-
const handleLogin = (callbackUrl) => {
|
|
3
|
-
const response = {
|
|
4
|
-
state: "",
|
|
5
|
-
codeVerifier: "",
|
|
6
|
-
authorisationUrl: callbackUrl.toString(),
|
|
7
|
-
};
|
|
8
|
-
return Promise.resolve(response);
|
|
9
|
-
};
|
|
10
|
-
const handleCallback = async (state, codeVerifier, eventUrl) => {
|
|
11
|
-
const tokenRes = await fetch(`${serverUrl}/api/login/oauth/access_token`, {
|
|
12
|
-
method: "POST",
|
|
13
|
-
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
14
|
-
body: new URLSearchParams({
|
|
15
|
-
grant_type: "client_credentials",
|
|
16
|
-
client_id: clientId,
|
|
17
|
-
client_secret: clientSecret,
|
|
18
|
-
scope: "profile openid email offline_access"
|
|
19
|
-
})
|
|
20
|
-
});
|
|
21
|
-
const tokens = await tokenRes.json();
|
|
22
|
-
return {
|
|
23
|
-
access_token: tokens.access_token,
|
|
24
|
-
id_token: tokens.id_token,
|
|
25
|
-
refresh_token: tokens.refresh_token,
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
return {
|
|
29
|
-
handleLogin,
|
|
30
|
-
handleCallback,
|
|
31
|
-
};
|
|
32
|
-
};
|