mirror of
https://github.com/better-auth/better-auth.git
synced 2026-07-20 00:33:45 -05:00
feat(oauth-provider): accept POST on the userinfo endpoint (#9937)
This commit is contained in:
@@ -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`.
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user