fix(auth): renew cached subdomain tokens before bounded request replay
This commit is contained in:
1 parent
fac81b08e8
commit
53689e89d0
6 files changed
+365
-326
No files matched your search
@@ -138,9 +138,11 @@ function invalidateEasoCache(corpId: string): void {
|
||||
function invalidateUnityCache(corpId: string): void {
|
||||
unityMemoryCache.delete(`${corpId}:unity`);
|
||||
const persisted = getCorpTokens(corpId);
|
||||
if (persisted?.unity) {
|
||||
if (persisted?.unity || persisted?.eas) {
|
||||
const next = { ...persisted };
|
||||
delete next.unity;
|
||||
// EASO also persists the Unity JWT; do not resurrect the rejected token through that fallback.
|
||||
delete next.eas;
|
||||
setCorpTokens(corpId, next);
|
||||
}
|
||||
}
|
||||
@@ -184,13 +186,15 @@ export async function getEasoClient(corp: CorpConfig): Promise<{
|
||||
client: createAuthClient({
|
||||
prefixUrl: EASO_BASE_URL,
|
||||
getHeaders: () => ({
|
||||
Authorization: `Bearer ${cachedToken}`,
|
||||
Authorization: `Bearer ${easoMemoryCache.get(cacheKey)?.token ?? cachedToken}`,
|
||||
accesstoken: corp.credentials.accessToken,
|
||||
corporationid: corpId,
|
||||
hoseaccesstoken: cachedHoseToken,
|
||||
hoseaccesstoken: easoMemoryCache.get(cacheKey)?.hoseToken ?? cachedHoseToken,
|
||||
}),
|
||||
onUnauthorized: () => {
|
||||
onUnauthorized: async () => {
|
||||
invalidateEasoCache(corp.id);
|
||||
if (canRefreshCorpAccessToken(corp)) await refreshSingleCorpAccessToken(corp);
|
||||
await getEasoClient(corp);
|
||||
},
|
||||
}),
|
||||
};
|
||||
@@ -262,13 +266,15 @@ export async function getEasoClient(corp: CorpConfig): Promise<{
|
||||
client: createAuthClient({
|
||||
prefixUrl: EASO_BASE_URL,
|
||||
getHeaders: () => ({
|
||||
Authorization: `Bearer ${easoToken}`,
|
||||
Authorization: `Bearer ${easoMemoryCache.get(cacheKey)?.token ?? easoToken}`,
|
||||
accesstoken: corp.credentials.accessToken,
|
||||
corporationid: corpId,
|
||||
hoseaccesstoken: hoseToken,
|
||||
hoseaccesstoken: easoMemoryCache.get(cacheKey)?.hoseToken ?? hoseToken,
|
||||
}),
|
||||
onUnauthorized: () => {
|
||||
onUnauthorized: async () => {
|
||||
invalidateEasoCache(corp.id);
|
||||
if (canRefreshCorpAccessToken(corp)) await refreshSingleCorpAccessToken(corp);
|
||||
await getEasoClient(corp);
|
||||
},
|
||||
}),
|
||||
};
|
||||
@@ -314,10 +320,12 @@ export async function getUnityClient(corp: CorpConfig): Promise<{
|
||||
client: createAuthClient({
|
||||
prefixUrl: EASO_BASE_URL,
|
||||
getHeaders: () => ({
|
||||
Authorization: `Bearer ${cachedJwt}`,
|
||||
Authorization: `Bearer ${unityMemoryCache.get(cacheKey)?.token ?? cachedJwt}`,
|
||||
}),
|
||||
onUnauthorized: () => {
|
||||
onUnauthorized: async () => {
|
||||
invalidateUnityCache(corp.id);
|
||||
if (canRefreshCorpAccessToken(corp)) await refreshSingleCorpAccessToken(corp);
|
||||
await getUnityClient(corp);
|
||||
},
|
||||
}),
|
||||
};
|
||||
@@ -364,10 +372,12 @@ export async function getUnityClient(corp: CorpConfig): Promise<{
|
||||
client: createAuthClient({
|
||||
prefixUrl: EASO_BASE_URL,
|
||||
getHeaders: () => ({
|
||||
Authorization: `Bearer ${unityJwt}`,
|
||||
Authorization: `Bearer ${unityMemoryCache.get(cacheKey)?.token ?? unityJwt}`,
|
||||
}),
|
||||
onUnauthorized: () => {
|
||||
onUnauthorized: async () => {
|
||||
invalidateUnityCache(corp.id);
|
||||
if (canRefreshCorpAccessToken(corp)) await refreshSingleCorpAccessToken(corp);
|
||||
await getUnityClient(corp);
|
||||
},
|
||||
}),
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user