@@ -96,14 +96,14 @@ public function register_routes() {
9696 'callback ' => array ( $ this , 'generate_key_pair ' ),
9797 'permission_callback ' => '__return_true ' ,
9898 'args ' => array (
99- 'name ' => array (
99+ 'name ' => array (
100100 'description ' => esc_html__ ( 'The name of the key-pair. ' , 'jwt-auth ' ),
101101 'type ' => 'string ' ,
102102 'required ' => true ,
103103 'sanitize_callback ' => 'sanitize_text_field ' ,
104104 'validate_callback ' => 'rest_validate_request_arg ' ,
105105 ),
106- 'user_id ' => array (
106+ 'user_id ' => array (
107107 'description ' => esc_html__ ( 'The ID of the user. ' , 'jwt-auth ' ),
108108 'type ' => 'integer ' ,
109109 'required ' => true ,
@@ -120,7 +120,7 @@ public function register_routes() {
120120 'callback ' => array ( $ this , 'delete_all_key_pairs ' ),
121121 'permission_callback ' => '__return_true ' ,
122122 'args ' => array (
123- 'user_id ' => array (
123+ 'user_id ' => array (
124124 'description ' => esc_html__ ( 'The ID of the user. ' , 'jwt-auth ' ),
125125 'type ' => 'integer ' ,
126126 'required ' => true ,
@@ -136,14 +136,14 @@ public function register_routes() {
136136 'callback ' => array ( $ this , 'delete_key_pair ' ),
137137 'permission_callback ' => '__return_true ' ,
138138 'args ' => array (
139- 'user_id ' => array (
139+ 'user_id ' => array (
140140 'description ' => esc_html__ ( 'The ID of the user. ' , 'jwt-auth ' ),
141141 'type ' => 'integer ' ,
142142 'required ' => true ,
143143 'sanitize_callback ' => 'absint ' ,
144144 'validate_callback ' => 'rest_validate_request_arg ' ,
145145 ),
146- 'api_key ' => array (
146+ 'api_key ' => array (
147147 'description ' => esc_html__ ( 'The API key being revoked. ' , 'jwt-auth ' ),
148148 'type ' => 'string ' ,
149149 'required ' => true ,
@@ -359,11 +359,14 @@ public function authenticate( $user, WP_REST_Request $request ) {
359359
360360 $ found = false ;
361361 $ keypairs = $ this ->get_user_key_pairs ( $ get_user ->ID );
362+
363+ // Update the "Last IP" which accessed the keypair. This may not work
364+ // in some environments due to caching.
362365 foreach ( $ keypairs as $ _key => $ item ) {
363366 if ( isset ( $ item ['api_key ' ] ) && $ item ['api_key ' ] === $ key ) {
364367 $ keypairs [ $ _key ]['last_used ' ] = time ();
365368
366- $ ip = isset ( $ _SERVER ['REMOTE_ADDR ' ] ) ? filter_var ( wp_unslash ( $ _SERVER ['REMOTE_ADDR ' ] ), FILTER_VALIDATE_IP ) : null ;
369+ $ ip = isset ( $ _SERVER ['REMOTE_ADDR ' ] ) ? filter_var ( wp_unslash ( $ _SERVER ['REMOTE_ADDR ' ] ), FILTER_VALIDATE_IP ) : null ; // phpcs:ignore WordPressVIPMinimum.Variables.ServerVariables.UserControlledHeaders, WordPressVIPMinimum.Variables.RestrictedVariables.cache_constraints___SERVER__REMOTE_ADDR__
367370 if ( $ ip ) {
368371 $ keypairs [ $ _key ]['last_ip ' ] = $ ip ;
369372 }
@@ -708,6 +711,7 @@ public function template_new_key_pair() {
708711 * @since 0.1
709712 */
710713 public function template_new_token_key_pair () {
714+ // phpcs:disable WordPressVIPMinimum.Security.Mustache.OutputNotation
711715 ?>
712716 <script type="text/html" id="tmpl-new-token-key-pair">
713717 <div class="new-key-pair notification-dialog-wrap" data-api_key="{{ data.api_key }}" data-name="{{ data.name }}">
@@ -764,6 +768,7 @@ public function template_new_token_key_pair() {
764768 </div>
765769 </script>
766770 <?php
771+ // phpcs:enable WordPressVIPMinimum.Security.Mustache.OutputNotation
767772 }
768773
769774 /**
0 commit comments