@defra/lis-hubs-infra-access 0.42.0 → 0.43.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/package.json +1 -1
- package/src/authentication/oidc.js +16 -2
package/package.json
CHANGED
|
@@ -32,8 +32,16 @@ async function readOAuthErrorCode(response) {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
// Discovery and token exchange go to the identity provider via the outbound
|
|
36
|
+
// proxy; without a timeout a hung connection holds the sign-in request open
|
|
37
|
+
// for as long as the socket lives.
|
|
38
|
+
const OIDC_FETCH_TIMEOUT_MS = 10000
|
|
39
|
+
|
|
35
40
|
async function fetchJson(url, options = {}) {
|
|
36
|
-
const response = await fetch(url,
|
|
41
|
+
const response = await fetch(url, {
|
|
42
|
+
signal: AbortSignal.timeout(OIDC_FETCH_TIMEOUT_MS),
|
|
43
|
+
...options
|
|
44
|
+
})
|
|
37
45
|
|
|
38
46
|
if (!response.ok) {
|
|
39
47
|
const oauthError = await readOAuthErrorCode(response)
|
|
@@ -76,9 +84,15 @@ function createMetadataLoader(resolveProviderConfig) {
|
|
|
76
84
|
const providerConfig = resolveProviderConfig(providerId)
|
|
77
85
|
|
|
78
86
|
if (!providerMetadata.has(providerConfig.providerId)) {
|
|
87
|
+
// Cache the in-flight request so concurrent sign-ins share one fetch,
|
|
88
|
+
// but drop it if it fails: a cached rejection would turn one timeout
|
|
89
|
+
// or proxy blip into a 503 on every sign-in until the instance restarts.
|
|
79
90
|
providerMetadata.set(
|
|
80
91
|
providerConfig.providerId,
|
|
81
|
-
fetchJson(providerConfig.discoveryUrl)
|
|
92
|
+
fetchJson(providerConfig.discoveryUrl).catch((error) => {
|
|
93
|
+
providerMetadata.delete(providerConfig.providerId)
|
|
94
|
+
throw error
|
|
95
|
+
})
|
|
82
96
|
)
|
|
83
97
|
}
|
|
84
98
|
|