@@ -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
7895export 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