Support custom callback for configuring Generic OAuth token url (tokenUrlParams) #2058

Closed
opened 2026-03-13 09:23:28 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @acusti on GitHub (Oct 1, 2025).

Is this suited for github?

  • Yes, this is suited for github

I am trying to integrate with Follow Up Boss via the Generic OAuth plugin. I am currently stuck on an issue with the validateAuthorizationCode step. the FUB docs state that the request must include state (“This is an opaque value provided by the requesting system to prevent CSRF attacks and to maintain the state between requests and callbacks”), which I can see is not provided from validateAuthorizationCode.

I saw that the authorizationUrlParams config option was just updated a few days ago in #4919 to support a callback function form that takes ctx. I believe my issue would be easy to solve via my own config if the same change were made to the tokenUrlParams config option, because I could then do:

    tokenUrlParams: (ctx: GenericEndpointContext) => ({ state: ctx.query.state || ctx.body.state }),

that example is based on the parseState function, which is used with the same ctx before validateAuthorizationCode is invoked and additionalParams: provider.tokenUrlParams, is provided to it.

Describe the solution you'd like

I would like to add support to tokenUrlParams for the same custom callback form that has been added to authorizationUrlParams in #4919, which would allow me to dynamically customize the additional params passed to to the token URL request the way I described above.

Describe alternatives you've considered

The main alternative (I think) would be to create a followupboss plugin that duplicates the generic oauth plugin functionality but that calls validateAuthorizationCode with the state as additionalParams automatically.

Additional context

There is more context in the discord help topic I created for this issue: https://discord.com/channels/1288403910284935179/1422975484534460529

Originally created by @acusti on GitHub (Oct 1, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. I am trying to integrate with Follow Up Boss via the Generic OAuth plugin. I am currently stuck on an issue with the `validateAuthorizationCode` step. the [FUB docs](https://docs.followupboss.com/docs/oauth-authentication-and-authorization#step-3-exchanging-auth_code-for-tokens) state that the request must include `state` (“This is an opaque value provided by the requesting system to prevent CSRF attacks and to maintain the state between requests and callbacks”), which I can see is not provided from [`validateAuthorizationCode`.](https://github.com/better-auth/better-auth/blob/19f39cb400d1b7afe925528bb58bccb8c3f077c3/packages/better-auth/src/oauth2/validate-authorization-code.ts) I saw that the `authorizationUrlParams` config option was just updated a few days ago in #4919 to support a callback function form that takes `ctx`. I believe my issue would be easy to solve via my own config if the same change were made to the `tokenUrlParams` config option, because I could then do: ```ts tokenUrlParams: (ctx: GenericEndpointContext) => ({ state: ctx.query.state || ctx.body.state }), ``` that example is based on the [`parseState` function](https://github.com/better-auth/better-auth/blob/canary/packages/better-auth/src/oauth2/state.ts#L68C16-L68C45), which is [used with the same `ctx`](https://github.com/better-auth/better-auth/blob/19f39cb400d1b7afe925528bb58bccb8c3f077c3/packages/better-auth/src/plugins/generic-oauth/index.ts#L587-L594) before `validateAuthorizationCode` is invoked and `additionalParams: provider.tokenUrlParams,` is provided to it. ### Describe the solution you'd like I would like to add support to `tokenUrlParams` for the same custom callback form that has been added to `authorizationUrlParams` in #4919, which would allow me to dynamically customize the additional params passed to to the token URL request the way I described above. ### Describe alternatives you've considered The main alternative (I think) would be to create a followupboss plugin that duplicates the generic oauth plugin functionality but that calls `validateAuthorizationCode` with the state as `additionalParams` automatically. ### Additional context There is more context in the discord help topic I created for this issue: https://discord.com/channels/1288403910284935179/1422975484534460529
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2058