@@ -72,7 +72,24 @@ export interface OAuthClientProvider {
72
72
*/
73
73
codeVerifier ( ) : string | Promise < string > ;
74
74
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 > ;
76
93
}
77
94
78
95
export type AuthResult = "AUTHORIZED" | "REDIRECT" ;
@@ -538,8 +555,8 @@ export async function exchangeAuthorization(
538
555
redirect_uri : String ( redirectUri ) ,
539
556
} ) ;
540
557
541
- if ( provider ?. authToTokenEndpoint ) {
542
- provider . authToTokenEndpoint ( tokenUrl , headers , params ) ;
558
+ if ( provider ?. addClientAuthentication ) {
559
+ provider . addClientAuthentication ( tokenUrl , headers , params ) ;
543
560
} else {
544
561
// Determine and apply client authentication method
545
562
const supportedMethods = metadata ?. token_endpoint_auth_methods_supported ?? [ ] ;
@@ -617,8 +634,8 @@ export async function refreshAuthorization(
617
634
refresh_token : refreshToken ,
618
635
} ) ;
619
636
620
- if ( provider ?. authToTokenEndpoint ) {
621
- provider . authToTokenEndpoint ( tokenUrl , headers , params ) ;
637
+ if ( provider ?. addClientAuthentication ) {
638
+ provider . addClientAuthentication ( tokenUrl , headers , params ) ;
622
639
} else {
623
640
// Determine and apply client authentication method
624
641
const supportedMethods = metadata ?. token_endpoint_auth_methods_supported ?? [ ] ;
0 commit comments