Skip to content

Commit afe1279

Browse files
committed
rename authToTokenEndpoint -> addClientAuthentication
1 parent 8bae46e commit afe1279

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

src/client/auth.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ describe("OAuth Authorization", () => {
505505
});
506506

507507
it("exchanges code for tokens with auth", async () => {
508-
mockProvider.authToTokenEndpoint = function(url: URL, headers: Headers, params: URLSearchParams) {
508+
mockProvider.addClientAuthentication = function(url: URL, headers: Headers, params: URLSearchParams) {
509509
headers.set("Authorization", "Basic " + btoa(validClientInfo.client_id + ":" + validClientInfo.client_secret));
510510
params.set("example_url", url.toString());
511511
params.set("example_param", "example_value");
@@ -651,7 +651,7 @@ describe("OAuth Authorization", () => {
651651
});
652652

653653
it("exchanges refresh token for new tokens with auth", async () => {
654-
mockProvider.authToTokenEndpoint = function(url: URL, headers: Headers, params: URLSearchParams) {
654+
mockProvider.addClientAuthentication = function(url: URL, headers: Headers, params: URLSearchParams) {
655655
headers.set("Authorization", "Basic " + btoa(validClientInfo.client_id + ":" + validClientInfo.client_secret));
656656
params.set("example_url", url.toString());
657657
params.set("example_param", "example_value");

src/client/auth.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,24 @@ export interface OAuthClientProvider {
7272
*/
7373
codeVerifier(): string | Promise<string>;
7474

75-
authToTokenEndpoint?(url: URL, headers: Headers, params: URLSearchParams): void | Promise<void>;
75+
/**
76+
* Adds custom client authentication to OAuth token requests.
77+
*
78+
* This optional method allows implementations to customize how client credentials
79+
* are included in token exchange and refresh requests. When provided, this method
80+
* is called instead of the default authentication logic, giving full control over
81+
* the authentication mechanism.
82+
*
83+
* Common use cases include:
84+
* - Supporting authentication methods beyond the standard OAuth 2.0 methods
85+
* - Adding custom headers for proprietary authentication schemes
86+
* - Implementing client assertion-based authentication (e.g., JWT bearer tokens)
87+
*
88+
* @param url - The token endpoint URL being called
89+
* @param headers - The request headers (can be modified to add authentication)
90+
* @param params - The request body parameters (can be modified to add credentials)
91+
*/
92+
addClientAuthentication?(url: URL, headers: Headers, params: URLSearchParams): void | Promise<void>;
7693
}
7794

7895
export type AuthResult = "AUTHORIZED" | "REDIRECT";
@@ -538,8 +555,8 @@ export async function exchangeAuthorization(
538555
redirect_uri: String(redirectUri),
539556
});
540557

541-
if (provider?.authToTokenEndpoint) {
542-
provider.authToTokenEndpoint(tokenUrl, headers, params);
558+
if (provider?.addClientAuthentication) {
559+
provider.addClientAuthentication(tokenUrl, headers, params);
543560
} else {
544561
// Determine and apply client authentication method
545562
const supportedMethods = metadata?.token_endpoint_auth_methods_supported ?? [];
@@ -617,8 +634,8 @@ export async function refreshAuthorization(
617634
refresh_token: refreshToken,
618635
});
619636

620-
if (provider?.authToTokenEndpoint) {
621-
provider.authToTokenEndpoint(tokenUrl, headers, params);
637+
if (provider?.addClientAuthentication) {
638+
provider.addClientAuthentication(tokenUrl, headers, params);
622639
} else {
623640
// Determine and apply client authentication method
624641
const supportedMethods = metadata?.token_endpoint_auth_methods_supported ?? [];

0 commit comments

Comments
 (0)