Skip to content

Commit 02414d5

Browse files
author
Joe McGill
authored
Merge pull request #5 from alleyinteractive/fix/add_permission_callbacks
Add permission callbacks to REST API endpoints
2 parents 5ca835e + afac56e commit 02414d5

File tree

2 files changed

+28
-23
lines changed

2 files changed

+28
-23
lines changed

wp-includes/rest-api/auth/class-wp-rest-key-pair.php

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,33 +92,35 @@ public static function get_rest_uri() {
9292
*/
9393
public function register_routes() {
9494
$args = array(
95-
'methods' => WP_REST_Server::CREATABLE,
96-
'callback' => array( $this, 'generate_key_pair' ),
97-
'args' => array(
98-
'name' => array(
95+
'methods' => WP_REST_Server::CREATABLE,
96+
'callback' => array( $this, 'generate_key_pair' ),
97+
'permission_callback' => '__return_true',
98+
'args' => array(
99+
'name' => array(
99100
'description' => esc_html__( 'The name of the key-pair.', 'jwt-auth' ),
100101
'type' => 'string',
101102
'required' => true,
102103
'sanitize_callback' => 'sanitize_text_field',
103104
'validate_callback' => 'rest_validate_request_arg',
104105
),
105-
'user_id' => array(
106+
'user_id' => array(
106107
'description' => esc_html__( 'The ID of the user.', 'jwt-auth' ),
107108
'type' => 'integer',
108109
'required' => true,
109110
'sanitize_callback' => 'absint',
110111
'validate_callback' => 'rest_validate_request_arg',
111112
),
112113
),
113-
'schema' => array( $this, 'get_item_schema' ),
114+
'schema' => array( $this, 'get_item_schema' ),
114115
);
115116
register_rest_route( self::_NAMESPACE_, '/' . self::_REST_BASE_ . '/(?P<user_id>[\d]+)', $args );
116117

117118
$args = array(
118-
'methods' => WP_REST_Server::DELETABLE,
119-
'callback' => array( $this, 'delete_all_key_pairs' ),
120-
'args' => array(
121-
'user_id' => array(
119+
'methods' => WP_REST_Server::DELETABLE,
120+
'callback' => array( $this, 'delete_all_key_pairs' ),
121+
'permission_callback' => '__return_true',
122+
'args' => array(
123+
'user_id' => array(
122124
'description' => esc_html__( 'The ID of the user.', 'jwt-auth' ),
123125
'type' => 'integer',
124126
'required' => true,
@@ -130,17 +132,18 @@ public function register_routes() {
130132
register_rest_route( self::_NAMESPACE_, '/' . self::_REST_BASE_ . '/(?P<user_id>[\d]+)/revoke-all', $args );
131133

132134
$args = array(
133-
'methods' => WP_REST_Server::DELETABLE,
134-
'callback' => array( $this, 'delete_key_pair' ),
135-
'args' => array(
136-
'user_id' => array(
135+
'methods' => WP_REST_Server::DELETABLE,
136+
'callback' => array( $this, 'delete_key_pair' ),
137+
'permission_callback' => '__return_true',
138+
'args' => array(
139+
'user_id' => array(
137140
'description' => esc_html__( 'The ID of the user.', 'jwt-auth' ),
138141
'type' => 'integer',
139142
'required' => true,
140143
'sanitize_callback' => 'absint',
141144
'validate_callback' => 'rest_validate_request_arg',
142145
),
143-
'api_key' => array(
146+
'api_key' => array(
144147
'description' => esc_html__( 'The API key being revoked.', 'jwt-auth' ),
145148
'type' => 'string',
146149
'required' => true,

wp-includes/rest-api/auth/class-wp-rest-token.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,29 +98,31 @@ public static function get_rest_uri() {
9898
*/
9999
public function register_routes() {
100100
$args = array(
101-
'methods' => WP_REST_Server::READABLE,
102-
'callback' => array( $this, 'validate' ),
101+
'methods' => WP_REST_Server::READABLE,
102+
'callback' => array( $this, 'validate' ),
103+
'permission_callback' => '__return_true'
103104
);
104105
register_rest_route( self::_NAMESPACE_, '/' . self::_REST_BASE_ . '/validate', $args );
105106

106107
$args = array(
107-
'methods' => WP_REST_Server::CREATABLE,
108-
'callback' => array( $this, 'generate_token' ),
109-
'args' => array(
110-
'api_key' => array(
108+
'methods' => WP_REST_Server::CREATABLE,
109+
'callback' => array( $this, 'generate_token' ),
110+
'permission_callback' => '__return_true',
111+
'args' => array(
112+
'api_key' => array(
111113
'description' => __( 'The API key of the user; requires also setting the api_secret.', 'jwt-auth' ),
112114
'type' => 'string',
113115
'sanitize_callback' => 'sanitize_text_field',
114116
'validate_callback' => 'rest_validate_request_arg',
115117
),
116-
'api_secret' => array(
118+
'api_secret' => array(
117119
'description' => __( 'The API secret of the user; requires also setting the api_key.', 'jwt-auth' ),
118120
'type' => 'string',
119121
'sanitize_callback' => 'sanitize_text_field',
120122
'validate_callback' => 'rest_validate_request_arg',
121123
),
122124
),
123-
'schema' => array( $this, 'get_item_schema' ),
125+
'schema' => array( $this, 'get_item_schema' ),
124126
);
125127
register_rest_route( self::_NAMESPACE_, '/' . self::_REST_BASE_, $args );
126128
}

0 commit comments

Comments
 (0)