Skip to content

Commit 1d60de9

Browse files
committed
wip
1 parent 9a54df7 commit 1d60de9

File tree

9 files changed

+25
-5
lines changed

9 files changed

+25
-5
lines changed

packages/backend/src/constants.ts

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const Cookies = {
2121
Handshake: '__clerk_handshake',
2222
DevBrowser: '__clerk_db_jwt',
2323
RedirectCount: '__clerk_redirect_count',
24+
HandshakeFormat: '__clerk_handshake_format',
2425
HandshakeNonce: '__clerk_handshake_nonce',
2526
} as const;
2627

@@ -34,6 +35,7 @@ const QueryParameters = {
3435
HandshakeHelp: '__clerk_help',
3536
LegacyDevBrowser: '__dev_session',
3637
HandshakeReason: '__clerk_hs_reason',
38+
HandshakeFormat: Cookies.HandshakeFormat,
3739
HandshakeNonce: Cookies.HandshakeNonce,
3840
} as const;
3941

packages/backend/src/tokens/authenticateContext.ts

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ interface AuthenticateContext extends AuthenticateRequestOptions {
2525
clientUat: number;
2626
// handshake-related values
2727
devBrowserToken: string | undefined;
28+
handshakeFormat: 'nonce' | 'token' | undefined;
2829
handshakeNonce: string | undefined;
2930
handshakeToken: string | undefined;
3031
handshakeRedirectLoopCounter: number;

packages/backend/src/tokens/handshake.ts

+5
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ export class HandshakeService {
146146
);
147147
url.searchParams.append(constants.QueryParameters.HandshakeReason, reason);
148148

149+
// Include handshakeFormat preference if specified
150+
if (this.authenticateContext.handshakeFormat) {
151+
url.searchParams.append(constants.QueryParameters.HandshakeFormat, this.authenticateContext.handshakeFormat);
152+
}
153+
149154
if (this.authenticateContext.instanceType === 'development' && this.authenticateContext.devBrowserToken) {
150155
url.searchParams.append(constants.QueryParameters.DevBrowser, this.authenticateContext.devBrowserToken);
151156
}

packages/backend/src/tokens/types.ts

+8
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ export type AuthenticateRequestOptions = {
4545
* If the activation can't be performed, either because an organization doesn't exist or the user lacks access, the active organization in the session won't be changed. Ultimately, it's the responsibility of the page to verify that the resources are appropriate to render given the URL and handle mismatches appropriately (e.g., by returning a 404).
4646
*/
4747
organizationSyncOptions?: OrganizationSyncOptions;
48+
/**
49+
* Specifies the handshake format to be used during OAuth authentication flows.
50+
* When set to 'nonce', the backend signals to the frontend that it can handle nonce-based handshakes
51+
* during OAuth flow resolution, which is more secure for certain environments.
52+
*
53+
* @default 'token'
54+
*/
55+
handshakeFormat?: 'nonce' | 'token';
4856
/**
4957
* @internal
5058
*/

packages/clerk-js/src/core/resources/SignIn.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export class SignIn extends BaseResource implements SignInResource {
230230
params: AuthenticateWithRedirectParams,
231231
navigateCallback: (url: URL | string) => void,
232232
): Promise<void> => {
233-
const { strategy, redirectUrl, redirectUrlComplete, identifier, handshakeFormat } = params || {};
233+
const { strategy, redirectUrl, redirectUrlComplete, identifier } = params || {};
234234

235235
const { firstFactorVerification } =
236236
(strategy === 'saml' || strategy === 'enterprise_sso') && this.id

packages/express/src/authenticateRequest.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { incomingMessageToRequest, loadApiEnv, loadClientEnv } from './utils';
1212

1313
export const authenticateRequest = (opts: AuthenticateRequestParams) => {
1414
const { clerkClient, request, options } = opts;
15-
const { jwtKey, authorizedParties, audience } = options || {};
15+
const { jwtKey, authorizedParties, audience, handshakeFormat } = options || {};
1616

1717
const clerkRequest = createClerkRequest(incomingMessageToRequest(request));
1818
const env = { ...loadApiEnv(), ...loadClientEnv() };
@@ -46,6 +46,7 @@ export const authenticateRequest = (opts: AuthenticateRequestParams) => {
4646
isSatellite,
4747
domain,
4848
signInUrl,
49+
handshakeFormat,
4950
});
5051
};
5152

packages/react-router/src/ssr/authenticateRequest.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export async function authenticateRequest(
1111
opts: AuthenticateRequestOptions,
1212
): Promise<SignedInState | SignedOutState> {
1313
const { request } = args;
14-
const { audience, authorizedParties } = opts;
14+
const { audience, authorizedParties, handshakeFormat } = opts;
1515

1616
const { apiUrl, secretKey, jwtKey, proxyUrl, isSatellite, domain, publishableKey } = opts;
1717
const { signInUrl, #Url, afterSignInUrl, after#Url } = opts;
@@ -32,6 +32,7 @@ export async function authenticateRequest(
3232
#Url,
3333
afterSignInUrl,
3434
after#Url,
35+
handshakeFormat,
3536
});
3637

3738
const locationHeader = requestState.headers.get(constants.Headers.Location);

packages/remix/src/ssr/authenticateRequest.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export async function authenticateRequest(
1111
opts: AuthenticateRequestOptions,
1212
): Promise<SignedInState | SignedOutState> {
1313
const { request } = args;
14-
const { audience, authorizedParties } = opts;
14+
const { audience, authorizedParties, handshakeFormat } = opts;
1515

1616
const { apiUrl, secretKey, jwtKey, proxyUrl, isSatellite, domain, publishableKey } = opts;
1717
const { signInUrl, #Url, afterSignInUrl, after#Url } = opts;
@@ -32,6 +32,7 @@ export async function authenticateRequest(
3232
#Url,
3333
afterSignInUrl,
3434
after#Url,
35+
handshakeFormat,
3536
});
3637

3738
const locationHeader = requestState.headers.get(constants.Headers.Location);

packages/tanstack-react-start/src/server/authenticateRequest.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export async function authenticateRequest(
1010
request: Request,
1111
opts: AuthenticateRequestOptions,
1212
): Promise<SignedInState | SignedOutState> {
13-
const { audience, authorizedParties } = opts;
13+
const { audience, authorizedParties, handshakeFormat } = opts;
1414

1515
const { apiUrl, secretKey, jwtKey, proxyUrl, isSatellite, domain, publishableKey } = opts;
1616
const { signInUrl, #Url, afterSignInUrl, after#Url } = opts;
@@ -31,6 +31,7 @@ export async function authenticateRequest(
3131
#Url,
3232
afterSignInUrl,
3333
after#Url,
34+
handshakeFormat,
3435
});
3536

3637
const locationHeader = requestState.headers.get(constants.Headers.Location);

0 commit comments

Comments
 (0)