Skip to content

Commit 4ba09f4

Browse files
committed
fix(sso): default tokenEndpointAuthentication to client_secret_post
better-auth's SSO plugin does not URL-encode credentials before Base64 encoding in client_secret_basic mode (RFC 6749 §2.3.1). When the client secret contains special characters (+, =, /), OIDC providers decode them incorrectly, causing invalid_client errors. Default to client_secret_post when tokenEndpointAuthentication is not explicitly set to avoid this upstream encoding issue. Fixes #3626
1 parent b3d9e54 commit 4ba09f4

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/db/scripts/register-sso-provider.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,11 @@ async function registerSSOProvider(): Promise<boolean> {
507507
clientSecret: ssoConfig.oidcConfig.clientSecret,
508508
authorizationEndpoint: ssoConfig.oidcConfig.authorizationEndpoint,
509509
tokenEndpoint: ssoConfig.oidcConfig.tokenEndpoint,
510-
tokenEndpointAuthentication: ssoConfig.oidcConfig.tokenEndpointAuthentication,
510+
// Default to client_secret_post: better-auth sends client_secret_basic
511+
// credentials without URL-encoding per RFC 6749 §2.3.1, so '+' in secrets
512+
// is decoded as space by OIDC providers, causing invalid_client errors.
513+
tokenEndpointAuthentication:
514+
ssoConfig.oidcConfig.tokenEndpointAuthentication || 'client_secret_post',
511515
jwksEndpoint: ssoConfig.oidcConfig.jwksEndpoint,
512516
pkce: ssoConfig.oidcConfig.pkce,
513517
discoveryEndpoint:

0 commit comments

Comments
 (0)