[PR #3823] [CLOSED] feat: allow token url params in generic oauth to be functions #5026

Closed
opened 2026-03-13 12:08:24 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/3823
Author: @frectonz
Created: 8/6/2025
Status: Closed

Base: canaryHead: feat/allow-token-url-param-functions


📝 Commits (2)

  • 8afdff3 feat: allow token url params in generic oauth to be functions
  • 7ebd00a fix: allow synchronous functions

📊 Changes

2 files changed (+11 additions, -3 deletions)

View changed files

📝 packages/better-auth/src/oauth2/validate-authorization-code.ts (+10 -2)
📝 packages/better-auth/src/plugins/generic-oauth/index.ts (+1 -1)

📄 Description

I ran into problems with while I was integrating with a OAuth server that uses client_assertion OAuth instead of the normal clientId + clientSecret OAuth2 implementation. In client_assertion OAuth, the developer is given a PRIVATE_KEY and they are expected to essentially auto-generate a client secret by signing their clientID and the token endpoint they will call using their private key.

The problem is that the server will expect the newly generated JWT to have an expiration date, so the JWT cannot be generated once and reused; it must be regenerated within some timeframe, but the current tokenUrlParams option in Better Auth only accepts static strings; it doesn't allow the user to set a function this PR implements that feature. So the user can add a function to tokenUrlParams that will auto-generate the JWT.

Before

genericOAuth({
  config: [
    {
      // ....
      tokenUrlParams: {
        client_assertion: await generateSignedJwt(clientId, privateKey),
        client_assertion_type:
          "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
      },
    },
  ],
});

After

genericOAuth({
  config: [
    {
      // ....
      tokenUrlParams: {
        client_assertion: () => await generateSignedJwt(clientId, privateKey),
        client_assertion_type:
          "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
      },
    },
  ],
});

Summary by cubic

Added support for functions in the generic OAuth tokenUrlParams, allowing dynamic values like freshly generated JWTs for client_assertion flows.

  • New Features
    • tokenUrlParams now accepts async functions, enabling on-demand generation of parameters such as client_assertion.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/3823 **Author:** [@frectonz](https://github.com/frectonz) **Created:** 8/6/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `feat/allow-token-url-param-functions` --- ### 📝 Commits (2) - [`8afdff3`](https://github.com/better-auth/better-auth/commit/8afdff39bfc3e110684e7c96eaea98dfc96c7b65) feat: allow token url params in generic oauth to be functions - [`7ebd00a`](https://github.com/better-auth/better-auth/commit/7ebd00a16496be324027da5feb41e34b56fbfe59) fix: allow synchronous functions ### 📊 Changes **2 files changed** (+11 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/oauth2/validate-authorization-code.ts` (+10 -2) 📝 `packages/better-auth/src/plugins/generic-oauth/index.ts` (+1 -1) </details> ### 📄 Description I ran into problems with while I was integrating with a OAuth server that uses `client_assertion` OAuth instead of the normal `clientId` + `clientSecret` OAuth2 implementation. In `client_assertion` OAuth, the developer is given a PRIVATE_KEY and they are expected to essentially auto-generate a client secret by signing their clientID and the token endpoint they will call using their private key. The problem is that the server will expect the newly generated JWT to have an expiration date, so the JWT cannot be generated once and reused; it must be regenerated within some timeframe, but the current `tokenUrlParams` option in Better Auth only accepts static strings; it doesn't allow the user to set a function this PR implements that feature. So the user can add a function to `tokenUrlParams` that will auto-generate the JWT. Before ```typescript genericOAuth({ config: [ { // .... tokenUrlParams: { client_assertion: await generateSignedJwt(clientId, privateKey), client_assertion_type: "urn:ietf:params:oauth:client-assertion-type:jwt-bearer", }, }, ], }); ``` After ```typescript genericOAuth({ config: [ { // .... tokenUrlParams: { client_assertion: () => await generateSignedJwt(clientId, privateKey), client_assertion_type: "urn:ietf:params:oauth:client-assertion-type:jwt-bearer", }, }, ], }); ``` <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Added support for functions in the generic OAuth tokenUrlParams, allowing dynamic values like freshly generated JWTs for client_assertion flows. - **New Features** - tokenUrlParams now accepts async functions, enabling on-demand generation of parameters such as client_assertion. <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 12:08:24 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#5026