@functionalcms/svelte-components 2.27.0 → 2.28.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.
@@ -1,12 +1,13 @@
1
1
  import {} from '@sveltejs/kit';
2
2
  const authSessionCookieName = `auth_session`;
3
- const logout = async (cookies, sessionProvider, afterLogoutPath = '/') => {
3
+ const logout = async (cookies, token, provider, sessionProvider, afterLogoutPath = '/') => {
4
4
  const headers = new Headers();
5
5
  const state = cookies.get(authSessionCookieName);
6
6
  if (state) {
7
7
  cookies.delete('auth_session', { path: '/' });
8
8
  const sid = cookies.get('auth_session');
9
9
  await sessionProvider.deleteSession(sid);
10
+ await provider.logout(token);
10
11
  headers.append('Set-Cookie', `${authSessionCookieName}=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT;`);
11
12
  headers.append('Location', afterLogoutPath);
12
13
  }
@@ -53,7 +54,7 @@ export const authenticationHandle = (provider, sessionProvider) => {
53
54
  //logout
54
55
  if (event.url.pathname === '/auth/logout') {
55
56
  // await provider.logout();
56
- const headers = await logout(event.cookies, sessionProvider);
57
+ const headers = await logout(event.cookies, event.locals.token, provider, sessionProvider);
57
58
  return new Response('Logging Out...', { status: 303, headers });
58
59
  }
59
60
  // login
@@ -3,5 +3,6 @@ export declare const machineAuthenticationProvider: (scope?: string, redirectPat
3
3
  getAuthIdentity: (domain: string) => Promise<any>;
4
4
  getValidation: (event: any) => Promise<Token>;
5
5
  getUser: (token: Token) => Promise<any>;
6
+ logout: (token: Token) => Promise<void>;
6
7
  redirectPath: string;
7
8
  };
@@ -63,6 +63,23 @@ const getUser = async (issuer, token) => {
63
63
  });
64
64
  }
65
65
  };
66
+ const logout = async (issuer, clientId, token) => {
67
+ const response = await fetch(`${issuer}/protocol/openid-connect/logout`, {
68
+ method: "POST",
69
+ body: new URLSearchParams({
70
+ client_id: clientId,
71
+ access_token: token.access_token,
72
+ }),
73
+ headers: {
74
+ "Content-Type": "application/x-www-form-urlencoded",
75
+ Accept: "application/json"
76
+ }
77
+ });
78
+ if (!response.ok) {
79
+ console.log('Response was NOT okay');
80
+ throw new Error('Token not validated.');
81
+ }
82
+ };
66
83
  export const machineAuthenticationProvider = (scope = '', redirectPath = '/') => {
67
84
  const extendedScope = `openid profile offline_access ${scope}`;
68
85
  const redirectUrl = "/auth/validate";
@@ -80,6 +97,9 @@ export const machineAuthenticationProvider = (scope = '', redirectPath = '/') =>
80
97
  const user = await getUser(AUTH_KEYCLOAK_ISSUER, token);
81
98
  return user;
82
99
  },
100
+ logout: async (token) => {
101
+ await logout(AUTH_KEYCLOAK_ISSUER, AUTH_KEYCLOAK_ID, token);
102
+ },
83
103
  redirectPath
84
104
  };
85
105
  };
@@ -22,6 +22,7 @@ export interface IProvider {
22
22
  getAuthIdentity(domain: string): Promise<any>;
23
23
  getValidation(event: any): Promise<Token>;
24
24
  getUser(token: Token): any;
25
+ logout(token: Token): Promise<any>;
25
26
  }
26
27
  export interface ISessionStorage {
27
28
  clean(): Promise<void>;
@@ -3,5 +3,6 @@ export declare const userAuthenticationProvider: (scope?: string, redirectPath?:
3
3
  getAuthIdentity: (domain: string) => Promise<any>;
4
4
  getValidation: (event: any) => Promise<Token>;
5
5
  getUser: (token: Token) => Promise<any>;
6
+ logout: (token: Token) => Promise<void>;
6
7
  redirectPath: string;
7
8
  };
@@ -76,6 +76,23 @@ const getUser = async (issuer, token) => {
76
76
  });
77
77
  }
78
78
  };
79
+ const logout = async (issuer, clientId, token) => {
80
+ const response = await fetch(`${issuer}/protocol/openid-connect/logout`, {
81
+ method: "POST",
82
+ body: new URLSearchParams({
83
+ client_id: clientId,
84
+ access_token: token.access_token,
85
+ }),
86
+ headers: {
87
+ "Content-Type": "application/x-www-form-urlencoded",
88
+ Accept: "application/json"
89
+ }
90
+ });
91
+ if (!response.ok) {
92
+ console.log('Response was NOT okay');
93
+ throw new Error('Token not validated.');
94
+ }
95
+ };
79
96
  export const userAuthenticationProvider = (scope = '', redirectPath = '/') => {
80
97
  const extendedScope = `openid profile offline_access ${scope}`;
81
98
  const redirectUrl = "/auth/validate";
@@ -93,6 +110,9 @@ export const userAuthenticationProvider = (scope = '', redirectPath = '/') => {
93
110
  const user = await getUser(AUTH_KEYCLOAK_ISSUER, token);
94
111
  return user;
95
112
  },
113
+ logout: async (token) => {
114
+ await logout(AUTH_KEYCLOAK_ISSUER, AUTH_KEYCLOAK_ID, token);
115
+ },
96
116
  redirectPath
97
117
  };
98
118
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@functionalcms/svelte-components",
3
- "version": "2.27.0",
3
+ "version": "2.28.0",
4
4
  "watch": {
5
5
  "build": {
6
6
  "patterns": [