-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(oidc): token renew only when required (release) (#1327)
- Loading branch information
1 parent
db67095
commit 9a3ad3a
Showing
15 changed files
with
83 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
import {ILOidcLocation} from "./location"; | ||
|
||
export { getFetchDefault } from './oidc.js'; | ||
export { TokenRenewMode } from './parseTokens.js'; | ||
export { getParseQueryStringFromLocation, getPath } from './route-utils'; | ||
export type { | ||
AuthorityConfiguration, | ||
Fetch, | ||
OidcConfiguration, | ||
StringMap, | ||
StringMap | ||
} from './types.js'; | ||
export { type ILOidcLocation, OidcLocation } from './location.js'; | ||
|
||
export { OidcLocation } from './location.js'; | ||
export type { ILOidcLocation } from './location.js'; | ||
export { TokenAutomaticRenewMode } from './types.js'; | ||
export { type OidcUserInfo, OidcClient } from './oidcClient.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,22 @@ | ||
import { sleepAsync } from './initWorker.js'; | ||
import { isTokensValid } from './parseTokens.js'; | ||
import Oidc from "./oidc"; | ||
import {fetchWithTokens} from "./fetch"; | ||
|
||
export const userInfoAsync = (oidc:Oidc) => async (noCache = false) => { | ||
if (oidc.userInfo != null && !noCache) { | ||
return oidc.userInfo; | ||
} | ||
|
||
// We wait the synchronisation before making a request | ||
while (oidc.tokens && !isTokensValid(oidc.tokens)) { | ||
await sleepAsync({milliseconds: 200}); | ||
} | ||
|
||
if (!oidc.tokens) { | ||
return null; | ||
} | ||
const accessToken = oidc.tokens.accessToken; | ||
if (!accessToken) { | ||
return null; | ||
} | ||
|
||
const configuration = oidc.configuration; | ||
const oidcServerConfiguration = await oidc.initAsync(configuration.authority, configuration.authority_configuration); | ||
const url = oidcServerConfiguration.userInfoEndpoint; | ||
const fetchUserInfo = async (accessToken) => { | ||
const res = await fetch(url, { | ||
headers: { | ||
authorization: `Bearer ${accessToken}`, | ||
}, | ||
}); | ||
|
||
if (res.status !== 200) { | ||
const fetchUserInfo = async () => { | ||
const oidcFetch = fetchWithTokens(fetch, oidc); | ||
const response = await oidcFetch(url); | ||
if (response.status !== 200) { | ||
return null; | ||
} | ||
|
||
return res.json(); | ||
return response.json(); | ||
}; | ||
const userInfo = await fetchUserInfo(accessToken); | ||
const userInfo = await fetchUserInfo(); | ||
oidc.userInfo = userInfo; | ||
return userInfo; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters