@forgerock/sdk-oidc 1.2.0 → 1.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/CHANGELOG.md +22 -0
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/coverage-final.json +4 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +131 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +210 -0
- package/coverage/src/index.html +116 -0
- package/coverage/src/index.ts.html +109 -0
- package/coverage/src/lib/authorize.effects.ts.html +265 -0
- package/coverage/src/lib/index.html +131 -0
- package/coverage/src/lib/state-pkce.effects.ts.html +274 -0
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +8 -2
- package/dist/src/lib/authorize.effects.d.ts +1 -1
- package/dist/src/lib/authorize.effects.d.ts.map +1 -1
- package/dist/src/lib/authorize.effects.js +4 -2
- package/dist/src/lib/state-pkce.effects.d.ts +2 -7
- package/dist/src/lib/state-pkce.effects.d.ts.map +1 -1
- package/dist/src/lib/state-pkce.effects.js +7 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/eslint.config.mjs +1 -1
- package/package.json +3 -3
- package/src/index.ts +8 -2
- package/src/lib/authorize.effects.ts +5 -3
- package/src/lib/authorize.test.ts +138 -0
- package/src/lib/state-pkce.effects.ts +5 -7
- package/src/lib/state-pkce.test.ts +121 -0
- package/vite.config.ts +0 -0
- package/dist/src/lib/authorize.types.d.ts +0 -25
- package/dist/src/lib/authorize.types.d.ts.map +0 -1
- package/dist/src/lib/authorize.types.js +0 -7
- package/dist/src/lib/index.d.ts +0 -3
- package/dist/src/lib/index.d.ts.map +0 -1
- package/dist/src/lib/index.js +0 -8
- package/src/lib/authorize.types.ts +0 -32
- package/src/lib/index.ts +0 -9
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Ping Identity Corporation. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* This software may be modified and distributed under the terms
|
|
5
|
+
* of the MIT license. See the LICENSE file for details.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { describe, expect, it, beforeEach } from 'vitest';
|
|
9
|
+
import {
|
|
10
|
+
generateAndStoreAuthUrlValues,
|
|
11
|
+
getStorageKey,
|
|
12
|
+
getStoredAuthUrlValues,
|
|
13
|
+
} from './state-pkce.effects.js';
|
|
14
|
+
import type { GenerateAndStoreAuthUrlValues } from '@forgerock/sdk-types';
|
|
15
|
+
|
|
16
|
+
const mockSessionStorage = (() => {
|
|
17
|
+
let store: { [key: string]: string } = {};
|
|
18
|
+
return {
|
|
19
|
+
getItem: (key: string) => store[key] || null,
|
|
20
|
+
setItem: (key: string, value: string) => {
|
|
21
|
+
store[key] = value;
|
|
22
|
+
},
|
|
23
|
+
removeItem: (key: string) => {
|
|
24
|
+
delete store[key];
|
|
25
|
+
},
|
|
26
|
+
clear: () => {
|
|
27
|
+
store = {};
|
|
28
|
+
},
|
|
29
|
+
length: 0,
|
|
30
|
+
key: (index: number) => Object.keys(store)[index] || null,
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
|
|
34
|
+
describe('PKCE', () => {
|
|
35
|
+
beforeEach(() => {
|
|
36
|
+
if (typeof sessionStorage === 'undefined') {
|
|
37
|
+
global.sessionStorage = mockSessionStorage;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
sessionStorage.clear();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const mockOptions: GenerateAndStoreAuthUrlValues = {
|
|
44
|
+
clientId: 'test-client',
|
|
45
|
+
redirectUri: 'http://localhost:8080',
|
|
46
|
+
scope: 'openid profile',
|
|
47
|
+
responseType: 'code',
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
describe('getStorageKey', () => {
|
|
51
|
+
const clientId = 'test-client-id';
|
|
52
|
+
|
|
53
|
+
it('should generate storage key with default prefix', () => {
|
|
54
|
+
const key = getStorageKey(clientId);
|
|
55
|
+
expect(key).toBe('FR-SDK-authflow-test-client-id');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should generate storage key with custom prefix', () => {
|
|
59
|
+
const customPrefix = 'CUSTOM';
|
|
60
|
+
const key = getStorageKey(clientId, customPrefix);
|
|
61
|
+
expect(key).toBe('CUSTOM-authflow-test-client-id');
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe('generateAndStoreAuthUrlValues', () => {
|
|
66
|
+
it('should generate PKCE values', () => {
|
|
67
|
+
const [options] = generateAndStoreAuthUrlValues(mockOptions);
|
|
68
|
+
|
|
69
|
+
expect(options).toBeDefined();
|
|
70
|
+
expect(options).toHaveProperty('state');
|
|
71
|
+
expect(options).toHaveProperty('verifier');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('should store options in sessionStorage when storage function is called', () => {
|
|
75
|
+
const [options, storeAuthUrl] = generateAndStoreAuthUrlValues(mockOptions);
|
|
76
|
+
storeAuthUrl();
|
|
77
|
+
|
|
78
|
+
const storageKey = getStorageKey(mockOptions.clientId, mockOptions.prefix);
|
|
79
|
+
const storedValue = sessionStorage.getItem(storageKey);
|
|
80
|
+
expect(storedValue).toBeDefined();
|
|
81
|
+
|
|
82
|
+
const parsedValue = JSON.parse(storedValue as string);
|
|
83
|
+
expect(parsedValue).toEqual(options);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe('getStoredAuthUrlValues', () => {
|
|
88
|
+
it('should retrieve and parse stored values', () => {
|
|
89
|
+
const [options, storeAuthUrl] = generateAndStoreAuthUrlValues(mockOptions);
|
|
90
|
+
storeAuthUrl();
|
|
91
|
+
|
|
92
|
+
const storedValues = getStoredAuthUrlValues(mockOptions.clientId, mockOptions.prefix);
|
|
93
|
+
expect(storedValues).toEqual(options);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('should remove values from storage after retrieval', () => {
|
|
97
|
+
const [, storeAuthUrl] = generateAndStoreAuthUrlValues(mockOptions);
|
|
98
|
+
storeAuthUrl();
|
|
99
|
+
|
|
100
|
+
const storageKey = getStorageKey(mockOptions.clientId, mockOptions.prefix);
|
|
101
|
+
|
|
102
|
+
// Verify value exists before retrieval
|
|
103
|
+
expect(sessionStorage.getItem(storageKey)).toBeDefined();
|
|
104
|
+
|
|
105
|
+
// Retrieve values
|
|
106
|
+
getStoredAuthUrlValues(mockOptions.clientId, mockOptions.prefix);
|
|
107
|
+
|
|
108
|
+
// Verify value was removed
|
|
109
|
+
expect(sessionStorage.getItem(storageKey)).toBeNull();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('should throw error when stored values cannot be parsed', () => {
|
|
113
|
+
const storageKey = getStorageKey(mockOptions.clientId, mockOptions.prefix);
|
|
114
|
+
sessionStorage.setItem(storageKey, 'invalid json');
|
|
115
|
+
|
|
116
|
+
expect(() => getStoredAuthUrlValues(mockOptions.clientId, mockOptions.prefix)).toThrow(
|
|
117
|
+
'Stored values for Auth URL could not be parsed',
|
|
118
|
+
);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
});
|
package/vite.config.ts
CHANGED
|
Binary file
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { LegacyConfigOptions } from '@forgerock/sdk-types';
|
|
2
|
-
/**
|
|
3
|
-
* Define the options for the authorization URL
|
|
4
|
-
* @param clientId The client ID of the application
|
|
5
|
-
* @param redirectUri The redirect URI of the application
|
|
6
|
-
* @param responseType The response type of the authorization request
|
|
7
|
-
* @param scope The scope of the authorization request
|
|
8
|
-
*/
|
|
9
|
-
export type ResponseType = 'code' | 'token';
|
|
10
|
-
export interface GetAuthorizationUrlOptions extends LegacyConfigOptions {
|
|
11
|
-
/**
|
|
12
|
-
* These three properties clientid, scope and redirectUri are required
|
|
13
|
-
* when using this type, which are not required when defining Config.
|
|
14
|
-
*/
|
|
15
|
-
clientId: string;
|
|
16
|
-
login?: 'redirect' | 'embedded';
|
|
17
|
-
scope: string;
|
|
18
|
-
redirectUri: string;
|
|
19
|
-
responseType: ResponseType;
|
|
20
|
-
state?: string;
|
|
21
|
-
verifier?: string;
|
|
22
|
-
query?: Record<string, string>;
|
|
23
|
-
prompt?: 'none' | 'login' | 'consent';
|
|
24
|
-
}
|
|
25
|
-
//# sourceMappingURL=authorize.types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authorize.types.d.ts","sourceRoot":"","sources":["../../../src/lib/authorize.types.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAEhE;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,OAAO,CAAC;AAC5C,MAAM,WAAW,0BAA2B,SAAQ,mBAAmB;IACrE;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,UAAU,GAAG,UAAU,CAAC;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,YAAY,CAAC;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;CACvC"}
|
package/dist/src/lib/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/index.ts"],"names":[],"mappings":"AAOA,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC"}
|
package/dist/src/lib/index.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2025 Ping Identity Corporation. All rights reserved.
|
|
3
|
-
*
|
|
4
|
-
* This software may be modified and distributed under the terms
|
|
5
|
-
* of the MIT license. See the LICENSE file for details.
|
|
6
|
-
*/
|
|
7
|
-
export * from './authorize.effects.js';
|
|
8
|
-
export * from './state-pkce.effects.js';
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2025 Ping Identity Corporation. All rights reserved.
|
|
3
|
-
*
|
|
4
|
-
* This software may be modified and distributed under the terms
|
|
5
|
-
* of the MIT license. See the LICENSE file for details.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import type { LegacyConfigOptions } from '@forgerock/sdk-types';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Define the options for the authorization URL
|
|
12
|
-
* @param clientId The client ID of the application
|
|
13
|
-
* @param redirectUri The redirect URI of the application
|
|
14
|
-
* @param responseType The response type of the authorization request
|
|
15
|
-
* @param scope The scope of the authorization request
|
|
16
|
-
*/
|
|
17
|
-
export type ResponseType = 'code' | 'token';
|
|
18
|
-
export interface GetAuthorizationUrlOptions extends LegacyConfigOptions {
|
|
19
|
-
/**
|
|
20
|
-
* These three properties clientid, scope and redirectUri are required
|
|
21
|
-
* when using this type, which are not required when defining Config.
|
|
22
|
-
*/
|
|
23
|
-
clientId: string;
|
|
24
|
-
login?: 'redirect' | 'embedded';
|
|
25
|
-
scope: string;
|
|
26
|
-
redirectUri: string;
|
|
27
|
-
responseType: ResponseType;
|
|
28
|
-
state?: string;
|
|
29
|
-
verifier?: string;
|
|
30
|
-
query?: Record<string, string>;
|
|
31
|
-
prompt?: 'none' | 'login' | 'consent';
|
|
32
|
-
}
|
package/src/lib/index.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2025 Ping Identity Corporation. All rights reserved.
|
|
3
|
-
*
|
|
4
|
-
* This software may be modified and distributed under the terms
|
|
5
|
-
* of the MIT license. See the LICENSE file for details.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export * from './authorize.effects.js';
|
|
9
|
-
export * from './state-pkce.effects.js';
|