[GH-ISSUE #4125] oauth2 basic auth-header #18468

Closed
opened 2026-04-15 16:55:34 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @CodeWithAlexander on GitHub (Aug 21, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/4125

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Send a refresh token request a Generic OAuth provider.
  2. Observe the error: invalid-authorization-header.

Current vs. Expected behavior

Currently when I try to refresh the OAuth token I am getting invalid headers as a response, note this wasn't happening on older versions of better-auth.
not sure why the authentication scheme was removed from the headers

What version of Better Auth are you using?

1.3.4

System info

System:
    OS: Windows 11 10.0.26100
    CPU: (16) x64 AMD Ryzen 7 5700U with Radeon Graphics
    Memory: 2.23 GB / 15.33 GB
  Browsers:
    Edge: Chromium (139.0.3405.102)
    Internet Explorer: 11.0.26100.1882

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

Package, Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
});

Additional context

No response

Originally created by @CodeWithAlexander on GitHub (Aug 21, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/4125 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Send a refresh token request a Generic OAuth provider. 2. Observe the error: invalid-authorization-header. ### Current vs. Expected behavior Currently when I try to refresh the OAuth token I am getting invalid headers as a response, note this wasn't happening on older versions of better-auth. not sure why the authentication scheme was removed from the headers ### What version of Better Auth are you using? 1.3.4 ### System info ```bash System: OS: Windows 11 10.0.26100 CPU: (16) x64 AMD Ryzen 7 5700U with Radeon Graphics Memory: 2.23 GB / 15.33 GB Browsers: Edge: Chromium (139.0.3405.102) Internet Explorer: 11.0.26100.1882 ``` ### Which area(s) are affected? (Select all that apply) Package, Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context _No response_
GiteaMirror added the locked label 2026-04-15 16:55:34 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 21, 2025):

Hi @CodeWithAlexander! I'm Dosu and I’m helping the better-auth team.

This is a regression in Better Auth v1.3.4: the refresh token request's Authorization header is missing the required Basic prefix, which most OAuth2 providers (including GitHub) expect. The code currently sets the header to just the base64-encoded credentials, but omits the prefix, causing the invalid-authorization-header error you’re seeing [source].

Workaround:
If you can patch your local install, update the refreshAccessToken function in packages/better-auth/src/oauth2/refresh-access-token.ts so that when using "basic" authentication, it sets the header like this:

headers["authorization"] = "Basic " + base64.encode(`${options.clientId}:${options.clientSecret ?? ""}`);

This matches the correct behavior (and what the code does for the authorization code flow). Until an official fix lands, this patch will restore compatibility with providers expecting the standard OAuth2 header format [source].

No config change will fix this; it requires the code patch above.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

<!-- gh-comment-id:3211025172 --> @dosubot[bot] commented on GitHub (Aug 21, 2025): <!-- Greeting --> Hi @CodeWithAlexander! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This is a regression in Better Auth v1.3.4: the refresh token request's Authorization header is missing the required `Basic ` prefix, which most OAuth2 providers (including GitHub) expect. The code currently sets the header to just the base64-encoded credentials, but omits the prefix, causing the `invalid-authorization-header` error you’re seeing [[source](https://github.com/better-auth/better-auth/pull/3824)]. **Workaround:** If you can patch your local install, update the `refreshAccessToken` function in `packages/better-auth/src/oauth2/refresh-access-token.ts` so that when using `"basic"` authentication, it sets the header like this: ```ts headers["authorization"] = "Basic " + base64.encode(`${options.clientId}:${options.clientSecret ?? ""}`); ``` This matches the correct behavior (and what the code does for the authorization code flow). Until an official fix lands, this patch will restore compatibility with providers expecting the standard OAuth2 header format [[source](https://github.com/better-auth/better-auth/pull/3846)]. No config change will fix this; it requires the code patch above. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/05c61e69-ba27-4f60-a4c4-4f1e06839c7e?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/05c61e69-ba27-4f60-a4c4-4f1e06839c7e?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/05c61e69-ba27-4f60-a4c4-4f1e06839c7e?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/05c61e69-ba27-4f60-a4c4-4f1e06839c7e?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/05c61e69-ba27-4f60-a4c4-4f1e06839c7e?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/05c61e69-ba27-4f60-a4c4-4f1e06839c7e?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/05c61e69-ba27-4f60-a4c4-4f1e06839c7e?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/4125)
Author
Owner

@himself65 commented on GitHub (Aug 21, 2025):

Can you show the minimal reproducing code? how did you send the reqeust to the backend?

<!-- gh-comment-id:3211065605 --> @himself65 commented on GitHub (Aug 21, 2025): Can you show the minimal reproducing code? how did you send the reqeust to the backend?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#18468