X (Twitter) refreshAccessToken #965

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

Originally created by @phanmn on GitHub (Apr 3, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

https://devcommunity.x.com/t/trying-to-get-oauth-2-0-token-receiving-missing-valid-authorization-header-error/163633

Current vs. Expected behavior

Current: Error “Missing valid authorization header”

Expected: Work

What version of Better Auth are you using?

1.2.5

Provide environment information

- Macos

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

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: false
  },
socialProviders: {
      twitter: {
        clientId: process.env.TWITTER_CLIENT_ID!,
        clientSecret: process.env.TWITTER_CLIENT_SECRET!,
        scope: ["tweet.read", "tweet.write", "offline.access", "users.read"]
      },
    },
});

Additional context

I have to add authentication: basic to custom refreshAccessToken to make it work

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: false
  },
socialProviders: {
      twitter: {
        clientId: process.env.TWITTER_CLIENT_ID!,
        clientSecret: process.env.TWITTER_CLIENT_SECRET!,
        scope: ["tweet.read", "tweet.write", "offline.access", "users.read"],
        refreshAccessToken: async (refreshToken) => {
          return refreshAccessToken({
            refreshToken,
            options: {
              clientId: process.env.TWITTER_CLIENT_ID!,
              clientSecret: process.env.TWITTER_CLIENT_SECRET!,
            },
            authentication: 'basic',
            tokenEndpoint: "https://api.twitter.com/2/oauth2/token",
          });
        },
      },
    },
});
Originally created by @phanmn on GitHub (Apr 3, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce https://devcommunity.x.com/t/trying-to-get-oauth-2-0-token-receiving-missing-valid-authorization-header-error/163633 ### Current vs. Expected behavior Current: Error “Missing valid authorization header” Expected: Work ### What version of Better Auth are you using? 1.2.5 ### Provide environment information ```bash - Macos ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: false }, socialProviders: { twitter: { clientId: process.env.TWITTER_CLIENT_ID!, clientSecret: process.env.TWITTER_CLIENT_SECRET!, scope: ["tweet.read", "tweet.write", "offline.access", "users.read"] }, }, }); ``` ### Additional context I have to add `authentication: basic` to custom `refreshAccessToken` to make it work ``` import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: false }, socialProviders: { twitter: { clientId: process.env.TWITTER_CLIENT_ID!, clientSecret: process.env.TWITTER_CLIENT_SECRET!, scope: ["tweet.read", "tweet.write", "offline.access", "users.read"], refreshAccessToken: async (refreshToken) => { return refreshAccessToken({ refreshToken, options: { clientId: process.env.TWITTER_CLIENT_ID!, clientSecret: process.env.TWITTER_CLIENT_SECRET!, }, authentication: 'basic', tokenEndpoint: "https://api.twitter.com/2/oauth2/token", }); }, }, }, }); ```
GiteaMirror added the bug label 2026-03-13 08:12:21 -05:00
Author
Owner

@Kinfe123 commented on GitHub (May 5, 2025):

Good catch! since it is a change from their side it does not actually require a change on our end. may be we will try to update the docs if necessary.

@Kinfe123 commented on GitHub (May 5, 2025): Good catch! since it is a change from their side it does not actually require a change on our end. may be we will try to update the docs if necessary.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#965