feat(oauth-provider): accept POST on the userinfo endpoint (#9937)

This commit is contained in:
Gustavo Valverde
2026-06-07 21:09:27 -07:00
committed by GitHub
parent d23735b1de
commit fe9600bc07
3 changed files with 21 additions and 1 deletions
@@ -0,0 +1,5 @@
---
"@better-auth/oauth-provider": patch
---
The UserInfo endpoint (`/oauth2/userinfo`) now accepts `POST` with the access token in the `Authorization` header, in addition to `GET`.
+1 -1
View File
@@ -1112,7 +1112,7 @@ export const oauthProvider = <O extends OAuthOptions<Scope[]>>(options: O) => {
oauth2UserInfo: createAuthEndpoint(
"/oauth2/userinfo",
{
method: "GET",
method: ["GET", "POST"],
metadata: {
openapi: {
description:
@@ -198,6 +198,21 @@ describe("oauth userinfo", async () => {
});
});
it("should accept POST with the bearer token in the Authorization header", async () => {
const tokens = await getTokens();
expect(tokens.data?.access_token).toBeDefined();
const userinfo = await client.$fetch<Record<string, string>>(
"/oauth2/userinfo",
{
method: "POST",
headers: {
authorization: `Bearer ${tokens.data?.access_token ?? ""}`,
},
},
);
expect(userinfo.data).toMatchObject({ sub: user.id });
});
/**
* Programmatic callers have no `ctx.request`, so userinfo must resolve the
* bearer token from `ctx.headers` for both transports.