@@ -21,6 +21,12 @@ class WP_JSON_Authentication_OAuth1 extends WP_JSON_Authentication {
21
21
*/
22
22
protected $ type = 'oauth1 ' ;
23
23
24
+ /**
25
+ * Errors that occurred during authentication
26
+ * @var WP_Error|null|boolean True if succeeded, WP_Error if errored, null if not OAuth
27
+ */
28
+ protected $ auth_status = null ;
29
+
24
30
/**
25
31
* Parse the Authorization header into parameters
26
32
*
@@ -134,35 +140,50 @@ public function authenticate( $user ) {
134
140
135
141
$ params = $ this ->get_parameters ();
136
142
if ( ! is_array ( $ params ) ) {
137
- return $ params ;
143
+ $ this ->auth_status = $ params ;
144
+ return null ;
138
145
}
139
146
140
147
// Fetch user by token key
141
148
$ token = $ this ->get_access_token ( $ params ['oauth_token ' ] );
142
149
if ( is_wp_error ( $ token ) ) {
143
- return $ token ;
150
+ $ this ->auth_status = $ token ;
151
+ return null ;
144
152
}
145
153
146
154
$ result = $ this ->check_token ( $ token , $ params ['oauth_consumer_key ' ] );
147
155
if ( is_wp_error ( $ result ) ) {
148
- return $ result ;
156
+ $ this ->auth_status = $ result ;
157
+ return null ;
149
158
}
150
159
list ( $ consumer , $ user ) = $ result ;
151
160
152
161
// Perform OAuth validation
153
162
$ error = $ this ->check_oauth_signature ( $ user , $ params , $ token );
154
163
if ( is_wp_error ( $ error ) ) {
155
- return $ error ;
164
+ $ this ->auth_status = $ error ;
165
+ return null ;
156
166
}
157
167
158
168
$ error = $ this ->check_oauth_timestamp_and_nonce ( $ user , $ params ['oauth_timestamp ' ], $ params ['oauth_nonce ' ] );
159
169
if ( is_wp_error ( $ error ) ) {
160
- return $ error ;
170
+ $ this ->auth_status = $ error ;
171
+ return null ;
161
172
}
162
173
174
+ $ this ->auth_status = true ;
163
175
return $ user ;
164
176
}
165
177
178
+ /**
179
+ * Report authentication errors to the JSON API
180
+ *
181
+ * @return WP_Error|boolean|null {@see WP_JSON_Server::check_authentication}
182
+ */
183
+ public function get_authentication_errors () {
184
+ return $ this ->auth_status ;
185
+ }
186
+
166
187
/**
167
188
* Serve an OAuth request
168
189
*
0 commit comments