@@ -502,7 +502,9 @@ static bool _oauth2_metadata_verify_callback(oauth2_log_t *log,
502502 char * response = NULL ;
503503 json_t * json_metadata = NULL , * json_jwks_uri = NULL ,
504504 * json_introspection_endpoint ;
505- const char * jwks_uri = NULL , * introspection_endpoint = NULL ;
505+ oauth2_jose_jwt_verify_ctx_t * jwks_uri_verify = NULL ;
506+ oauth2_introspect_ctx_t * introspect_ctx = NULL ;
507+ const char * jwks_uri = NULL , * introspection_uri = NULL ;
506508 char * peek = NULL ;
507509
508510 if ((verify == NULL) || (verify -> ctx == NULL) ||
@@ -538,12 +540,14 @@ static bool _oauth2_metadata_verify_callback(oauth2_log_t *log,
538540 oauth2_warn (log , "\"jwks_uri\" value is not a string" );
539541 }
540542 }
541-
542543 if (jwks_uri ) {
544+ // NB: need a copy because we're going to modify a static/shared config setting
545+ jwks_uri_verify =
546+ oauth2_jose_jwt_verify_ctx_clone (log , ptr -> jwks_uri_verify );
543547 oauth2_cfg_endpoint_set_url (
544- ptr -> jwks_uri_verify -> jwks_provider -> jwks_uri -> endpoint ,
548+ jwks_uri_verify -> jwks_provider -> jwks_uri -> endpoint ,
545549 jwks_uri );
546- rc = oauth2_jose_jwt_verify (log , ptr -> jwks_uri_verify , token ,
550+ rc = oauth2_jose_jwt_verify (log , jwks_uri_verify , token ,
547551 json_payload , s_payload );
548552 if (rc == true)
549553 goto end ;
@@ -555,7 +559,7 @@ static bool _oauth2_metadata_verify_callback(oauth2_log_t *log,
555559 json_object_get (json_metadata , "introspection_endpoint" );
556560 if (json_introspection_endpoint ) {
557561 if (json_is_string (json_introspection_endpoint )) {
558- introspection_endpoint =
562+ introspection_uri =
559563 json_string_value (json_introspection_endpoint );
560564 } else {
561565 oauth2_warn (
@@ -564,10 +568,13 @@ static bool _oauth2_metadata_verify_callback(oauth2_log_t *log,
564568 }
565569 }
566570
567- if (introspection_endpoint ) {
568- oauth2_cfg_endpoint_set_url (ptr -> introspect -> endpoint ,
569- introspection_endpoint );
570- rc = _oauth2_introspect_verify (log , ptr -> introspect , token ,
571+ if (introspection_uri ) {
572+ // NB: need a copy because we're going to modify a static/shared config setting
573+ introspect_ctx =
574+ oauth2_introspect_ctx_clone (log , ptr -> introspect );
575+ oauth2_cfg_endpoint_set_url (introspect_ctx -> endpoint ,
576+ introspection_uri );
577+ rc = _oauth2_introspect_verify (log , introspect_ctx , token ,
571578 json_payload , s_payload );
572579 if (rc == true)
573580 goto end ;
@@ -581,6 +588,10 @@ static bool _oauth2_metadata_verify_callback(oauth2_log_t *log,
581588 json_decref (json_metadata );
582589 if (response )
583590 oauth2_mem_free (response );
591+ if (jwks_uri_verify )
592+ oauth2_jose_jwt_verify_ctx_free (log , jwks_uri_verify );
593+ if (introspect_ctx )
594+ oauth2_introspect_ctx_free (log , introspect_ctx );
584595
585596 return rc ;
586597}
0 commit comments