Skip to content

Commit

Permalink
feat: test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
porcellus committed Oct 25, 2024
1 parent aa2fb4f commit 4a90c0d
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/build/recipe/oauth2provider/api/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ async function login(apiImplementation, options, userContext) {
frontendRedirectTo: response.frontendRedirectTo,
});
} else if ("statusCode" in response) {
// We want to avoid returning a 401 to the frontend, as it may trigger a refresh loop
if (response.statusCode === 401) {
response.statusCode = 400;
}
utils_1.sendNon200Response(options.res, (_b = response.statusCode) !== null && _b !== void 0 ? _b : 400, {
error: response.error,
error_description: response.errorDescription,
Expand Down
4 changes: 4 additions & 0 deletions lib/build/recipe/oauth2provider/api/loginInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ async function loginInfoGET(apiImplementation, options, userContext) {
userContext,
});
if ("error" in response) {
// We want to avoid returning a 401 to the frontend, as it may trigger a refresh loop
if (response.statusCode === 401) {
response.statusCode = 400;
}
utils_1.sendNon200Response(options.res, (_b = response.statusCode) !== null && _b !== void 0 ? _b : 400, {
error: response.error,
error_description: response.errorDescription,
Expand Down
4 changes: 4 additions & 0 deletions lib/build/recipe/oauth2provider/api/logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ async function logoutPOST(apiImplementation, options, userContext) {
if ("status" in response && response.status === "OK") {
utils_1.send200Response(options.res, response);
} else if ("statusCode" in response) {
// We want to avoid returning a 401 to the frontend, as it may trigger a refresh loop
if (response.statusCode === 401) {
response.statusCode = 400;
}
utils_1.sendNon200Response(options.res, (_a = response.statusCode) !== null && _a !== void 0 ? _a : 400, {
error: response.error,
error_description: response.errorDescription,
Expand Down
1 change: 1 addition & 0 deletions lib/build/recipe/oauth2provider/api/revokeToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ async function revokeTokenPOST(apiImplementation, options, userContext) {
userContext,
});
if ("statusCode" in response && response.statusCode !== 200) {
// We do not need to normalize as this is not expected to be called by frontends where interception is enabled
utils_1.sendNon200Response(options.res, (_a = response.statusCode) !== null && _a !== void 0 ? _a : 400, {
error: response.error,
error_description: response.errorDescription,
Expand Down
1 change: 1 addition & 0 deletions lib/build/recipe/oauth2provider/api/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ async function tokenPOST(apiImplementation, options, userContext) {
userContext,
});
if ("error" in response) {
// We do not need to normalize as this is not expected to be called by frontends where interception is enabled
utils_1.sendNon200Response(options.res, (_a = response.statusCode) !== null && _a !== void 0 ? _a : 400, {
error: response.error,
error_description: response.errorDescription,
Expand Down
1 change: 1 addition & 0 deletions lib/build/recipe/oauth2provider/recipeImplementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ function getRecipeInterface(
new normalisedURLPath_1.default(`/recipe/oauth/auth`),
{
params: Object.assign(Object.assign({}, input.params), { scope: scopes.join(" ") }),
iss: await recipe_2.default.getIssuer(input.userContext),
cookies: input.cookies,
session: payloads,
},
Expand Down
5 changes: 5 additions & 0 deletions lib/ts/recipe/oauth2provider/api/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ export default async function login(
frontendRedirectTo: response.frontendRedirectTo,
});
} else if ("statusCode" in response) {
// We want to avoid returning a 401 to the frontend, as it may trigger a refresh loop
if (response.statusCode === 401) {
response.statusCode = 400;
}

sendNon200Response(options.res, response.statusCode ?? 400, {
error: response.error,
error_description: response.errorDescription,
Expand Down
4 changes: 4 additions & 0 deletions lib/ts/recipe/oauth2provider/api/loginInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export default async function loginInfoGET(
});

if ("error" in response) {
// We want to avoid returning a 401 to the frontend, as it may trigger a refresh loop
if (response.statusCode === 401) {
response.statusCode = 400;
}
sendNon200Response(options.res, response.statusCode ?? 400, {
error: response.error,
error_description: response.errorDescription,
Expand Down
5 changes: 5 additions & 0 deletions lib/ts/recipe/oauth2provider/api/logout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ export async function logoutPOST(
if ("status" in response && response.status === "OK") {
send200Response(options.res, response);
} else if ("statusCode" in response) {
// We want to avoid returning a 401 to the frontend, as it may trigger a refresh loop
if (response.statusCode === 401) {
response.statusCode = 400;
}

sendNon200Response(options.res, response.statusCode ?? 400, {
error: response.error,
error_description: response.errorDescription,
Expand Down
1 change: 1 addition & 0 deletions lib/ts/recipe/oauth2provider/api/revokeToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export default async function revokeTokenPOST(
});

if ("statusCode" in response && response.statusCode !== 200) {
// We do not need to normalize as this is not expected to be called by frontends where interception is enabled
sendNon200Response(options.res, response.statusCode ?? 400, {
error: response.error,
error_description: response.errorDescription,
Expand Down
1 change: 1 addition & 0 deletions lib/ts/recipe/oauth2provider/api/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default async function tokenPOST(
});

if ("error" in response) {
// We do not need to normalize as this is not expected to be called by frontends where interception is enabled
sendNon200Response(options.res, response.statusCode ?? 400, {
error: response.error,
error_description: response.errorDescription,
Expand Down
1 change: 1 addition & 0 deletions lib/ts/recipe/oauth2provider/recipeImplementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ export default function getRecipeInterface(
...input.params,
scope: scopes.join(" "),
},
iss: await OpenIdRecipe.getIssuer(input.userContext),
cookies: input.cookies,
session: payloads,
},
Expand Down

0 comments on commit 4a90c0d

Please sign in to comment.