@axa-fr/react-oidc 6.6.7 → 6.6.8
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/FetchToken.d.ts.map +1 -1
- package/dist/FetchToken.js +4 -9
- package/dist/FetchToken.js.map +1 -1
- package/dist/OidcProvider.d.ts.map +1 -1
- package/dist/OidcProvider.js +19 -19
- package/dist/OidcProvider.js.map +1 -1
- package/dist/OidcSecure.d.ts +1 -2
- package/dist/OidcSecure.d.ts.map +1 -1
- package/dist/OidcSecure.js +4 -7
- package/dist/OidcSecure.js.map +1 -1
- package/dist/ReactOidc.d.ts +3 -3
- package/dist/ReactOidc.d.ts.map +1 -1
- package/dist/ReactOidc.js +19 -17
- package/dist/ReactOidc.js.map +1 -1
- package/dist/User.d.ts.map +1 -1
- package/dist/User.js +2 -5
- package/dist/User.js.map +1 -1
- package/dist/core/default-component/Callback.component.js +3 -3
- package/dist/core/default-component/Callback.component.js.map +1 -1
- package/dist/core/default-component/SilentCallback.component.js +3 -6
- package/dist/core/default-component/SilentCallback.component.js.map +1 -1
- package/dist/core/default-component/SilentLogin.component.js +2 -5
- package/dist/core/default-component/SilentLogin.component.js.map +1 -1
- package/dist/vanilla/index.d.ts +1 -1
- package/dist/vanilla/index.d.ts.map +1 -1
- package/dist/vanilla/index.js +3 -3
- package/dist/vanilla/index.js.map +1 -1
- package/dist/vanilla/initWorker.d.ts +1 -1
- package/dist/vanilla/initWorker.d.ts.map +1 -1
- package/dist/vanilla/initWorker.js +4 -0
- package/dist/vanilla/initWorker.js.map +1 -1
- package/dist/vanilla/noHashQueryStringUtils.d.ts.map +1 -1
- package/dist/vanilla/noHashQueryStringUtils.js +1 -2
- package/dist/vanilla/noHashQueryStringUtils.js.map +1 -1
- package/dist/vanilla/oidc.d.ts +16 -12
- package/dist/vanilla/oidc.d.ts.map +1 -1
- package/dist/vanilla/oidc.js +37 -38
- package/dist/vanilla/oidc.js.map +1 -1
- package/dist/vanilla/parseTokens.d.ts +11 -2
- package/dist/vanilla/parseTokens.d.ts.map +1 -1
- package/dist/vanilla/parseTokens.js +2 -2
- package/dist/vanilla/parseTokens.js.map +1 -1
- package/dist/vanilla/timer.js +3 -3
- package/dist/vanilla/timer.js.map +1 -1
- package/dist/vanilla/vanillaOidc.d.ts +56 -0
- package/dist/vanilla/vanillaOidc.d.ts.map +1 -0
- package/dist/vanilla/vanillaOidc.js +84 -0
- package/dist/vanilla/vanillaOidc.js.map +1 -0
- package/package.json +1 -1
- package/src/Home.tsx +0 -1
- package/src/configurations.ts +3 -3
- package/src/oidc/FetchToken.tsx +6 -11
- package/src/oidc/OidcProvider.tsx +21 -20
- package/src/oidc/OidcSecure.tsx +5 -6
- package/src/oidc/ReactOidc.tsx +20 -14
- package/src/oidc/User.ts +2 -4
- package/src/oidc/core/default-component/Callback.component.tsx +3 -3
- package/src/oidc/core/default-component/SilentCallback.component.tsx +3 -3
- package/src/oidc/core/default-component/SilentLogin.component.tsx +2 -2
- package/src/oidc/vanilla/index.ts +1 -1
- package/src/oidc/vanilla/initWorker.ts +5 -0
- package/src/oidc/vanilla/noHashQueryStringUtils.ts +1 -2
- package/src/oidc/vanilla/oidc.ts +57 -64
- package/src/oidc/vanilla/parseTokens.ts +13 -4
- package/src/oidc/vanilla/timer.ts +3 -3
- package/src/oidc/vanilla/vanillaOidc.ts +74 -0
package/src/oidc/vanilla/oidc.ts
CHANGED
|
@@ -19,7 +19,7 @@ import timer from './timer';
|
|
|
19
19
|
import {CheckSessionIFrame} from "./checkSessionIFrame"
|
|
20
20
|
import {getParseQueryStringFromLocation} from "./route-utils";
|
|
21
21
|
import {AuthorizationServiceConfigurationJson} from "@openid/appauth/src/authorization_service_configuration";
|
|
22
|
-
import {computeTimeLeft, isTokensOidcValid, isTokensValid, parseOriginalTokens, setTokens} from "./parseTokens";
|
|
22
|
+
import {computeTimeLeft, isTokensOidcValid, isTokensValid, parseOriginalTokens, setTokens, Tokens} from "./parseTokens";
|
|
23
23
|
|
|
24
24
|
const performTokenRequestAsync= async (url, details, extras, oldTokens) => {
|
|
25
25
|
|
|
@@ -77,6 +77,15 @@ const internalFetch = async (url, headers, numberRetry=0) => {
|
|
|
77
77
|
return response;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
const randomString = function(length) {
|
|
81
|
+
let text = "";
|
|
82
|
+
const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
83
|
+
for(let i = 0; i < length; i++) {
|
|
84
|
+
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
85
|
+
}
|
|
86
|
+
return text;
|
|
87
|
+
}
|
|
88
|
+
|
|
80
89
|
export interface OidcAuthorizationServiceConfigurationJson extends AuthorizationServiceConfigurationJson{
|
|
81
90
|
check_session_iframe?: string;
|
|
82
91
|
issuer:string;
|
|
@@ -103,10 +112,6 @@ export interface StringMap {
|
|
|
103
112
|
[key: string]: string;
|
|
104
113
|
}
|
|
105
114
|
|
|
106
|
-
export interface loginCallbackResult {
|
|
107
|
-
state: string,
|
|
108
|
-
callbackPath: string,
|
|
109
|
-
}
|
|
110
115
|
|
|
111
116
|
export interface AuthorityConfiguration {
|
|
112
117
|
authorization_endpoint: string;
|
|
@@ -146,16 +151,25 @@ const oidcFactory = (configuration: OidcConfiguration, name="default") => {
|
|
|
146
151
|
oidcDatabase[name] = new Oidc(configuration, name)
|
|
147
152
|
return oidcDatabase[name];
|
|
148
153
|
}
|
|
154
|
+
export type LoginCallback = {
|
|
155
|
+
callbackPath:string
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export type InternalLoginCallback = {
|
|
159
|
+
callbackPath:string
|
|
160
|
+
parsedTokens:Tokens,
|
|
161
|
+
}
|
|
149
162
|
|
|
150
|
-
const loginCallbackWithAutoTokensRenewAsync = async (oidc) => {
|
|
151
|
-
const { parsedTokens,
|
|
163
|
+
const loginCallbackWithAutoTokensRenewAsync = async (oidc) : Promise<LoginCallback> => {
|
|
164
|
+
const { parsedTokens, callbackPath } = await oidc.loginCallbackAsync();
|
|
152
165
|
oidc.timeoutId = autoRenewTokens(oidc, parsedTokens.refreshToken, parsedTokens.expiresAt)
|
|
153
|
-
return {
|
|
166
|
+
return { callbackPath };
|
|
154
167
|
}
|
|
155
168
|
|
|
156
169
|
async function renewTokensAndStartTimerAsync(oidc, refreshToken, forceRefresh =false, extras:StringMap=null) {
|
|
157
|
-
const
|
|
158
|
-
|
|
170
|
+
const updateTokens = (tokens) => oidc.tokens = tokens;
|
|
171
|
+
const {tokens, status} = await oidc.synchroniseTokensAsync(refreshToken, 0, forceRefresh, extras, updateTokens);
|
|
172
|
+
|
|
159
173
|
const serviceWorker = await initWorkerAsync(oidc.configuration.service_worker_relative_url, oidc.configurationName);
|
|
160
174
|
if (!serviceWorker) {
|
|
161
175
|
const session = initSession(oidc.configurationName, oidc.configuration.redirect_uri, oidc.configuration.storage);
|
|
@@ -306,24 +320,10 @@ const fetchFromIssuer = async (openIdIssuerUrl: string, timeCacheSecond = oneHou
|
|
|
306
320
|
return new OidcAuthorizationServiceConfiguration(result);
|
|
307
321
|
}
|
|
308
322
|
|
|
309
|
-
const buildQueries = (extras:StringMap) => {
|
|
310
|
-
let queries = '';
|
|
311
|
-
if(extras != null){
|
|
312
|
-
for (let [key, value] of Object.entries(extras)) {
|
|
313
|
-
if (queries === ""){
|
|
314
|
-
queries = `?${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
315
|
-
} else {
|
|
316
|
-
queries+= `&${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
return queries;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
323
|
export class Oidc {
|
|
324
324
|
public configuration: OidcConfiguration;
|
|
325
325
|
public userInfo: null;
|
|
326
|
-
public tokens
|
|
326
|
+
public tokens?: Tokens;
|
|
327
327
|
public events: Array<any>;
|
|
328
328
|
private timeoutId: NodeJS.Timeout;
|
|
329
329
|
private configurationName: string;
|
|
@@ -360,13 +360,13 @@ export class Oidc {
|
|
|
360
360
|
this.initAsync(this.configuration.authority, this.configuration.authority_configuration);
|
|
361
361
|
}
|
|
362
362
|
|
|
363
|
-
subscriveEvents(func){
|
|
363
|
+
subscriveEvents(func):string{
|
|
364
364
|
const id = getRandomInt(9999999999999).toString();
|
|
365
365
|
this.events.push({id, func});
|
|
366
366
|
return id;
|
|
367
367
|
}
|
|
368
368
|
|
|
369
|
-
removeEventSubscription(id){
|
|
369
|
+
removeEventSubscription(id) :void{
|
|
370
370
|
const newEvents = this.events.filter(e => e.id !== id);
|
|
371
371
|
this.events = newEvents;
|
|
372
372
|
}
|
|
@@ -402,7 +402,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
402
402
|
}
|
|
403
403
|
}
|
|
404
404
|
|
|
405
|
-
async
|
|
405
|
+
async silentLoginCallbackAsync() {
|
|
406
406
|
try {
|
|
407
407
|
await this.loginCallbackAsync(true);
|
|
408
408
|
this._silentLoginCallbackFromIFrame();
|
|
@@ -536,11 +536,10 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
536
536
|
}
|
|
537
537
|
|
|
538
538
|
tryKeepExistingSessionPromise = null;
|
|
539
|
-
async tryKeepExistingSessionAsync() {
|
|
539
|
+
async tryKeepExistingSessionAsync() :Promise<boolean> {
|
|
540
540
|
if(this.tryKeepExistingSessionPromise !== null){
|
|
541
541
|
return this.tryKeepExistingSessionPromise;
|
|
542
542
|
}
|
|
543
|
-
|
|
544
543
|
const funcAsync =async () => {
|
|
545
544
|
let serviceWorker
|
|
546
545
|
if (this.tokens != null) {
|
|
@@ -617,25 +616,20 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
617
616
|
});
|
|
618
617
|
}
|
|
619
618
|
|
|
620
|
-
loginPromise: Promise<
|
|
619
|
+
loginPromise: Promise<void>=null;
|
|
621
620
|
async loginAsync(callbackPath:string=undefined, extras:StringMap=null, isSilentSignin:boolean=false, scope:string=undefined, silentLoginOnly = false) {
|
|
622
621
|
if(this.loginPromise !== null){
|
|
623
622
|
return this.loginPromise;
|
|
624
623
|
}
|
|
625
|
-
|
|
626
624
|
const loginLocalAsync=async () => {
|
|
627
|
-
|
|
628
625
|
const location = window.location;
|
|
629
626
|
const url = callbackPath || location.pathname + (location.search || '') + (location.hash || '');
|
|
630
|
-
|
|
631
627
|
const configuration = this.configuration;
|
|
632
628
|
let state = undefined;
|
|
633
629
|
if(extras && "state" in extras){
|
|
634
630
|
state = extras["state"];
|
|
635
631
|
delete extras["state"];
|
|
636
632
|
}
|
|
637
|
-
|
|
638
|
-
|
|
639
633
|
if(silentLoginOnly){
|
|
640
634
|
try {
|
|
641
635
|
const extraFinal = extras ?? configuration.extras ?? {};
|
|
@@ -662,15 +656,6 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
662
656
|
scope = configuration.scope;
|
|
663
657
|
}
|
|
664
658
|
|
|
665
|
-
const randomString = function(length) {
|
|
666
|
-
let text = "";
|
|
667
|
-
const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
668
|
-
for(let i = 0; i < length; i++) {
|
|
669
|
-
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
670
|
-
}
|
|
671
|
-
return text;
|
|
672
|
-
}
|
|
673
|
-
|
|
674
659
|
setLoginParams(this.configurationName, redirectUri, {callbackPath: url, extras, state});
|
|
675
660
|
const extraFinal = extras ?? configuration.extras ?? {};
|
|
676
661
|
if(!extraFinal.nonce) {
|
|
@@ -693,7 +678,6 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
693
678
|
storage = new MemoryStorageBackend(session.saveItemsAsync, {});
|
|
694
679
|
}
|
|
695
680
|
|
|
696
|
-
|
|
697
681
|
// @ts-ignore
|
|
698
682
|
const queryStringUtil = redirectUri.includes("#") ? new HashQueryStringUtils() : new NoHashQueryStringUtils();
|
|
699
683
|
const authorizationHandler = new RedirectRequestHandler(storage, queryStringUtil, window.location, new DefaultCrypto());
|
|
@@ -781,24 +765,22 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
781
765
|
return this.loginCallbackPromise;
|
|
782
766
|
}
|
|
783
767
|
|
|
784
|
-
const loginCallbackLocalAsync= async(
|
|
768
|
+
const loginCallbackLocalAsync= async():Promise<InternalLoginCallback> =>{
|
|
785
769
|
const response = await this._loginCallbackAsync(isSilenSignin);
|
|
786
770
|
// @ts-ignore
|
|
787
|
-
const
|
|
788
|
-
|
|
789
|
-
this.tokens =
|
|
771
|
+
const parsedTokens = response.tokens;
|
|
772
|
+
// @ts-ignore
|
|
773
|
+
this.tokens = response.tokens;
|
|
790
774
|
const oidc = this;
|
|
791
775
|
const serviceWorker = await initWorkerAsync(oidc.configuration.service_worker_relative_url, oidc.configurationName);
|
|
792
776
|
if (!serviceWorker) {
|
|
793
777
|
const session = initSession(this.configurationName, oidc.configuration.redirect_uri, oidc.configuration.storage);
|
|
794
778
|
await session.setTokens(parsedTokens);
|
|
795
779
|
}
|
|
796
|
-
|
|
797
780
|
this.publishEvent(Oidc.eventNames.token_aquired, parsedTokens);
|
|
798
781
|
// @ts-ignore
|
|
799
782
|
return { parsedTokens, state:response.state, callbackPath : response.callbackPath};
|
|
800
783
|
}
|
|
801
|
-
|
|
802
784
|
this.loginCallbackPromise = loginCallbackLocalAsync();
|
|
803
785
|
return this.loginCallbackPromise.then(result =>{
|
|
804
786
|
this.loginCallbackPromise = null;
|
|
@@ -891,16 +873,19 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
891
873
|
try {
|
|
892
874
|
const tokenHandler = new BaseTokenRequestHandler(new FetchRequestor());
|
|
893
875
|
tokenHandler.performTokenRequest(oidcServerConfiguration, tokenRequest).then(async (tokenResponse) => {
|
|
876
|
+
|
|
894
877
|
if (timeoutId) {
|
|
895
878
|
clearTimeout(timeoutId);
|
|
896
879
|
this.timeoutId = null;
|
|
897
880
|
const loginParams = getLoginParams(this.configurationName, redirectUri);
|
|
898
|
-
|
|
881
|
+
let formattedTokens = null;
|
|
899
882
|
if (serviceWorker) {
|
|
900
883
|
const {tokens} = await serviceWorker.initAsync(oidcServerConfiguration, "syncTokensAsync");
|
|
901
|
-
|
|
884
|
+
formattedTokens = tokens;
|
|
885
|
+
} else{
|
|
886
|
+
formattedTokens = setTokens(tokenResponse);
|
|
902
887
|
}
|
|
903
|
-
if(!isTokensOidcValid(
|
|
888
|
+
if(!isTokensOidcValid(formattedTokens, nonceData.nonce, oidcServerConfiguration)){
|
|
904
889
|
const exception = new Error("Tokens are not OpenID valid");
|
|
905
890
|
if(timeoutId) {
|
|
906
891
|
clearTimeout(timeoutId);
|
|
@@ -915,7 +900,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
915
900
|
this.startCheckSessionAsync(oidcServerConfiguration.check_session_iframe, clientId, sessionState, isSilentSignin).then(() => {
|
|
916
901
|
this.publishEvent(eventNames.loginCallbackAsync_end, {});
|
|
917
902
|
resolve({
|
|
918
|
-
tokens:
|
|
903
|
+
tokens: formattedTokens,
|
|
919
904
|
state: request.state,
|
|
920
905
|
callbackPath: loginParams.callbackPath,
|
|
921
906
|
});
|
|
@@ -941,12 +926,11 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
941
926
|
}
|
|
942
927
|
}
|
|
943
928
|
|
|
944
|
-
async synchroniseTokensAsync(refreshToken, index=0, forceRefresh =false, extras:StringMap=null) {
|
|
945
|
-
|
|
929
|
+
async synchroniseTokensAsync(refreshToken, index=0, forceRefresh =false, extras:StringMap=null, updateTokens) {
|
|
946
930
|
if (document.hidden) {
|
|
947
931
|
await sleepAsync(1000);
|
|
948
932
|
this.publishEvent(eventNames.refreshTokensAsync, {message: "wait because document is hidden"});
|
|
949
|
-
return await this.synchroniseTokensAsync(refreshToken, index, forceRefresh);
|
|
933
|
+
return await this.synchroniseTokensAsync(refreshToken, index, forceRefresh, extras, updateTokens);
|
|
950
934
|
}
|
|
951
935
|
let numberTryOnline = 6;
|
|
952
936
|
while (!navigator.onLine && numberTryOnline > 0) {
|
|
@@ -968,6 +952,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
968
952
|
prompt: "none"
|
|
969
953
|
}, loginParams.state);
|
|
970
954
|
if (silent_token_response) {
|
|
955
|
+
updateTokens(silent_token_response.tokens);
|
|
971
956
|
this.publishEvent(Oidc.eventNames.token_renewed, {});
|
|
972
957
|
return {tokens:silent_token_response.tokens, status:"LOGGED"};
|
|
973
958
|
}
|
|
@@ -975,12 +960,14 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
975
960
|
console.error(exceptionSilent);
|
|
976
961
|
this.publishEvent(eventNames.refreshTokensAsync_silent_error, {message: "exceptionSilent" ,exception: exceptionSilent.message});
|
|
977
962
|
if(exceptionSilent && exceptionSilent.message && exceptionSilent.message.startsWith("oidc")){
|
|
963
|
+
updateTokens(null);
|
|
978
964
|
this.publishEvent(eventNames.refreshTokensAsync_error, {message: `refresh token silent` });
|
|
979
965
|
return {tokens:null, status:"SESSION_LOST"};
|
|
980
966
|
}
|
|
981
967
|
await sleepAsync(1000);
|
|
982
968
|
throw exceptionSilent;
|
|
983
969
|
}
|
|
970
|
+
updateTokens(null);
|
|
984
971
|
this.publishEvent(eventNames.refreshTokensAsync_error, {message: `refresh token silent return` });
|
|
985
972
|
return {tokens:null, status:"SESSION_LOST"};
|
|
986
973
|
}
|
|
@@ -990,16 +977,21 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
990
977
|
const { status, tokens, nonce } = await this.syncTokensInfoAsync(configuration, this.configurationName, this.tokens, forceRefresh);
|
|
991
978
|
switch (status) {
|
|
992
979
|
case "SESSION_LOST":
|
|
980
|
+
updateTokens(null);
|
|
993
981
|
this.publishEvent(eventNames.refreshTokensAsync_error, {message: `refresh token session lost` });
|
|
994
982
|
return {tokens:null, status:"SESSION_LOST"};
|
|
995
983
|
case "NOT_CONNECTED":
|
|
984
|
+
updateTokens(null);
|
|
996
985
|
return {tokens:null, status:null};
|
|
997
986
|
case "TOKENS_VALID":
|
|
987
|
+
updateTokens(tokens);
|
|
998
988
|
return {tokens, status:"LOGGED_IN"};
|
|
999
989
|
case "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID":
|
|
990
|
+
updateTokens(tokens);
|
|
1000
991
|
this.publishEvent(Oidc.eventNames.token_renewed, {});
|
|
1001
992
|
return {tokens, status:"LOGGED_IN"};
|
|
1002
993
|
case "LOGOUT_FROM_ANOTHER_TAB":
|
|
994
|
+
updateTokens(null);
|
|
1003
995
|
this.publishEvent(eventNames.logout_from_another_tab, {"status": "session syncTokensAsync"});
|
|
1004
996
|
return {tokens:null, status:"LOGGED_OUT"};
|
|
1005
997
|
case "REQUIRE_SYNC_TOKENS":
|
|
@@ -1008,7 +1000,6 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
1008
1000
|
default:
|
|
1009
1001
|
if(!refreshToken)
|
|
1010
1002
|
{
|
|
1011
|
-
this.publishEvent(eventNames.refreshTokensAsync_begin, {refreshToken:refreshToken, tryNumber: index});
|
|
1012
1003
|
return await localsilentLoginAsync();
|
|
1013
1004
|
}
|
|
1014
1005
|
this.publishEvent(eventNames.refreshTokensAsync_begin, {refreshToken:refreshToken, status, tryNumber: index});
|
|
@@ -1028,9 +1019,11 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
1028
1019
|
const tokenResponse = await performTokenRequestAsync(oidcServerConfiguration.tokenEndpoint, details, finalExtras, tokens);
|
|
1029
1020
|
if (tokenResponse.success) {
|
|
1030
1021
|
if(!isTokensOidcValid(tokenResponse.data, nonce.nonce, oidcServerConfiguration)){
|
|
1022
|
+
updateTokens(null);
|
|
1031
1023
|
this.publishEvent(eventNames.refreshTokensAsync_error, {message: `refresh token return not valid tokens` });
|
|
1032
1024
|
return {tokens:null, status:"SESSION_LOST"};
|
|
1033
1025
|
}
|
|
1026
|
+
updateTokens(tokenResponse.data);
|
|
1034
1027
|
this.publishEvent(eventNames.refreshTokensAsync_end, {success: tokenResponse.success});
|
|
1035
1028
|
this.publishEvent(Oidc.eventNames.token_renewed, {});
|
|
1036
1029
|
return {tokens: tokenResponse.data, status:"LOGGED_IN"};
|
|
@@ -1039,13 +1032,13 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
1039
1032
|
message: "bad request",
|
|
1040
1033
|
tokenResponse: tokenResponse
|
|
1041
1034
|
});
|
|
1042
|
-
return await this.synchroniseTokensAsync(null, index+1, forceRefresh);
|
|
1035
|
+
return await this.synchroniseTokensAsync(null, index+1, forceRefresh, extras, updateTokens);
|
|
1043
1036
|
}
|
|
1044
1037
|
}
|
|
1045
1038
|
} catch (exception) {
|
|
1046
1039
|
console.error(exception);
|
|
1047
1040
|
this.publishEvent(eventNames.refreshTokensAsync_silent_error, {message: "exception" ,exception: exception.message});
|
|
1048
|
-
return this.synchroniseTokensAsync(refreshToken, index+1, forceRefresh);
|
|
1041
|
+
return this.synchroniseTokensAsync(refreshToken, index+1, forceRefresh, extras, updateTokens);
|
|
1049
1042
|
}
|
|
1050
1043
|
}
|
|
1051
1044
|
|
|
@@ -1103,8 +1096,8 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
1103
1096
|
return { tokens:currentTokens, status, nonce};
|
|
1104
1097
|
}
|
|
1105
1098
|
|
|
1106
|
-
loginCallbackWithAutoTokensRenewPromise:Promise<
|
|
1107
|
-
loginCallbackWithAutoTokensRenewAsync():Promise<
|
|
1099
|
+
loginCallbackWithAutoTokensRenewPromise:Promise<LoginCallback> = null;
|
|
1100
|
+
loginCallbackWithAutoTokensRenewAsync():Promise<LoginCallback>{
|
|
1108
1101
|
if(this.loginCallbackWithAutoTokensRenewPromise !== null){
|
|
1109
1102
|
return this.loginCallbackWithAutoTokensRenewPromise;
|
|
1110
1103
|
}
|
|
@@ -24,8 +24,17 @@ const countLetter = (str, find)=> {
|
|
|
24
24
|
return (str.split(find)).length - 1;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
export type Tokens = {
|
|
28
|
+
refreshToken: string,
|
|
29
|
+
idTokenPayload:any,
|
|
30
|
+
idToken:string,
|
|
31
|
+
accessTokenPayload:any,
|
|
32
|
+
accessToken:string,
|
|
33
|
+
expiresAt: number,
|
|
34
|
+
issuedAt: number
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const setTokens = (tokens, oldTokens=null):Tokens =>{
|
|
29
38
|
|
|
30
39
|
if(!tokens){
|
|
31
40
|
return null;
|
|
@@ -45,9 +54,9 @@ export const setTokens = (tokens, oldTokens=null) =>{
|
|
|
45
54
|
}
|
|
46
55
|
const _idTokenPayload = tokens.idTokenPayload ? tokens.idTokenPayload : extractTokenPayload(tokens.idToken);
|
|
47
56
|
|
|
48
|
-
const
|
|
57
|
+
const idTokenExpireAt =(_idTokenPayload && _idTokenPayload.exp) ? _idTokenPayload.exp: Number.MAX_VALUE;
|
|
49
58
|
const accessTokenExpiresAt = (accessTokenPayload && accessTokenPayload.exp)? accessTokenPayload.exp : tokens.issuedAt + tokens.expiresIn;
|
|
50
|
-
const expiresAt =
|
|
59
|
+
const expiresAt = idTokenExpireAt < accessTokenExpiresAt ? idTokenExpireAt : accessTokenExpiresAt;
|
|
51
60
|
|
|
52
61
|
const newTokens = {...tokens, idTokenPayload: _idTokenPayload, accessTokenPayload, expiresAt};
|
|
53
62
|
// When refresh_token is not rotated we reuse ald refresh_token
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
function onMessage(port, event) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
const method = event.data[0];
|
|
36
|
+
const id = event.data[1];
|
|
37
|
+
const option = event.data[2];
|
|
38
38
|
|
|
39
39
|
if (methods[method]) {
|
|
40
40
|
methods[method](port, id, option);
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import {LoginCallback, Oidc, OidcConfiguration, StringMap} from "./oidc";
|
|
2
|
+
import {isTokensValid} from "./parseTokens";
|
|
3
|
+
import {sleepAsync} from "./initWorker";
|
|
4
|
+
import {Tokens} from "./parseTokens";
|
|
5
|
+
|
|
6
|
+
type ValidToken = {
|
|
7
|
+
isTokensValid: Boolean,
|
|
8
|
+
tokens: Tokens,
|
|
9
|
+
numberWaited: Number
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class VanillaOidc {
|
|
13
|
+
private _oidc: Oidc;
|
|
14
|
+
constructor(oidc: Oidc) {
|
|
15
|
+
this._oidc = oidc;
|
|
16
|
+
}
|
|
17
|
+
subscriveEvents(func:Function):string{
|
|
18
|
+
return this._oidc.subscriveEvents(func);
|
|
19
|
+
}
|
|
20
|
+
removeEventSubscription(id:string):void{
|
|
21
|
+
this._oidc.removeEventSubscription(id);
|
|
22
|
+
}
|
|
23
|
+
publishEvent(eventName:string, data:any) : void{
|
|
24
|
+
this._oidc.publishEvent(eventName, data);
|
|
25
|
+
}
|
|
26
|
+
static getOrCreate(configuration:OidcConfiguration, name:string="default"):VanillaOidc {
|
|
27
|
+
return new VanillaOidc(Oidc.getOrCreate(configuration, name));
|
|
28
|
+
}
|
|
29
|
+
static get(name:string="default"):VanillaOidc {
|
|
30
|
+
return new VanillaOidc(Oidc.get(name));
|
|
31
|
+
}
|
|
32
|
+
static eventNames = Oidc.eventNames;
|
|
33
|
+
tryKeepExistingSessionAsync():Promise<boolean>{
|
|
34
|
+
return this._oidc.tryKeepExistingSessionAsync();
|
|
35
|
+
}
|
|
36
|
+
loginAsync(callbackPath:string=undefined, extras:StringMap=null, isSilentSignin:boolean=false, scope:string=undefined, silentLoginOnly = false):Promise<void> {
|
|
37
|
+
return this._oidc.loginAsync(callbackPath, extras, isSilentSignin, scope, silentLoginOnly);
|
|
38
|
+
}
|
|
39
|
+
logoutAsync(callbackPathOrUrl: string | null | undefined = undefined, extras: StringMap = null):Promise<void> {
|
|
40
|
+
return this._oidc.logoutAsync(callbackPathOrUrl, extras);
|
|
41
|
+
}
|
|
42
|
+
silentLoginCallbackAsync():Promise<any>{
|
|
43
|
+
return this._oidc.silentLoginCallbackAsync();
|
|
44
|
+
};
|
|
45
|
+
renewTokensAsync(extras:StringMap=null):Promise<void> {
|
|
46
|
+
return this._oidc.renewTokensAsync(extras);
|
|
47
|
+
}
|
|
48
|
+
loginCallbackAsync():Promise<LoginCallback>{
|
|
49
|
+
return this._oidc.loginCallbackWithAutoTokensRenewAsync();
|
|
50
|
+
}
|
|
51
|
+
get tokens():Tokens {
|
|
52
|
+
return this._oidc.tokens;
|
|
53
|
+
}
|
|
54
|
+
get configuration():OidcConfiguration {
|
|
55
|
+
return this._oidc.configuration;
|
|
56
|
+
}
|
|
57
|
+
async getValidTokenAsync(waitMs=200, numberWait=50 ): Promise<ValidToken> {
|
|
58
|
+
const oidc = this._oidc;
|
|
59
|
+
let numberWaitTemp = numberWait;
|
|
60
|
+
while (oidc.tokens && !isTokensValid(oidc.tokens) && numberWaitTemp > 0) {
|
|
61
|
+
await sleepAsync(200);
|
|
62
|
+
numberWaitTemp=numberWaitTemp-1;
|
|
63
|
+
}
|
|
64
|
+
const isValid = !isTokensValid(oidc.tokens);
|
|
65
|
+
return {
|
|
66
|
+
isTokensValid: isValid,
|
|
67
|
+
tokens: oidc.tokens,
|
|
68
|
+
numberWaited: numberWaitTemp - numberWait
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
async userInfoAsync():Promise<any>{
|
|
72
|
+
return this._oidc.userInfoAsync();
|
|
73
|
+
}
|
|
74
|
+
}
|