Support custom validateAuthorizationCode in generic-oauth plugin #557

Closed
opened 2026-03-13 07:52:53 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @windson4 on GitHub (Jan 12, 2025).

Is this suited for github?

  • Yes, this is suited for github

Is your feature request related to a problem? Please describe.

The generic-oauth plugin currently doesn't support customizing the validateAuthorizationCode logic. While the plugin provides options to customize getUserInfo and mapProfileToUser, there's no way to customize the authorization code validation process.

Describe the solution you'd like

Add a new optional configuration option validateAuthorizationCode to GenericOAuthConfig interface:

interface GenericOAuthConfig {
	validateAuthorizationCode?: (data: {
		code: string;
		codeVerifier?: string;
		redirectURI: string;
	}) => Promise<OAuth2Tokens>;
}

This would allow users to implement their own authorization code validation logic while maintaining the default implementation for standard cases.

Describe alternatives you've considered

currently, I'm using a workaround in my Next project by:
create a custom API route to handle token fetch and set this route as the tokenUrl in the generic-oauth configuration.

    genericOAuth({
      config: [
        {
          providerId: "xxx",
          tokenUrl: `${process.env.NEXT_PUBLIC_DOMAIN}/api/auth/oauth2/token`,
        },
      ],
    }),

While this works, it has several drawbacks:

  • Requires additional route setup and maintenance
  • Adds unnecessary network requests

A built-in way to customize the validation logic would be more elegant and maintainable than the current workaround.

Additional context

No response

Originally created by @windson4 on GitHub (Jan 12, 2025). ### Is this suited for github? - [X] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. The `generic-oauth` plugin currently doesn't support customizing the `validateAuthorizationCode` logic. While the plugin provides options to customize `getUserInfo` and `mapProfileToUser`, there's no way to customize the authorization code validation process. ### Describe the solution you'd like Add a new optional configuration option `validateAuthorizationCode` to `GenericOAuthConfig` interface: ```typescript interface GenericOAuthConfig { validateAuthorizationCode?: (data: { code: string; codeVerifier?: string; redirectURI: string; }) => Promise<OAuth2Tokens>; } ``` This would allow users to implement their own authorization code validation logic while maintaining the default implementation for standard cases. ### Describe alternatives you've considered currently, I'm using a workaround in my Next project by: create a custom API route to handle token fetch and set this route as the tokenUrl in the generic-oauth configuration. ```typescript genericOAuth({ config: [ { providerId: "xxx", tokenUrl: `${process.env.NEXT_PUBLIC_DOMAIN}/api/auth/oauth2/token`, }, ], }), ``` While this works, it has several drawbacks: - Requires additional route setup and maintenance - Adds unnecessary network requests A built-in way to customize the validation logic would be more elegant and maintainable than the current workaround. ### Additional context _No response_
GiteaMirror added the enhancement label 2026-03-13 07:52:53 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jun 12, 2025):

Hi, @windson4. I'm Dosu, and I'm helping the better-auth team manage their backlog. I'm marking this issue as stale.

Issue Summary:

  • You proposed adding a customizable validateAuthorizationCode option to the generic-oauth plugin.
  • This feature would allow users to implement custom logic for validating authorization codes.
  • The enhancement aims to improve efficiency and reduce maintenance efforts.
  • No comments or additional activity have occurred on this issue.

Next Steps:

  • Please let us know if this issue is still relevant to the latest version of the better-auth repository by commenting here.
  • If there is no response, the issue will be automatically closed in 7 days.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Jun 12, 2025): Hi, @windson4. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog. I'm marking this issue as stale. **Issue Summary:** - You proposed adding a customizable `validateAuthorizationCode` option to the `generic-oauth` plugin. - This feature would allow users to implement custom logic for validating authorization codes. - The enhancement aims to improve efficiency and reduce maintenance efforts. - No comments or additional activity have occurred on this issue. **Next Steps:** - Please let us know if this issue is still relevant to the latest version of the better-auth repository by commenting here. - If there is no response, the issue will be automatically closed in 7 days. Thank you for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#557