@axa-fr/react-oidc 6.11.4-alpha2 → 6.12.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/OidcProvider.d.ts +1 -1
- package/dist/OidcProvider.d.ts.map +1 -1
- package/dist/OidcSecure.d.ts +1 -1
- package/dist/OidcSecure.d.ts.map +1 -1
- package/dist/OidcServiceWorker.js +16 -3
- package/dist/ReactOidc.d.ts +1 -1
- package/dist/ReactOidc.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/vanilla/initSession.d.ts +3 -3
- package/dist/vanilla/initSession.d.ts.map +1 -1
- package/dist/vanilla/initSession.js +20 -20
- package/dist/vanilla/initSession.js.map +1 -1
- package/dist/vanilla/initWorker.d.ts +4 -4
- package/dist/vanilla/initWorker.d.ts.map +1 -1
- package/dist/vanilla/initWorker.js +13 -13
- package/dist/vanilla/initWorker.js.map +1 -1
- package/dist/vanilla/oidc.d.ts +36 -7
- package/dist/vanilla/oidc.d.ts.map +1 -1
- package/dist/vanilla/oidc.js +357 -82
- package/dist/vanilla/oidc.js.map +1 -1
- package/dist/vanilla/requests.d.ts +0 -2
- package/dist/vanilla/requests.d.ts.map +1 -1
- package/dist/vanilla/requests.js +1 -20
- package/dist/vanilla/requests.js.map +1 -1
- package/dist/vanilla/route-utils.js +1 -1
- package/dist/vanilla/route-utils.js.map +1 -1
- package/dist/vanilla/vanillaOidc.d.ts +1 -2
- package/dist/vanilla/vanillaOidc.d.ts.map +1 -1
- package/dist/vanilla/vanillaOidc.js.map +1 -1
- package/package.json +1 -1
- package/src/oidc/OidcProvider.tsx +1 -1
- package/src/oidc/OidcSecure.tsx +1 -1
- package/src/oidc/ReactOidc.tsx +1 -1
- package/src/oidc/index.ts +1 -1
- package/src/oidc/vanilla/OidcServiceWorker.js +16 -3
- package/src/oidc/vanilla/index.ts +1 -1
- package/src/oidc/vanilla/initSession.ts +20 -20
- package/src/oidc/vanilla/initWorker.ts +14 -14
- package/src/oidc/vanilla/oidc.ts +380 -52
- package/src/oidc/vanilla/requests.ts +0 -24
- package/src/oidc/vanilla/route-utils.ts +1 -1
- package/src/oidc/vanilla/vanillaOidc.ts +1 -2
- package/dist/vanilla/checkSession.d.ts +0 -5
- package/dist/vanilla/checkSession.d.ts.map +0 -1
- package/dist/vanilla/checkSession.js +0 -68
- package/dist/vanilla/checkSession.js.map +0 -1
- package/dist/vanilla/events.d.ts +0 -29
- package/dist/vanilla/events.d.ts.map +0 -1
- package/dist/vanilla/events.js +0 -32
- package/dist/vanilla/events.js.map +0 -1
- package/dist/vanilla/login.d.ts +0 -4
- package/dist/vanilla/login.d.ts.map +0 -1
- package/dist/vanilla/login.js +0 -125
- package/dist/vanilla/login.js.map +0 -1
- package/dist/vanilla/silentLogin.d.ts +0 -8
- package/dist/vanilla/silentLogin.d.ts.map +0 -1
- package/dist/vanilla/silentLogin.js +0 -95
- package/dist/vanilla/silentLogin.js.map +0 -1
- package/dist/vanilla/types.d.ts +0 -33
- package/dist/vanilla/types.d.ts.map +0 -1
- package/dist/vanilla/types.js +0 -3
- package/dist/vanilla/types.js.map +0 -1
- package/dist/vanilla/user.d.ts +0 -2
- package/dist/vanilla/user.d.ts.map +0 -1
- package/dist/vanilla/user.js +0 -48
- package/dist/vanilla/user.js.map +0 -1
- package/src/oidc/vanilla/checkSession.ts +0 -55
- package/src/oidc/vanilla/events.ts +0 -29
- package/src/oidc/vanilla/login.ts +0 -118
- package/src/oidc/vanilla/silentLogin.ts +0 -102
- package/src/oidc/vanilla/types.ts +0 -35
- package/src/oidc/vanilla/user.ts +0 -39
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { AuthorizationRequest, DefaultCrypto, RedirectRequestHandler } from '@openid/appauth';
|
|
2
|
-
|
|
3
|
-
import { eventNames } from './events';
|
|
4
|
-
import { initSession } from './initSession';
|
|
5
|
-
import { initWorkerAsync } from './initWorker';
|
|
6
|
-
import { MemoryStorageBackend } from './memoryStorageBackend';
|
|
7
|
-
import { HashQueryStringUtils, NoHashQueryStringUtils } from './noHashQueryStringUtils';
|
|
8
|
-
import { OidcConfiguration, StringMap } from './types';
|
|
9
|
-
|
|
10
|
-
const randomString = function(length) {
|
|
11
|
-
let text = '';
|
|
12
|
-
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
13
|
-
for (let i = 0; i < length; i++) {
|
|
14
|
-
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
15
|
-
}
|
|
16
|
-
return text;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
20
|
-
export const defaultLoginAsync = (window, configurationName, configuration:OidcConfiguration, silentLoginAsync:Function, publishEvent :(string, any)=>void, initAsync:Function) => (callbackPath:string = undefined, extras:StringMap = null, isSilentSignin = false, scope:string = undefined) => {
|
|
21
|
-
const originExtras = extras;
|
|
22
|
-
extras = { ...extras };
|
|
23
|
-
const loginLocalAsync = async () => {
|
|
24
|
-
const location = window.location;
|
|
25
|
-
const url = callbackPath || location.pathname + (location.search || '') + (location.hash || '');
|
|
26
|
-
let state;
|
|
27
|
-
if (extras && 'state' in extras) {
|
|
28
|
-
state = extras.state;
|
|
29
|
-
delete extras.state;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
publishEvent(eventNames.loginAsync_begin, {});
|
|
33
|
-
if (extras) {
|
|
34
|
-
for (const key of Object.keys(extras)) {
|
|
35
|
-
if (key.endsWith(':token_request')) {
|
|
36
|
-
delete extras[key];
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
try {
|
|
41
|
-
const redirectUri = isSilentSignin ? configuration.silent_redirect_uri : configuration.redirect_uri;
|
|
42
|
-
if (!scope) {
|
|
43
|
-
scope = configuration.scope;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const extraFinal = extras ?? configuration.extras ?? {};
|
|
47
|
-
if (!extraFinal.nonce) {
|
|
48
|
-
extraFinal.nonce = randomString(12);
|
|
49
|
-
}
|
|
50
|
-
const nonce = { nonce: extraFinal.nonce };
|
|
51
|
-
const serviceWorker = await initWorkerAsync(configuration.service_worker_relative_url, configurationName);
|
|
52
|
-
const oidcServerConfiguration = await initAsync(configuration.authority, configuration.authority_configuration);
|
|
53
|
-
let storage;
|
|
54
|
-
if (serviceWorker) {
|
|
55
|
-
serviceWorker.setLoginParams(configurationName, { callbackPath: url, extras: originExtras, state });
|
|
56
|
-
serviceWorker.startKeepAliveServiceWorker();
|
|
57
|
-
await serviceWorker.initAsync(oidcServerConfiguration, 'loginAsync', configuration);
|
|
58
|
-
await serviceWorker.setNonceAsync(nonce);
|
|
59
|
-
storage = new MemoryStorageBackend(serviceWorker.saveItemsAsync, {});
|
|
60
|
-
await storage.setItem('dummy', {});
|
|
61
|
-
} else {
|
|
62
|
-
let session = initSession(configurationName, configuration.storage ?? sessionStorage);
|
|
63
|
-
session.setLoginParams(configurationName, { callbackPath: url, extras: originExtras, state });
|
|
64
|
-
session = initSession(configurationName);
|
|
65
|
-
await session.setNonceAsync(nonce);
|
|
66
|
-
storage = new MemoryStorageBackend(session.saveItemsAsync, {});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// @ts-ignore
|
|
70
|
-
const queryStringUtil = redirectUri.includes('#') ? new HashQueryStringUtils() : new NoHashQueryStringUtils();
|
|
71
|
-
const authorizationHandler = new RedirectRequestHandler(storage, queryStringUtil, window.location, new DefaultCrypto());
|
|
72
|
-
const authRequest = new AuthorizationRequest({
|
|
73
|
-
client_id: configuration.client_id,
|
|
74
|
-
redirect_uri: redirectUri,
|
|
75
|
-
scope,
|
|
76
|
-
response_type: AuthorizationRequest.RESPONSE_TYPE_CODE,
|
|
77
|
-
state,
|
|
78
|
-
extras: extraFinal,
|
|
79
|
-
});
|
|
80
|
-
authorizationHandler.performAuthorizationRequest(oidcServerConfiguration, authRequest);
|
|
81
|
-
} catch (exception) {
|
|
82
|
-
publishEvent(eventNames.loginAsync_error, exception);
|
|
83
|
-
throw exception;
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
return loginLocalAsync();
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
90
|
-
export const defaultSilentLoginAsync2 = (window, configurationName, configuration:OidcConfiguration, publishEvent :(string, any)=>void, oidc:any) => (extras:StringMap = null, scope:string = undefined) => {
|
|
91
|
-
extras = { ...extras };
|
|
92
|
-
const loginLocalAsync = async () => {
|
|
93
|
-
let state;
|
|
94
|
-
if (extras && 'state' in extras) {
|
|
95
|
-
state = extras.state;
|
|
96
|
-
delete extras.state;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
try {
|
|
100
|
-
const extraFinal = extras ?? configuration.extras ?? {};
|
|
101
|
-
const silentResult = await oidc.silentLoginAsync({
|
|
102
|
-
...extraFinal,
|
|
103
|
-
prompt: 'none',
|
|
104
|
-
}, state, scope);
|
|
105
|
-
|
|
106
|
-
if (silentResult) {
|
|
107
|
-
oidc.tokens = silentResult.tokens;
|
|
108
|
-
publishEvent(eventNames.token_aquired, {});
|
|
109
|
-
// @ts-ignore
|
|
110
|
-
this.timeoutId = autoRenewTokens(this, this.tokens.refreshToken, this.tokens.expiresAt, extras);
|
|
111
|
-
return {};
|
|
112
|
-
}
|
|
113
|
-
} catch (e) {
|
|
114
|
-
return e;
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
return loginLocalAsync();
|
|
118
|
-
};
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { eventNames } from './events';
|
|
2
|
-
import { Tokens } from './parseTokens';
|
|
3
|
-
import { OidcConfiguration, StringMap } from './types';
|
|
4
|
-
|
|
5
|
-
type SilentLoginResponse = {
|
|
6
|
-
tokens:Tokens;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
10
|
-
const silentLoginAsync = (configurationName:string, configuration:OidcConfiguration, publishEvent:Function) => (extras:StringMap = null, state:string = null, scope:string = null):Promise<SilentLoginResponse> => {
|
|
11
|
-
if (!configuration.silent_redirect_uri || !configuration.silent_login_uri) {
|
|
12
|
-
return Promise.resolve(null);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
publishEvent(eventNames.silentLoginAsync_begin, {});
|
|
17
|
-
let queries = '';
|
|
18
|
-
|
|
19
|
-
if (state) {
|
|
20
|
-
if (extras == null) {
|
|
21
|
-
extras = {};
|
|
22
|
-
}
|
|
23
|
-
extras.state = state;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (scope) {
|
|
27
|
-
if (extras == null) {
|
|
28
|
-
extras = {};
|
|
29
|
-
}
|
|
30
|
-
extras.scope = scope;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (extras != null) {
|
|
34
|
-
for (const [key, value] of Object.entries(extras)) {
|
|
35
|
-
if (queries === '') {
|
|
36
|
-
queries = `?${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
37
|
-
} else {
|
|
38
|
-
queries += `&${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
const link = configuration.silent_login_uri + queries;
|
|
43
|
-
const idx = link.indexOf('/', link.indexOf('//') + 2);
|
|
44
|
-
const iFrameOrigin = link.substr(0, idx);
|
|
45
|
-
const iframe = document.createElement('iframe');
|
|
46
|
-
iframe.width = '0px';
|
|
47
|
-
iframe.height = '0px';
|
|
48
|
-
|
|
49
|
-
iframe.id = `${configurationName}_oidc_iframe`;
|
|
50
|
-
iframe.setAttribute('src', link);
|
|
51
|
-
document.body.appendChild(iframe);
|
|
52
|
-
return new Promise((resolve, reject) => {
|
|
53
|
-
try {
|
|
54
|
-
let isResolved = false;
|
|
55
|
-
window.onmessage = (e: MessageEvent<any>) => {
|
|
56
|
-
if (e.origin === iFrameOrigin &&
|
|
57
|
-
e.source === iframe.contentWindow
|
|
58
|
-
) {
|
|
59
|
-
const key = `${configurationName}_oidc_tokens:`;
|
|
60
|
-
const key_error = `${configurationName}_oidc_error:`;
|
|
61
|
-
const data = e.data;
|
|
62
|
-
if (data && typeof (data) === 'string') {
|
|
63
|
-
if (!isResolved) {
|
|
64
|
-
if (data.startsWith(key)) {
|
|
65
|
-
const result = JSON.parse(e.data.replace(key, ''));
|
|
66
|
-
publishEvent(eventNames.silentLoginAsync_end, {});
|
|
67
|
-
iframe.remove();
|
|
68
|
-
isResolved = true;
|
|
69
|
-
resolve(result);
|
|
70
|
-
} else if (data.startsWith(key_error)) {
|
|
71
|
-
const result = JSON.parse(e.data.replace(key_error, ''));
|
|
72
|
-
publishEvent(eventNames.silentLoginAsync_error, result);
|
|
73
|
-
iframe.remove();
|
|
74
|
-
isResolved = true;
|
|
75
|
-
reject(new Error('oidc_' + result.error));
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
const silentSigninTimeout = configuration.silent_login_timeout;
|
|
82
|
-
setTimeout(() => {
|
|
83
|
-
if (!isResolved) {
|
|
84
|
-
publishEvent(eventNames.silentLoginAsync_error, { reason: 'timeout' });
|
|
85
|
-
iframe.remove();
|
|
86
|
-
isResolved = true;
|
|
87
|
-
reject(new Error('timeout'));
|
|
88
|
-
}
|
|
89
|
-
}, silentSigninTimeout);
|
|
90
|
-
} catch (e) {
|
|
91
|
-
iframe.remove();
|
|
92
|
-
publishEvent(eventNames.silentLoginAsync_error, e);
|
|
93
|
-
reject(e);
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
} catch (e) {
|
|
97
|
-
publishEvent(eventNames.silentLoginAsync_error, e);
|
|
98
|
-
throw e;
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
export default silentLoginAsync;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export type OidcConfiguration = {
|
|
3
|
-
client_id: string;
|
|
4
|
-
redirect_uri: string;
|
|
5
|
-
silent_redirect_uri?:string;
|
|
6
|
-
silent_login_uri?:string;
|
|
7
|
-
silent_login_timeout?:number;
|
|
8
|
-
scope: string;
|
|
9
|
-
authority: string;
|
|
10
|
-
authority_time_cache_wellknowurl_in_second?: number;
|
|
11
|
-
authority_configuration?: AuthorityConfiguration;
|
|
12
|
-
refresh_time_before_tokens_expiration_in_second?: number;
|
|
13
|
-
token_request_timeout?: number;
|
|
14
|
-
service_worker_relative_url?:string;
|
|
15
|
-
service_worker_only?:boolean;
|
|
16
|
-
extras?:StringMap;
|
|
17
|
-
token_request_extras?:StringMap;
|
|
18
|
-
storage?: Storage;
|
|
19
|
-
monitor_session?: boolean;
|
|
20
|
-
token_renew_mode?: string;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export interface StringMap {
|
|
24
|
-
[key: string]: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface AuthorityConfiguration {
|
|
28
|
-
authorization_endpoint: string;
|
|
29
|
-
token_endpoint: string;
|
|
30
|
-
revocation_endpoint: string;
|
|
31
|
-
end_session_endpoint?: string;
|
|
32
|
-
userinfo_endpoint?: string;
|
|
33
|
-
check_session_iframe?:string;
|
|
34
|
-
issuer:string;
|
|
35
|
-
}
|
package/src/oidc/vanilla/user.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { sleepAsync } from './initWorker';
|
|
2
|
-
import { isTokensValid } from './parseTokens';
|
|
3
|
-
|
|
4
|
-
export const userInfoAsync = async (oidc) => {
|
|
5
|
-
if (oidc.userInfo != null) {
|
|
6
|
-
return oidc.userInfo;
|
|
7
|
-
}
|
|
8
|
-
if (!oidc.tokens) {
|
|
9
|
-
return null;
|
|
10
|
-
}
|
|
11
|
-
const accessToken = oidc.tokens.accessToken;
|
|
12
|
-
if (!accessToken) {
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// We wait the synchronisation before making a request
|
|
17
|
-
while (oidc.tokens && !isTokensValid(oidc.tokens)) {
|
|
18
|
-
await sleepAsync(200);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const oidcServerConfiguration = await oidc.initAsync(oidc.configuration.authority, oidc.configuration.authority_configuration);
|
|
22
|
-
const url = oidcServerConfiguration.userInfoEndpoint;
|
|
23
|
-
const fetchUserInfo = async (accessToken) => {
|
|
24
|
-
const res = await fetch(url, {
|
|
25
|
-
headers: {
|
|
26
|
-
authorization: `Bearer ${accessToken}`,
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
if (res.status !== 200) {
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return res.json();
|
|
35
|
-
};
|
|
36
|
-
const userInfo = await fetchUserInfo(accessToken);
|
|
37
|
-
oidc.userInfo = userInfo;
|
|
38
|
-
return userInfo;
|
|
39
|
-
};
|