getAccessToken API does not work with generic OAuth plugin #1282

Closed
opened 2026-03-13 08:31:14 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @dkokotov on GitHub (May 29, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Configure better-auth with Generic OAuth plugin (in my case for use with Auth0)
  2. try to use getAccessToken to retrieve the access token after successful login:
auth.api.getAccessToken({
        body: {
            providerId: 'auth0' // provider id used in the generic oauth plugin
        },
        headers: await headers()
    });

Current vs. Expected behavior

I expected to be able to retrieve the token, instead I got the error:

[APIError: Provider auth0 is not supported.] {
  status: 'BAD_REQUEST',
  body: {
    code: 'PROVIDER_AUTH0_IS_NOT_SUPPORTED',
    message: 'Provider auth0 is not supported.'
  },
  headers: {},
  statusCode: 400,
  digest: '1657267731'
}

What version of Better Auth are you using?

1.2.9-beta1

Provide environment information

- MacOS
- Safari

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)

export const auth = betterAuth({
    database: pool,
    baseURL: '***',
    plugins: [
        mcp({
            loginPage: '/login'
        }),
        genericOAuth({
            config: [
                {
                    providerId: 'auth0',
                    clientId: '***',
                    clientSecret: '***',
                    discoveryUrl: '***',
                    authentication: 'post',
                    pkce: true,
                    accessType: 'offline',
                    authorizationUrlParams: {
                        audience: '***'
                    }
                }
            ]
        })
    ]
});

Additional context

I suspect the reason might be this line: https://github.com/better-auth/better-auth/blob/main/packages/better-auth/src/api/routes/account.ts#L324

It looks like it checks that the providerId exists in the list of socialProviders, which would not be the case for a provider from generic oauth plugin. there is also some similar logic later in the function.

As broad context, I am building remote MCP server for which I'd like to support OAuth authorization. We use Auth0 for auth/authz. For our primary Next.js SaaS app, we use the official @auth0/nextjs-auth0 library. But it seemed like better-auth with MCP plugin could be a quick way to implement the MCP server (in a separate Next.js app), so I've been working on that path, and mostly got it working, but ran into this issue (I was trying to use the access token from Auth0 to call our backend as part of the implementation of the MCP tools).

Originally created by @dkokotov on GitHub (May 29, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Configure better-auth with Generic OAuth plugin (in my case for use with Auth0) 2. try to use `getAccessToken` to retrieve the access token after successful login: ``` auth.api.getAccessToken({ body: { providerId: 'auth0' // provider id used in the generic oauth plugin }, headers: await headers() }); ``` ### Current vs. Expected behavior I expected to be able to retrieve the token, instead I got the error: ``` [APIError: Provider auth0 is not supported.] { status: 'BAD_REQUEST', body: { code: 'PROVIDER_AUTH0_IS_NOT_SUPPORTED', message: 'Provider auth0 is not supported.' }, headers: {}, statusCode: 400, digest: '1657267731' } ``` ### What version of Better Auth are you using? 1.2.9-beta1 ### Provide environment information ```bash - MacOS - Safari ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript export const auth = betterAuth({ database: pool, baseURL: '***', plugins: [ mcp({ loginPage: '/login' }), genericOAuth({ config: [ { providerId: 'auth0', clientId: '***', clientSecret: '***', discoveryUrl: '***', authentication: 'post', pkce: true, accessType: 'offline', authorizationUrlParams: { audience: '***' } } ] }) ] }); ``` ### Additional context I suspect the reason might be this line: https://github.com/better-auth/better-auth/blob/main/packages/better-auth/src/api/routes/account.ts#L324 It looks like it checks that the providerId exists in the list of socialProviders, which would not be the case for a provider from generic oauth plugin. there is also some similar logic later in the function. As broad context, I am building remote MCP server for which I'd like to support OAuth authorization. We use Auth0 for auth/authz. For our primary Next.js SaaS app, we use the official `@auth0/nextjs-auth0` library. But it seemed like better-auth with MCP plugin could be a quick way to implement the MCP server (in a separate Next.js app), so I've been working on that path, and mostly got it working, but ran into this issue (I was trying to use the access token from Auth0 to call our backend as part of the implementation of the MCP tools).
Author
Owner

@dkokotov commented on GitHub (May 29, 2025):

Actually from looking further into it, it looks like this has already been addressed in https://github.com/better-auth/better-auth/pull/2643 but this was not included in the 1.2.9-beta1 version which is the latest in NPM.

Closing the issue but it would be great if there was another NPM release soon which included this fix. It looks like there is a 1.2.9-beta[2-5] tags, but no corresponding NPM releases

@dkokotov commented on GitHub (May 29, 2025): Actually from looking further into it, it looks like this has already been addressed in https://github.com/better-auth/better-auth/pull/2643 but this was not included in the 1.2.9-beta1 version which is the latest in NPM. Closing the issue but it would be great if there was another NPM release soon which included this fix. It looks like there is a 1.2.9-beta[2-5] tags, but no corresponding NPM releases
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1282