OAuth utilities separate from accounts #2868

Open
opened 2026-03-13 10:24:42 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @isaacwasserman on GitHub (Feb 13, 2026).

Is this suited for github?

  • Yes, this is suited for github

Better Auth has made integrating with different authentication providers through OAuth and OIDC so easy, but it remains difficult to maintain 3rd party OAuth tokens for non-authentication-related scopes.

For example, I want my app to integrate with users' Jira accounts via OAuth to allow management of issues. I don't necessarily need them to be able to sign-in to my app with this service. While additional scopes can be requested using Better Auth, there doesn't seem to be any easy way to request these tokens, auto refresh, etc. for non-user-authentication purposes (like arbitrary API interaction).

Describe the solution you'd like

I wish there was a Better Auth plugin that allowed me to provide a typical issuer, client_id, and client_secret for an arbitrary OAuth provider and request tokens using an interface like:

/* start frontend */
// 1. Direct user to oauth flow from frontend
const { data: { success } } = authClient.oAuth.acquireAccessToken({
  providerId,
  scopes,
  association: {
    userId // or organizationId
  }
})
/* end frontend */

/* start backend */
// 2. After callback, Better Auth saves access and refresh tokens to proper db record based on association parameters (e.g. saves it to users.oauthTokens[providerId][scopes])

// 3. Backend service requests token. Automatically refreshing it if expired.
const { data: { accessToken } } = auth.oAuth.retrieveAccessToken({
  providerId,
  scopes,
  association: {
    userId // or organizationId
  }
})

// 4. Backend service uses access token to query/mutate resources via 3rd party API
/* end backend */

Describe alternatives you've considered

There's always the option of doing this manually for each provider or trying to develop my own standard interface, but it's a pain, and Better Auth already does most of this so well. The process is mostly the same for each provider, but there are caveats that make a home-grown solution more brittle.

Additional context

No response

Originally created by @isaacwasserman on GitHub (Feb 13, 2026). ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. Better Auth has made integrating with different authentication providers through OAuth and OIDC so easy, but it remains difficult to maintain 3rd party OAuth tokens for non-authentication-related scopes. For example, I want my app to integrate with users' Jira accounts via OAuth to allow management of issues. I don't necessarily need them to be able to sign-in to my app with this service. While additional scopes can be requested using Better Auth, there doesn't seem to be any easy way to request these tokens, auto refresh, etc. for non-user-authentication purposes (like arbitrary API interaction). ### Describe the solution you'd like I wish there was a Better Auth plugin that allowed me to provide a typical issuer, client_id, and client_secret for an arbitrary OAuth provider and request tokens using an interface like: ```typescript /* start frontend */ // 1. Direct user to oauth flow from frontend const { data: { success } } = authClient.oAuth.acquireAccessToken({ providerId, scopes, association: { userId // or organizationId } }) /* end frontend */ /* start backend */ // 2. After callback, Better Auth saves access and refresh tokens to proper db record based on association parameters (e.g. saves it to users.oauthTokens[providerId][scopes]) // 3. Backend service requests token. Automatically refreshing it if expired. const { data: { accessToken } } = auth.oAuth.retrieveAccessToken({ providerId, scopes, association: { userId // or organizationId } }) // 4. Backend service uses access token to query/mutate resources via 3rd party API /* end backend */ ``` ### Describe alternatives you've considered There's always the option of doing this manually for each provider or trying to develop my own standard interface, but it's a pain, and Better Auth already does most of this so well. The process is mostly the same for each provider, but there are caveats that make a home-grown solution more brittle. ### Additional context _No response_
GiteaMirror added the enhancement label 2026-03-13 10:24:42 -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#2868