@@ -188,12 +188,6 @@ main(int argc, // I - Number of command-line arguments
188188 }
189189 else if (!strcmp (command , "get-user-id" ))
190190 {
191- if (i >= argc )
192- {
193- fputs ("testoauth: Missing resource URI.\n" , stderr );
194- return (usage (stderr ));
195- }
196-
197191 return (get_user_id (oauth_uri , argv [i ]));
198192 }
199193 else if (!strcmp (command , "set-client-data" ))
@@ -319,10 +313,52 @@ static int // O - Exit status
319313get_user_id (const char * oauth_uri , // I - Authorization Server URI
320314 const char * resource_uri ) // I - Resource URI
321315{
322- (void )oauth_uri ;
323- (void )resource_uri ;
316+ cups_jwt_t * user_id ; // User ID information
324317
325- return (1 );
318+
319+ if ((user_id = cupsOAuthCopyUserId (oauth_uri , resource_uri )) != NULL )
320+ {
321+ const char * aud = cupsJWTGetClaimString (user_id , CUPS_JWT_AUD );
322+ // Audience
323+ const char * iss = cupsJWTGetClaimString (user_id , CUPS_JWT_ISS );
324+ // Issuer
325+ const char * jti = cupsJWTGetClaimString (user_id , CUPS_JWT_JTI );
326+ // JWT ID
327+ const char * name = cupsJWTGetClaimString (user_id , CUPS_JWT_NAME );
328+ // Display name
329+ const char * sub = cupsJWTGetClaimString (user_id , CUPS_JWT_SUB );
330+ // Subject (username/ID)
331+ double iat = cupsJWTGetClaimNumber (user_id , CUPS_JWT_IAT );
332+ // Issue time
333+ double exp = cupsJWTGetClaimNumber (user_id , CUPS_JWT_EXP );
334+ // Expiration time
335+ double nbf = cupsJWTGetClaimNumber (user_id , CUPS_JWT_NBF );
336+ // Not before time
337+ char date [256 ]; // Date
338+
339+ if (iss )
340+ printf ("Issuer: %s\n" , iss );
341+ if (name )
342+ printf ("Display Name: %s\n" , name );
343+ if (sub )
344+ printf ("Subject: %s\n" , sub );
345+ if (aud )
346+ printf ("Audience: %s\n" , aud );
347+ if (jti )
348+ printf ("JWT ID: %s\n" , jti );
349+ if (iat > 0.0 )
350+ printf ("Issued On: %s\n" , httpGetDateString ((time_t )iat , date , sizeof (date )));
351+ if (exp > 0.0 )
352+ printf ("Expires On: %s\n" , httpGetDateString ((time_t )exp , date , sizeof (date )));
353+ if (nbf > 0.0 )
354+ printf ("Not Before: %s\n" , httpGetDateString ((time_t )nbf , date , sizeof (date )));
355+
356+ return (0 );
357+ }
358+ else
359+ {
360+ return (1 );
361+ }
326362}
327363
328364
@@ -411,8 +447,17 @@ unit_tests(const char *oauth_uri, // I - Authorization Server URI
411447 testBegin ("cupsOAuthCopyUserId(%s)" , oauth_uri );
412448 if ((user_id = cupsOAuthCopyUserId (oauth_uri , /*resource_uri*/ NULL )) != NULL )
413449 {
414- testEnd (true);
415- // TODO: Show user ID
450+ const char * iss = cupsJWTGetClaimString (user_id , CUPS_JWT_ISS );
451+ // Issuer
452+ const char * name = cupsJWTGetClaimString (user_id , CUPS_JWT_NAME );
453+ // Display name
454+ const char * sub = cupsJWTGetClaimString (user_id , CUPS_JWT_SUB );
455+ // Subject (username/ID)
456+ double exp = cupsJWTGetClaimNumber (user_id , CUPS_JWT_EXP );
457+ // Expiration time
458+ char expdate [256 ]; // Expiration date
459+
460+ testEndMessage (true, "iss=\"%s\", name=\"%s\", sub=\"%s\", exp=%s" , iss , name , sub , httpGetDateString ((time_t )exp , expdate , sizeof (expdate )));
416461 }
417462 else
418463 {
0 commit comments