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 ) {
246246 return new static ( $ post );
247247 }
248248
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+
249276 /**
250277 * Create a new client.
251278 *
Original file line number Diff line number Diff line change 22
33namespace WP \OAuth2 \Types ;
44
5+ use WP_Http ;
56use WP_Error ;
67use WP \OAuth2 \Client ;
78
@@ -24,7 +25,7 @@ public function handle_authorisation() {
2425 $ scope = isset ( $ _GET ['scope ' ] ) ? wp_unslash ( $ _GET ['scope ' ] ) : null ;
2526 $ state = isset ( $ _GET ['state ' ] ) ? wp_unslash ( $ _GET ['state ' ] ) : null ;
2627
27- $ client = Client::get_by_id ( $ client_id );
28+ $ client = Client::get_by_client_id ( $ client_id );
2829 if ( empty ( $ client ) ) {
2930 return new WP_Error (
3031 '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() {
7272 * @return array Grant types with additional types registered.
7373 */
7474function register_grant_types ( $ types ) {
75- $ types ['authorization_code ' ] = new Types \Authorization_Code ();
75+ $ types ['authorization_code ' ] = new Types \AuthorizationCode ();
7676 $ types ['implicit ' ] = new Types \Implicit ();
7777
7878 return $ types ;
You can’t perform that action at this time.
0 commit comments