File tree Expand file tree Collapse file tree 3 files changed +30
-2
lines changed Expand file tree Collapse file tree 3 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -246,6 +246,33 @@ public static function get_by_id( $id ) {
246
246
return new static ( $ post );
247
247
}
248
248
249
+ /**
250
+ * Get a client by Client ID.
251
+ *
252
+ * @param int $id Client ID of the app.
253
+ * @return static|null Client instance on success, null if invalid/not found.
254
+ */
255
+ public static function get_by_client_id ( $ id ) {
256
+ $ args = array (
257
+ 'meta_query ' => array (
258
+ array (
259
+ 'key ' => '_oauth2_client_id ' ,
260
+ 'value ' => $ id ,
261
+ 'compare ' => '= ' ,
262
+ )
263
+ ),
264
+ 'post_type ' => 'oauth2_client ' ,
265
+ 'post_status ' => 'any '
266
+ );
267
+
268
+ $ client_ids = get_posts ( $ args );
269
+ if ( count ( $ client_ids ) !== 1 ) {
270
+ return null ;
271
+ }
272
+
273
+ return new static ( $ client_ids [0 ] );
274
+ }
275
+
249
276
/**
250
277
* Create a new client.
251
278
*
Original file line number Diff line number Diff line change 2
2
3
3
namespace WP \OAuth2 \Types ;
4
4
5
+ use WP_Http ;
5
6
use WP_Error ;
6
7
use WP \OAuth2 \Client ;
7
8
@@ -24,7 +25,7 @@ public function handle_authorisation() {
24
25
$ scope = isset ( $ _GET ['scope ' ] ) ? wp_unslash ( $ _GET ['scope ' ] ) : null ;
25
26
$ state = isset ( $ _GET ['state ' ] ) ? wp_unslash ( $ _GET ['state ' ] ) : null ;
26
27
27
- $ client = Client::get_by_id ( $ client_id );
28
+ $ client = Client::get_by_client_id ( $ client_id );
28
29
if ( empty ( $ client ) ) {
29
30
return new WP_Error (
30
31
'oauth2.types.authorization_code.handle_authorisation.invalid_client_id ' ,
Original file line number Diff line number Diff line change @@ -72,7 +72,7 @@ function get_grant_types() {
72
72
* @return array Grant types with additional types registered.
73
73
*/
74
74
function register_grant_types ( $ types ) {
75
- $ types ['authorization_code ' ] = new Types \Authorization_Code ();
75
+ $ types ['authorization_code ' ] = new Types \AuthorizationCode ();
76
76
$ types ['implicit ' ] = new Types \Implicit ();
77
77
78
78
return $ types ;
You can’t perform that action at this time.
0 commit comments