Skip to content

Commit 1a4e2c4

Browse files
committed
chore(auth): drop comments the 1.7 upgrade made stale and pass the delegated token body directly
1 parent 377162e commit 1a4e2c4

5 files changed

Lines changed: 9 additions & 20 deletions

File tree

‎apps/sim/app/api/auth/oauth2/token/route.ts‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,7 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
8888
delegatedForm.delete('resource')
8989
const response = await withOAuthResourceIssuance(resource, () =>
9090
withOAuthProviderIssuanceCompensation(() =>
91-
betterAuthPOST(
92-
buildDelegatedOAuthRequest(request, {
93-
...parsed.value,
94-
rawBody: delegatedForm.toString(),
95-
})
96-
)
91+
betterAuthPOST(buildDelegatedOAuthRequest(request, delegatedForm.toString()))
9792
)
9893
)
9994
return normalizeDelegatedOAuthTokenResponse(response, parsed.value.credentials.method)

‎apps/sim/lib/auth/oauth-protocol-request.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,24 +231,21 @@ async function readBoundedOAuthBody(request: Request): Promise<OAuthBodyReadResu
231231
}
232232

233233
/**
234-
* Rebuilds the consumed request for Better Auth.
234+
* Rebuilds the consumed request for Better Auth with `body` as its form.
235235
* Client credentials keep the transport the client authenticated with: Better
236236
* Auth form-decodes Basic credentials itself and refuses a client that
237237
* presents them by any method other than the one it registered. A DPoP proof
238238
* is dropped: Sim's resource servers accept only bearer tokens, so a
239239
* DPoP-bound token would be unusable.
240240
*/
241-
export function buildDelegatedOAuthRequest(
242-
request: NextRequest,
243-
parsed: ParsedOAuthForm
244-
): NextRequest {
241+
export function buildDelegatedOAuthRequest(request: NextRequest, body: string): NextRequest {
245242
const headers = new Headers(request.headers)
246243
headers.delete('content-length')
247244
headers.delete('dpop')
248245
return new NextRequest(request.url, {
249246
method: request.method,
250247
headers,
251-
body: parsed.rawBody,
248+
body,
252249
signal: request.signal,
253250
})
254251
}

‎apps/sim/lib/auth/oauth-token-family.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ async function authenticateClient(
151151
return { success: true, value: client }
152152
}
153153

154-
/** Better Auth 1.6 marked public clients with `public`; 1.7 only registers them with `none`. */
154+
/** A client flagged `public` never authenticates with a secret, whatever method it carries. */
155155
if (client.public || !client.clientSecret || !credentials.clientSecret) {
156156
return protocolError('invalid_client', 'Client authentication failed.')
157157
}

‎apps/sim/lib/auth/sso/application/provider-registration.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,9 @@ function failSsoProvider(status: number, message: string, reason?: string): neve
5454
type TokenEndpointAuthMethod = 'client_secret_basic' | 'client_secret_post'
5555

5656
/**
57-
* Prefers client_secret_post over client_secret_basic when an IdP supports both:
58-
* better-auth sends client_secret_basic credentials without URL-encoding per
59-
* RFC 6749 §2.3.1, so a '+' in the client secret is decoded as a space, causing
60-
* invalid_client errors. Matches the same default in register-sso-provider.ts.
57+
* Prefers client_secret_post over client_secret_basic when an IdP supports both, so new
58+
* providers authenticate the way existing ones do. Matches the same default in
59+
* register-sso-provider.ts.
6160
*/
6261
function selectTokenEndpointAuthMethod(
6362
supportedMethods: unknown,

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -597,9 +597,7 @@ async function registerSSOProvider(): Promise<boolean> {
597597
clientSecret: ssoConfig.oidcConfig.clientSecret,
598598
authorizationEndpoint: ssoConfig.oidcConfig.authorizationEndpoint,
599599
tokenEndpoint: ssoConfig.oidcConfig.tokenEndpoint,
600-
// Default to client_secret_post: better-auth sends client_secret_basic
601-
// credentials without URL-encoding per RFC 6749 §2.3.1, so '+' in secrets
602-
// is decoded as space by OIDC providers, causing invalid_client errors.
600+
// Matches the default of providers saved in the app.
603601
tokenEndpointAuthentication:
604602
ssoConfig.oidcConfig.tokenEndpointAuthentication ?? 'client_secret_post',
605603
jwksEndpoint: ssoConfig.oidcConfig.jwksEndpoint,

0 commit comments

Comments
 (0)