Skip to content

Commit b797e9c

Browse files
jaredhansonochafik
authored andcommitted
Update addClientAuthentication tests for metadata.
1 parent 0bd770b commit b797e9c

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/client/auth.test.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
auth,
1212
type OAuthClientProvider,
1313
} from "./auth.js";
14+
import { OAuthMetadata } from 'src/shared/auth.js';
1415

1516
// Mock fetch globally
1617
const mockFetch = jest.fn();
@@ -588,6 +589,13 @@ describe("OAuth Authorization", () => {
588589
refresh_token: "refresh123",
589590
};
590591

592+
const validMetadata = {
593+
issuer: "https://auth.example.com",
594+
authorization_endpoint: "https://auth.example.com/authorize",
595+
token_endpoint: "https://auth.example.com/token",
596+
response_types_supported: ["code"]
597+
};
598+
591599
const validClientInfo = {
592600
client_id: "client123",
593601
client_secret: "secret123",
@@ -641,13 +649,15 @@ describe("OAuth Authorization", () => {
641649
});
642650

643651
const tokens = await exchangeAuthorization("https://auth.example.com", {
652+
metadata: validMetadata,
644653
clientInformation: validClientInfo,
645654
authorizationCode: "code123",
646655
codeVerifier: "verifier123",
647656
redirectUri: "http://localhost:3000/callback",
648-
addClientAuthentication: (headers: Headers, params: URLSearchParams, url: string | URL) => {
657+
addClientAuthentication: (headers: Headers, params: URLSearchParams, url: string | URL, metadata: OAuthMetadata) => {
649658
headers.set("Authorization", "Basic " + btoa(validClientInfo.client_id + ":" + validClientInfo.client_secret));
650659
params.set("example_url", typeof url === 'string' ? url : url.toString());
660+
params.set("example_metadata", metadata.authorization_endpoint);
651661
params.set("example_param", "example_value");
652662
},
653663
});
@@ -672,6 +682,7 @@ describe("OAuth Authorization", () => {
672682
expect(body.get("client_id")).toBeNull();
673683
expect(body.get("redirect_uri")).toBe("http://localhost:3000/callback");
674684
expect(body.get("example_url")).toBe("https://auth.example.com");
685+
expect(body.get("example_metadata")).toBe("https://auth.example.com/authorize");
675686
expect(body.get("example_param")).toBe("example_value");
676687
expect(body.get("client_secret")).toBeNull();
677688
});
@@ -724,6 +735,13 @@ describe("OAuth Authorization", () => {
724735
refresh_token: "newrefresh123",
725736
};
726737

738+
const validMetadata = {
739+
issuer: "https://auth.example.com",
740+
authorization_endpoint: "https://auth.example.com/authorize",
741+
token_endpoint: "https://auth.example.com/token",
742+
response_types_supported: ["code"]
743+
};
744+
727745
const validClientInfo = {
728746
client_id: "client123",
729747
client_secret: "secret123",
@@ -773,11 +791,13 @@ describe("OAuth Authorization", () => {
773791
});
774792

775793
const tokens = await refreshAuthorization("https://auth.example.com", {
794+
metadata: validMetadata,
776795
clientInformation: validClientInfo,
777796
refreshToken: "refresh123",
778-
addClientAuthentication: (headers: Headers, params: URLSearchParams, url: string | URL) => {
797+
addClientAuthentication: (headers: Headers, params: URLSearchParams, url: string | URL, metadata: OAuthMetadata) => {
779798
headers.set("Authorization", "Basic " + btoa(validClientInfo.client_id + ":" + validClientInfo.client_secret));
780799
params.set("example_url", typeof url === 'string' ? url : url.toString());
800+
params.set("example_metadata", metadata.authorization_endpoint);
781801
params.set("example_param", "example_value");
782802
},
783803
});
@@ -800,6 +820,7 @@ describe("OAuth Authorization", () => {
800820
expect(body.get("refresh_token")).toBe("refresh123");
801821
expect(body.get("client_id")).toBeNull();
802822
expect(body.get("example_url")).toBe("https://auth.example.com");
823+
expect(body.get("example_metadata")).toBe("https://auth.example.com/authorize");
803824
expect(body.get("example_param")).toBe("example_value");
804825
expect(body.get("client_secret")).toBeNull();
805826
});

0 commit comments

Comments
 (0)