Adding invalidateCredentials() to OAuthClientProvider (#570)

Co-authored-by: Paul Carleton <paulc@anthropic.com>
This commit is contained in:
Glen Maddern 2025-07-15 02:11:52 +10:00 • committed by GitHub
commit 4b2ad0385d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -10,6 +10,7 @@ import {
auth,
type OAuthClientProvider,
} from "./auth.js";
import {ServerError} from "../server/auth/errors.js";
import { OAuthMetadata } from '../shared/auth.js';
// Mock fetch globally
@ -596,10 +597,7 @@ describe("OAuth Authorization", () => {
});
it("throws on non-404 errors", async () => {
mockFetch.mockResolvedValueOnce({
ok: false,
status: 500,
});
mockFetch.mockResolvedValueOnce(new Response(null, { status: 500 }));
await expect(
discoverOAuthMetadata("https://auth.example.com")
@ -607,14 +605,15 @@ describe("OAuth Authorization", () => {
});
it("validates metadata schema", async () => {
mockFetch.mockResolvedValueOnce({
ok: true,
status: 200,
json: async () => ({
// Missing required fields
issuer: "https://auth.example.com",
}),
});
mockFetch.mockResolvedValueOnce(
Response.json(
{
// Missing required fields
issuer: "https://auth.example.com",
},
{ status: 200 }
)
);
await expect(
discoverOAuthMetadata("https://auth.example.com")
@ -902,10 +901,12 @@ describe("OAuth Authorization", () => {
});
it("throws on error response", async () => {
mockFetch.mockResolvedValueOnce({
ok: false,
status: 400,
});
mockFetch.mockResolvedValueOnce(
Response.json(
new ServerError("Token exchange failed").toResponseObject(),
{ status: 400 }
)
);
await expect(
exchangeAuthorization("https://auth.example.com", {
@ -1054,10 +1055,12 @@ describe("OAuth Authorization", () => {
});
it("throws on error response", async () => {
mockFetch.mockResolvedValueOnce({
ok: false,
status: 400,
});
mockFetch.mockResolvedValueOnce(
Response.json(
new ServerError("Token refresh failed").toResponseObject(),
{ status: 400 }
)
);
await expect(
refreshAuthorization("https://auth.example.com", {
@ -1142,10 +1145,12 @@ describe("OAuth Authorization", () => {
});
it("throws on error response", async () => {
mockFetch.mockResolvedValueOnce({
ok: false,
status: 400,
});
mockFetch.mockResolvedValueOnce(
Response.json(
new ServerError("Dynamic client registration failed").toResponseObject(),
{ status: 400 }
)
);
await expect(
registerClient("https://auth.example.com", {