@@ -31,14 +31,22 @@ export type ClientRegistrationHandlerOptions = {
3131 * Registration endpoints are particularly sensitive to abuse and should be rate limited.
3232 */
3333 rateLimit ?: Partial < RateLimitOptions > | false ;
34+
35+ /**
36+ * Whether to generate a client ID before calling the client registration endpoint.
37+ *
38+ * If not set, defaults to true.
39+ */
40+ clientIdGeneration ?: boolean ;
3441} ;
3542
3643const DEFAULT_CLIENT_SECRET_EXPIRY_SECONDS = 30 * 24 * 60 * 60 ; // 30 days
3744
3845export function clientRegistrationHandler ( {
3946 clientsStore,
4047 clientSecretExpirySeconds = DEFAULT_CLIENT_SECRET_EXPIRY_SECONDS ,
41- rateLimit : rateLimitConfig
48+ rateLimit : rateLimitConfig ,
49+ clientIdGeneration = true ,
4250} : ClientRegistrationHandlerOptions ) : RequestHandler {
4351 if ( ! clientsStore . registerClient ) {
4452 throw new Error ( "Client registration store does not support registering clients" ) ;
@@ -78,7 +86,6 @@ export function clientRegistrationHandler({
7886 const isPublicClient = clientMetadata . token_endpoint_auth_method === 'none'
7987
8088 // Generate client credentials
81- const clientId = crypto . randomUUID ( ) ;
8289 const clientSecret = isPublicClient
8390 ? undefined
8491 : crypto . randomBytes ( 32 ) . toString ( 'hex' ) ;
@@ -89,14 +96,17 @@ export function clientRegistrationHandler({
8996 const secretExpiryTime = clientsDoExpire ? clientIdIssuedAt + clientSecretExpirySeconds : 0
9097 const clientSecretExpiresAt = isPublicClient ? undefined : secretExpiryTime
9198
92- let clientInfo : OAuthClientInformationFull = {
99+ let clientInfo : Omit < OAuthClientInformationFull , "client_id" > & { client_id ?: string } = {
93100 ...clientMetadata ,
94- client_id : clientId ,
95101 client_secret : clientSecret ,
96102 client_id_issued_at : clientIdIssuedAt ,
97103 client_secret_expires_at : clientSecretExpiresAt ,
98104 } ;
99105
106+ if ( clientIdGeneration ) {
107+ clientInfo . client_id = crypto . randomUUID ( ) ;
108+ }
109+
100110 clientInfo = await clientsStore . registerClient ! ( clientInfo ) ;
101111 res . status ( 201 ) . json ( clientInfo ) ;
102112 } catch ( error ) {
0 commit comments