Skip to content

Commit

Permalink
fix: auth and token endpoint integration
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed Aug 21, 2024
1 parent 9f7866c commit 6f09926
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
29 changes: 13 additions & 16 deletions lib/build/recipe/oauth2provider/recipeImplementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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];
}
Expand Down Expand Up @@ -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
);
Expand All @@ -347,7 +344,7 @@ function getRecipeInterface(
errorDescription: res.data.error_description,
};
}
return res.data;
return res;
},
getOAuth2Clients: async function (input) {
var _a;
Expand Down
25 changes: 14 additions & 11 deletions lib/ts/recipe/oauth2provider/recipeImplementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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];
}
Expand Down Expand Up @@ -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
);
Expand All @@ -324,7 +327,7 @@ export default function getRecipeInterface(
errorDescription: res.data.error_description,
};
}
return res.data;
return res;
},

getOAuth2Clients: async function (input) {
Expand Down

0 comments on commit 6f09926

Please sign in to comment.