Allow to include client_id field in the body of the token request (problems with Modrinth OAuth) #1468

Closed
opened 2026-03-13 08:41:54 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @KostarSf on GitHub (Jul 6, 2025).

Is this suited for github?

  • Yes, this is suited for github

I can't set up the OAuth flow for the Morinth site using the genericOAuth plugin because their api requires the "client_id" to be included in the body of the token request.
According to Modrinth docs (https://docs.modrinth.com/guide/oauth), they need the client_id inside the FormData POST request to exchange the access token.

With the following configuration:

export const auth = betterAuth({
  plugins: [
    genericOAuth({
      config: [
        {
          providerId: "modrinth",
          clientId: env.MODRINTH_CLIENT_ID,
          clientSecret: env.MODRINTH_CLIENT_SECRET,
          authorizationUrl: "https://modrinth.com/auth/authorize",
          tokenUrl: `https://api.modrinth.com/_internal/oauth/token`,
          userInfoUrl: "https://api.modrinth.com/v2/user",
          authentication: "basic",
          scopes: ["USER_READ_EMAIL", "USER_READ"],
        },
      ],
    }),
    nextCookies(),
  ],
});

I get the following oauth_code_verification_failed error:

2025-07-06T14:24:23.702Z ERROR [Better Auth]:  {
  error: 'invalid_input',
  description: 'Error while validating input: Parse error: missing field `client_id`.',
  status: 400,
  statusText: 'Bad Request'
}

If I make a request to this endpoint manually with the following FormData body:

Key Value
code oauth code from previous step
client_id my client id
redirect_uri my redirect uri
grant_type authorization_code

I get access token successfully

Describe the solution you'd like

Include client_id field into token exchange request

Describe alternatives you've considered

Allow custom fields to be set when sending a token exchange request, for example:

genericOAuth({
  config: [
    {
      tokenUrl: `https://api.modrinth.com/_internal/oauth/token`,
      tokenData: {
        client_id: "client id",
      },
    },
  ],
}),

Additional context

Perhaps there is a simpler way around this issue. Please direct me to a possible solution, if so 🙄

Originally created by @KostarSf on GitHub (Jul 6, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. I can't set up the OAuth flow for the Morinth site using the genericOAuth plugin because their api requires the "client_id" to be included in the body of the token request. According to Modrinth docs (https://docs.modrinth.com/guide/oauth), they need the `client_id` inside the FormData POST request to exchange the access token. With the following configuration: ```js export const auth = betterAuth({ plugins: [ genericOAuth({ config: [ { providerId: "modrinth", clientId: env.MODRINTH_CLIENT_ID, clientSecret: env.MODRINTH_CLIENT_SECRET, authorizationUrl: "https://modrinth.com/auth/authorize", tokenUrl: `https://api.modrinth.com/_internal/oauth/token`, userInfoUrl: "https://api.modrinth.com/v2/user", authentication: "basic", scopes: ["USER_READ_EMAIL", "USER_READ"], }, ], }), nextCookies(), ], }); ``` I get the following oauth_code_verification_failed error: ``` 2025-07-06T14:24:23.702Z ERROR [Better Auth]: { error: 'invalid_input', description: 'Error while validating input: Parse error: missing field `client_id`.', status: 400, statusText: 'Bad Request' } ``` If I make a request to this endpoint manually with the following FormData body: | Key | Value | |-----|-----| | code | oauth code from previous step | | client_id | my client id | | redirect_uri | my redirect uri | | grant_type | authorization_code | I get access token successfully ### Describe the solution you'd like Include client_id field into token exchange request ### Describe alternatives you've considered Allow custom fields to be set when sending a token exchange request, for example: ```js genericOAuth({ config: [ { tokenUrl: `https://api.modrinth.com/_internal/oauth/token`, tokenData: { client_id: "client id", }, }, ], }), ``` ### Additional context Perhaps there is a simpler way around this issue. Please direct me to a possible solution, if so 🙄
GiteaMirror added the social-provider label 2026-03-13 08:41:54 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jul 6, 2025):

Hi @KostarSf! I'm Dosu and I’m helping the better-auth team.

The genericOAuth plugin in better-auth does not currently support adding custom fields like client_id to the token request body via configuration. The token exchange request is built from a fixed set of fields, and there is no option like tokenData to merge in extra fields as required by Modrinth's OAuth flow. This means your current setup cannot include client_id in the POST body automatically, which is why you're seeing the error from Modrinth's API "Parse error: missing field client_id".

To support this, the plugin would need a small extension: add a tokenData (or similar) option to the GenericOAuthConfig, and merge its contents into the token request body in the validateAuthorizationCode function. The codebase is modular and this change would be straightforward and backward-compatible.

As a workaround, you could fork the plugin and patch in this behavior, or implement a minimal custom OAuth provider that builds the token request body as Modrinth expects.

If you want to reference or propose this change, the relevant code is in packages/better-auth/src/plugins/generic-oauth/index.ts, specifically where the token request body is constructed in validateAuthorizationCode. This enhancement would also benefit other providers with non-standard requirements.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

@dosubot[bot] commented on GitHub (Jul 6, 2025): <!-- Greeting --> Hi @KostarSf! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> The genericOAuth plugin in better-auth does not currently support adding custom fields like client_id to the token request body via configuration. The token exchange request is built from a fixed set of fields, and there is no option like tokenData to merge in extra fields as required by Modrinth's OAuth flow. This means your current setup cannot include client_id in the POST body automatically, which is why you're seeing the error from Modrinth's API ["Parse error: missing field `client_id`"](https://github.com/better-auth/better-auth/blob/2734d07e88f78e4e79f8bb65e909c297c7197a09/packages/better-auth/src/plugins/generic-oauth/index.ts). To support this, the plugin would need a small extension: add a tokenData (or similar) option to the GenericOAuthConfig, and merge its contents into the token request body in the validateAuthorizationCode function. The codebase is modular and this change would be straightforward and backward-compatible. As a workaround, you could fork the plugin and patch in this behavior, or implement a minimal custom OAuth provider that builds the token request body as Modrinth expects. If you want to reference or propose this change, the relevant code is in packages/better-auth/src/plugins/generic-oauth/index.ts, specifically where the token request body is constructed in validateAuthorizationCode. This enhancement would also benefit other providers with non-standard requirements. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/64d3ddad-af05-4a2f-9300-a21460b3de6d?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/64d3ddad-af05-4a2f-9300-a21460b3de6d?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/64d3ddad-af05-4a2f-9300-a21460b3de6d?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/64d3ddad-af05-4a2f-9300-a21460b3de6d?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/64d3ddad-af05-4a2f-9300-a21460b3de6d?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/64d3ddad-af05-4a2f-9300-a21460b3de6d?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/64d3ddad-af05-4a2f-9300-a21460b3de6d?feedback_type=other)</sup>&nbsp;&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/3279)
Author
Owner

@Kinfe123 commented on GitHub (Jul 22, 2025):

already fixed. check on latest release.

@Kinfe123 commented on GitHub (Jul 22, 2025): already fixed. check on latest release.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1468