@@ -96,14 +96,14 @@ public function register_routes() {
96
96
'callback ' => array ( $ this , 'generate_key_pair ' ),
97
97
'permission_callback ' => '__return_true ' ,
98
98
'args ' => array (
99
- 'name ' => array (
99
+ 'name ' => array (
100
100
'description ' => esc_html__ ( 'The name of the key-pair. ' , 'jwt-auth ' ),
101
101
'type ' => 'string ' ,
102
102
'required ' => true ,
103
103
'sanitize_callback ' => 'sanitize_text_field ' ,
104
104
'validate_callback ' => 'rest_validate_request_arg ' ,
105
105
),
106
- 'user_id ' => array (
106
+ 'user_id ' => array (
107
107
'description ' => esc_html__ ( 'The ID of the user. ' , 'jwt-auth ' ),
108
108
'type ' => 'integer ' ,
109
109
'required ' => true ,
@@ -120,7 +120,7 @@ public function register_routes() {
120
120
'callback ' => array ( $ this , 'delete_all_key_pairs ' ),
121
121
'permission_callback ' => '__return_true ' ,
122
122
'args ' => array (
123
- 'user_id ' => array (
123
+ 'user_id ' => array (
124
124
'description ' => esc_html__ ( 'The ID of the user. ' , 'jwt-auth ' ),
125
125
'type ' => 'integer ' ,
126
126
'required ' => true ,
@@ -136,14 +136,14 @@ public function register_routes() {
136
136
'callback ' => array ( $ this , 'delete_key_pair ' ),
137
137
'permission_callback ' => '__return_true ' ,
138
138
'args ' => array (
139
- 'user_id ' => array (
139
+ 'user_id ' => array (
140
140
'description ' => esc_html__ ( 'The ID of the user. ' , 'jwt-auth ' ),
141
141
'type ' => 'integer ' ,
142
142
'required ' => true ,
143
143
'sanitize_callback ' => 'absint ' ,
144
144
'validate_callback ' => 'rest_validate_request_arg ' ,
145
145
),
146
- 'api_key ' => array (
146
+ 'api_key ' => array (
147
147
'description ' => esc_html__ ( 'The API key being revoked. ' , 'jwt-auth ' ),
148
148
'type ' => 'string ' ,
149
149
'required ' => true ,
@@ -359,11 +359,14 @@ public function authenticate( $user, WP_REST_Request $request ) {
359
359
360
360
$ found = false ;
361
361
$ 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.
362
365
foreach ( $ keypairs as $ _key => $ item ) {
363
366
if ( isset ( $ item ['api_key ' ] ) && $ item ['api_key ' ] === $ key ) {
364
367
$ keypairs [ $ _key ]['last_used ' ] = time ();
365
368
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__
367
370
if ( $ ip ) {
368
371
$ keypairs [ $ _key ]['last_ip ' ] = $ ip ;
369
372
}
@@ -708,6 +711,7 @@ public function template_new_key_pair() {
708
711
* @since 0.1
709
712
*/
710
713
public function template_new_token_key_pair () {
714
+ // phpcs:disable WordPressVIPMinimum.Security.Mustache.OutputNotation
711
715
?>
712
716
<script type="text/html" id="tmpl-new-token-key-pair">
713
717
<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() {
764
768
</div>
765
769
</script>
766
770
<?php
771
+ // phpcs:enable WordPressVIPMinimum.Security.Mustache.OutputNotation
767
772
}
768
773
769
774
/**
0 commit comments