mirror of
https://github.com/better-auth/better-auth.git
synced 2026-08-01 10:50:40 -05:00
feat(generic-oauth): add support for additional token URL params in generic OAuth (#3410)
* feat(generic-oauth): add support for additional token URL params in generic OAuth fix #3402 * Update packages/better-auth/src/oauth2/validate-authorization-code.ts Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> * fix: syntax error --------- Co-authored-by: Maxwell <145994855+ping-maxwell@users.noreply.github.com> Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> Co-authored-by: ping-maxwell <maxwell.multinite@gmail.com>
This commit is contained in:
co-authored by
Maxwell
cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
ping-maxwell
parent
adf8be7acb
commit
2ac4f9db35
@@ -13,6 +13,7 @@ export async function validateAuthorizationCode({
|
||||
authentication,
|
||||
deviceId,
|
||||
headers,
|
||||
additionalParams = {},
|
||||
}: {
|
||||
code: string;
|
||||
redirectURI: string;
|
||||
@@ -22,6 +23,7 @@ export async function validateAuthorizationCode({
|
||||
tokenEndpoint: string;
|
||||
authentication?: "basic" | "post";
|
||||
headers?: Record<string, string>;
|
||||
additionalParams?: Record<string, string>;
|
||||
}) {
|
||||
const body = new URLSearchParams();
|
||||
const requestHeaders: Record<string, any> = {
|
||||
@@ -46,6 +48,11 @@ export async function validateAuthorizationCode({
|
||||
body.set("client_id", options.clientId);
|
||||
body.set("client_secret", options.clientSecret);
|
||||
}
|
||||
|
||||
for (const [key, value] of Object.entries(additionalParams)) {
|
||||
if (!body.has(key)) body.append(key, value);
|
||||
}
|
||||
|
||||
const { data, error } = await betterFetch<object>(tokenEndpoint, {
|
||||
method: "POST",
|
||||
body: body,
|
||||
|
||||
@@ -113,6 +113,12 @@ export interface GenericOAuthConfig {
|
||||
* Warning: Search-params added here overwrite any default params.
|
||||
*/
|
||||
authorizationUrlParams?: Record<string, string>;
|
||||
|
||||
/**
|
||||
* Additional search-params to add to the tokenUrl.
|
||||
* Warning: Search-params added here overwrite any default params.
|
||||
*/
|
||||
tokenUrlParams?: Record<string, string>;
|
||||
/**
|
||||
* Disable implicit sign up for new users. When set to true for the provider,
|
||||
* sign-in need to be called with with requestSignUp as true to create new users.
|
||||
@@ -605,6 +611,7 @@ export const genericOAuth = (options: GenericOAuthOptions) => {
|
||||
},
|
||||
tokenEndpoint: finalTokenUrl,
|
||||
authentication: provider.authentication,
|
||||
additionalParams: provider.tokenUrlParams,
|
||||
});
|
||||
} catch (e) {
|
||||
ctx.context.logger.error(
|
||||
|
||||
Reference in New Issue
Block a user