piral-oidc 1.0.0-pre.2036 → 1.0.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/LICENSE +1 -1
- package/README.md +22 -8
- package/esm/OidcError.d.ts +13 -0
- package/esm/OidcError.js +30 -0
- package/esm/OidcError.js.map +1 -0
- package/esm/create.d.ts +6 -0
- package/esm/create.js +17 -0
- package/esm/create.js.map +1 -0
- package/esm/index.d.ts +3 -0
- package/esm/index.js +4 -0
- package/esm/index.js.map +1 -0
- package/esm/setup.d.ts +6 -0
- package/esm/setup.js +201 -0
- package/esm/setup.js.map +1 -0
- package/esm/types.d.ts +270 -0
- package/esm/types.js +61 -0
- package/esm/types.js.map +1 -0
- package/lib/OidcError.js +17 -23
- package/lib/OidcError.js.map +1 -1
- package/lib/create.d.ts +2 -2
- package/lib/create.js +3 -3
- package/lib/create.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/setup.js +121 -139
- package/lib/setup.js.map +1 -1
- package/lib/types.d.ts +37 -3
- package/lib/types.js.map +1 -1
- package/package.json +30 -6
- package/piral-oidc.min.js +103 -0
- package/src/create.test.ts +3 -3
- package/src/create.ts +2 -2
- package/src/setup.ts +17 -1
- package/src/types.ts +36 -2
package/src/create.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createOidcApi } from './create';
|
|
2
|
-
import {
|
|
2
|
+
import { PiletOidcApi } from './types';
|
|
3
3
|
|
|
4
4
|
declare module 'piral-oidc/src/types' {
|
|
5
5
|
interface PiralCustomOidcProfile {
|
|
@@ -33,7 +33,7 @@ describe('Piral-Oidc create module', () => {
|
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
it('api.getAccessToken() should return the client.token()', () => {
|
|
36
|
-
const api = createOidcApi(mock)(context) as
|
|
36
|
+
const api = createOidcApi(mock)(context) as PiletOidcApi;
|
|
37
37
|
expect(api.getAccessToken()).toBe(mockToken);
|
|
38
38
|
});
|
|
39
39
|
|
|
@@ -42,7 +42,7 @@ describe('Piral-Oidc create module', () => {
|
|
|
42
42
|
});
|
|
43
43
|
|
|
44
44
|
it('api.getProfile() should return client.account()', async () => {
|
|
45
|
-
const api = createOidcApi(mock)(context) as
|
|
45
|
+
const api = createOidcApi(mock)(context) as PiletOidcApi;
|
|
46
46
|
const profile = await api.getProfile();
|
|
47
47
|
expect(profile).toEqual(mockProfile);
|
|
48
48
|
// This is asserting the custom claims works, otherwise we would get a type error
|
package/src/create.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { PiralPlugin } from 'piral-core';
|
|
2
|
-
import {
|
|
2
|
+
import { PiletOidcApi, OidcClient } from './types';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Creates new Pilet API extensions for the integration of OpenID Connect.
|
|
6
6
|
*/
|
|
7
|
-
export function createOidcApi(client: OidcClient): PiralPlugin<
|
|
7
|
+
export function createOidcApi(client: OidcClient): PiralPlugin<PiletOidcApi> {
|
|
8
8
|
return (context) => {
|
|
9
9
|
context.on('before-fetch', client.extendHeaders);
|
|
10
10
|
|
package/src/setup.ts
CHANGED
|
@@ -31,12 +31,18 @@ export function setupOidcClient(config: OidcConfig): OidcClient {
|
|
|
31
31
|
signInRedirectParams,
|
|
32
32
|
postLogoutRedirectUri = location.origin,
|
|
33
33
|
responseType,
|
|
34
|
+
responseMode,
|
|
34
35
|
scopes,
|
|
35
36
|
restrict = false,
|
|
36
37
|
parentName,
|
|
37
38
|
appUri,
|
|
38
39
|
logLevel,
|
|
39
40
|
userStore,
|
|
41
|
+
extraQueryParams,
|
|
42
|
+
uiLocales,
|
|
43
|
+
metadata,
|
|
44
|
+
metadataUrl,
|
|
45
|
+
monitorSession,
|
|
40
46
|
} = config;
|
|
41
47
|
|
|
42
48
|
const isMainWindow = () => (parentName ? parentName === window.parent?.name : window === window.top);
|
|
@@ -51,7 +57,13 @@ export function setupOidcClient(config: OidcConfig): OidcClient {
|
|
|
51
57
|
client_secret: clientSecret,
|
|
52
58
|
response_type: responseType,
|
|
53
59
|
scope: scopes?.join(' '),
|
|
54
|
-
userStore
|
|
60
|
+
userStore,
|
|
61
|
+
extraQueryParams,
|
|
62
|
+
ui_locales: uiLocales,
|
|
63
|
+
response_mode: responseMode,
|
|
64
|
+
metadata,
|
|
65
|
+
metadataUrl,
|
|
66
|
+
monitorSession,
|
|
55
67
|
});
|
|
56
68
|
|
|
57
69
|
if (logLevel !== undefined) {
|
|
@@ -200,12 +212,16 @@ export function setupOidcClient(config: OidcConfig): OidcClient {
|
|
|
200
212
|
});
|
|
201
213
|
|
|
202
214
|
return {
|
|
215
|
+
_: userManager,
|
|
203
216
|
login() {
|
|
204
217
|
return userManager.signinRedirect(signInRedirectParams);
|
|
205
218
|
},
|
|
206
219
|
logout() {
|
|
207
220
|
return userManager.signoutRedirect();
|
|
208
221
|
},
|
|
222
|
+
revoke() {
|
|
223
|
+
return userManager.revokeAccessToken();
|
|
224
|
+
},
|
|
209
225
|
handleAuthentication,
|
|
210
226
|
extendHeaders(req) {
|
|
211
227
|
if (!restrict) {
|
package/src/types.ts
CHANGED
|
@@ -47,6 +47,12 @@ export interface OidcConfig {
|
|
|
47
47
|
* is used.
|
|
48
48
|
*/
|
|
49
49
|
responseType?: string;
|
|
50
|
+
/**
|
|
51
|
+
* The response mode, which is usually already configured well
|
|
52
|
+
* via the responseType. By default, the responseType `code` will
|
|
53
|
+
* get `query` and responseType `token` will get `fragment`.
|
|
54
|
+
*/
|
|
55
|
+
responseMode?: string;
|
|
50
56
|
/**
|
|
51
57
|
* The scopes to be used. By default, `openid` is used.
|
|
52
58
|
*/
|
|
@@ -73,6 +79,26 @@ export interface OidcConfig {
|
|
|
73
79
|
* This defaults to oidc-client's WebStorageStateStore, using sessionStorage as the internal store
|
|
74
80
|
*/
|
|
75
81
|
userStore?: OidcStore;
|
|
82
|
+
/**
|
|
83
|
+
* Provides some extra query parameters. These are included in the authorization request.
|
|
84
|
+
*/
|
|
85
|
+
extraQueryParams?: Record<string, any>;
|
|
86
|
+
/**
|
|
87
|
+
* Sets the optiopnal ui_locales parameter to set the language of the login page.
|
|
88
|
+
*/
|
|
89
|
+
uiLocales?: string;
|
|
90
|
+
/**
|
|
91
|
+
* Sets the metadata if the OIDC service does not allow querying it for whatever reason.
|
|
92
|
+
*/
|
|
93
|
+
metadata?: any;
|
|
94
|
+
/**
|
|
95
|
+
* Overrides the default metadata URL if the server does not follow the standard paths.
|
|
96
|
+
*/
|
|
97
|
+
metadataUrl?: string;
|
|
98
|
+
/**
|
|
99
|
+
* Determines if the OIDCS session should be automatically monitored.
|
|
100
|
+
*/
|
|
101
|
+
monitorSession?: boolean;
|
|
76
102
|
}
|
|
77
103
|
|
|
78
104
|
/**
|
|
@@ -135,6 +161,10 @@ export interface OidcRequest {
|
|
|
135
161
|
}
|
|
136
162
|
|
|
137
163
|
export interface OidcClient {
|
|
164
|
+
/**
|
|
165
|
+
* The underlying OIDC client.
|
|
166
|
+
*/
|
|
167
|
+
_: any;
|
|
138
168
|
/**
|
|
139
169
|
* Performs a login. Will do nothing when called from a non-top window.
|
|
140
170
|
*/
|
|
@@ -143,6 +173,10 @@ export interface OidcClient {
|
|
|
143
173
|
* Performs a logout.
|
|
144
174
|
*/
|
|
145
175
|
logout(): Promise<void>;
|
|
176
|
+
/**
|
|
177
|
+
* Revokes the access token.
|
|
178
|
+
*/
|
|
179
|
+
revoke(): Promise<void>;
|
|
146
180
|
/**
|
|
147
181
|
* Performs a login when the app needs a new token, handles callbacks when on
|
|
148
182
|
* a callback URL, and redirects into the app route if the client was configured with an `appUri`.
|
|
@@ -169,7 +203,7 @@ export interface OidcClient {
|
|
|
169
203
|
extendHeaders(req: OidcRequest): void;
|
|
170
204
|
}
|
|
171
205
|
|
|
172
|
-
export interface
|
|
206
|
+
export interface PiletOidcApi {
|
|
173
207
|
/**
|
|
174
208
|
* Gets the currently valid access token, if any.
|
|
175
209
|
*/
|
|
@@ -182,7 +216,7 @@ export interface PiralOidcApi {
|
|
|
182
216
|
}
|
|
183
217
|
|
|
184
218
|
declare module 'piral-core/lib/types/custom' {
|
|
185
|
-
interface PiletCustomApi extends
|
|
219
|
+
interface PiletCustomApi extends PiletOidcApi {}
|
|
186
220
|
}
|
|
187
221
|
|
|
188
222
|
/**
|