@@ -42,10 +42,9 @@ test.describe('machine-to-machine auth @machine', () => {
4242
4343 app.get('/api/protected', async (req, res) => {
4444 const token = req.get('Authorization')?.split(' ')[1];
45-
4645 try {
4746 const m2mToken = await clerkClient.m2m.verify({ token });
48- res.send('Protected response ' + m2mToken.id );
47+ res.send('Protected response ' + m2mToken.subject );
4948 } catch {
5049 res.status(401).send('Unauthorized');
5150 }
@@ -150,7 +149,7 @@ test.describe('machine-to-machine auth @machine', () => {
150149 } ,
151150 } ) ;
152151 expect ( res . status ( ) ) . toBe ( 200 ) ;
153- expect ( await res . text ( ) ) . toBe ( 'Protected response ' + emailServerM2MToken . id ) ;
152+ expect ( await res . text ( ) ) . toBe ( 'Protected response ' + emailServer . id ) ;
154153
155154 // Analytics server can access primary API server after adding scope
156155 await u . services . clerk . machines . createScope ( analyticsServer . id , primaryApiServer . id ) ;
@@ -165,9 +164,30 @@ test.describe('machine-to-machine auth @machine', () => {
165164 } ,
166165 } ) ;
167166 expect ( res2 . status ( ) ) . toBe ( 200 ) ;
168- expect ( await res2 . text ( ) ) . toBe ( 'Protected response ' + m2mToken . id ) ;
167+ expect ( await res2 . text ( ) ) . toBe ( 'Protected response ' + analyticsServer . id ) ;
169168 await u . services . clerk . m2m . revokeToken ( {
170169 m2mTokenId : m2mToken . id ,
171170 } ) ;
172171 } ) ;
172+
173+ test ( 'verifies JWT format M2M token via local verification' , async ( { page, context } ) => {
174+ const u = createTestUtils ( { app, page, context } ) ;
175+
176+ const client = createClerkClient ( {
177+ secretKey : instanceKeys . get ( 'with-api-keys' ) . sk ,
178+ } ) ;
179+ const jwtToken = await client . m2m . createToken ( {
180+ machineSecretKey : emailServer . secretKey ,
181+ secondsUntilExpiration : 60 * 30 ,
182+ tokenFormat : 'jwt' ,
183+ } ) ;
184+
185+ const res = await u . page . request . get ( app . serverUrl + '/api/protected' , {
186+ headers : { Authorization : `Bearer ${ jwtToken . token } ` } ,
187+ } ) ;
188+ expect ( res . status ( ) ) . toBe ( 200 ) ;
189+ expect ( await res . text ( ) ) . toBe ( 'Protected response ' + emailServer . id ) ;
190+ // JWT-format tokens are self-contained and not stored in BAPI, so revocation
191+ // is not applicable — they expire naturally via the exp claim.
192+ } ) ;
173193} ) ;
0 commit comments