From 6f0992606a7cd47dc4c27e6f24b194862f0db16f Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Wed, 21 Aug 2024 21:12:21 +0530 Subject: [PATCH] fix: auth and token endpoint integration --- .../oauth2provider/recipeImplementation.js | 29 +++++++++---------- .../oauth2provider/recipeImplementation.ts | 25 +++++++++------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/lib/build/recipe/oauth2provider/recipeImplementation.js b/lib/build/recipe/oauth2provider/recipeImplementation.js index c0371d998..0b37959b0 100644 --- a/lib/build/recipe/oauth2provider/recipeImplementation.js +++ b/lib/build/recipe/oauth2provider/recipeImplementation.js @@ -211,16 +211,16 @@ function getRecipeInterface( delete input.params.prompt; } } - const resp = await querier.sendGetRequestWithResponseHeaders( - new normalisedURLPath_1.default(`/recipe/oauth2/pub/auth`), - input.params, - { - // TODO: if session is not set also clear the oauth2 cookie - Cookie: `${input.cookies}`, - }, + const resp = await querier.sendPostRequest( + new normalisedURLPath_1.default(`/recipe/oauth/auth`), + Object.assign(Object.assign({}, input.params), { cookie: `${input.cookies}` }), + // { + // // TODO: if session is not set also clear the oauth2 cookie + // Cookie: `${input.cookies}`, + // }, input.userContext ); - const redirectTo = getUpdatedRedirectTo(appInfo, resp.headers.get("Location")); + const redirectTo = resp.redirectTo; if (redirectTo === undefined) { throw new Error(resp.body); } @@ -268,17 +268,14 @@ function getRecipeInterface( ); return { redirectTo: consentRes.redirectTo, - setCookie: (_a = resp.headers.get("set-cookie")) !== null && _a !== void 0 ? _a : undefined, + setCookie: (_a = resp.cookies) !== null && _a !== void 0 ? _a : undefined, }; } - return { - redirectTo, - setCookie: (_b = resp.headers.get("set-cookie")) !== null && _b !== void 0 ? _b : undefined, - }; + return { redirectTo, setCookie: (_b = resp.cookies) !== null && _b !== void 0 ? _b : undefined }; }, tokenExchange: async function (input) { var _a, _b; - const body = { $isFormData: true }; // TODO: we ideally want to avoid using formdata, the core can do the translation + const body = {}; for (const key in input.body) { body[key] = input.body[key]; } @@ -336,7 +333,7 @@ function getRecipeInterface( body["authorizationHeader"] = input.authorizationHeader; } const res = await querier.sendPostRequest( - new normalisedURLPath_1.default(`/recipe/oauth2/pub/token`), + new normalisedURLPath_1.default(`/recipe/oauth/token`), body, input.userContext ); @@ -347,7 +344,7 @@ function getRecipeInterface( errorDescription: res.data.error_description, }; } - return res.data; + return res; }, getOAuth2Clients: async function (input) { var _a; diff --git a/lib/ts/recipe/oauth2provider/recipeImplementation.ts b/lib/ts/recipe/oauth2provider/recipeImplementation.ts index 77aa57abc..9ab09301e 100644 --- a/lib/ts/recipe/oauth2provider/recipeImplementation.ts +++ b/lib/ts/recipe/oauth2provider/recipeImplementation.ts @@ -184,17 +184,20 @@ export default function getRecipeInterface( } } - const resp = await querier.sendGetRequestWithResponseHeaders( - new NormalisedURLPath(`/recipe/oauth2/pub/auth`), - input.params, + const resp = await querier.sendPostRequest( + new NormalisedURLPath(`/recipe/oauth/auth`), { - // TODO: if session is not set also clear the oauth2 cookie - Cookie: `${input.cookies}`, + ...input.params, + cookie: `${input.cookies}`, }, + // { + // // TODO: if session is not set also clear the oauth2 cookie + // Cookie: `${input.cookies}`, + // }, input.userContext ); - const redirectTo = getUpdatedRedirectTo(appInfo, resp.headers.get("Location")!); + const redirectTo = resp.redirectTo; if (redirectTo === undefined) { throw new Error(resp.body); } @@ -245,14 +248,14 @@ export default function getRecipeInterface( return { redirectTo: consentRes.redirectTo, - setCookie: resp.headers.get("set-cookie") ?? undefined, + setCookie: resp.cookies ?? undefined, }; } - return { redirectTo, setCookie: resp.headers.get("set-cookie") ?? undefined }; + return { redirectTo, setCookie: resp.cookies ?? undefined }; }, tokenExchange: async function (this: RecipeInterface, input) { - const body: any = { $isFormData: true }; // TODO: we ideally want to avoid using formdata, the core can do the translation + const body: any = {}; for (const key in input.body) { body[key] = input.body[key]; } @@ -312,7 +315,7 @@ export default function getRecipeInterface( } const res = await querier.sendPostRequest( - new NormalisedURLPath(`/recipe/oauth2/pub/token`), + new NormalisedURLPath(`/recipe/oauth/token`), body, input.userContext ); @@ -324,7 +327,7 @@ export default function getRecipeInterface( errorDescription: res.data.error_description, }; } - return res.data; + return res; }, getOAuth2Clients: async function (input) {