Skip to content

Commit 30a66f6

Browse files
committed
Get client ID by real client id instead of post id
1 parent d3a0326 commit 30a66f6

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

inc/class-client.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff 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
*

inc/types/class-base.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace WP\OAuth2\Types;
44

5+
use WP_Http;
56
use WP_Error;
67
use 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',

plugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function get_grant_types() {
7272
* @return array Grant types with additional types registered.
7373
*/
7474
function 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;

0 commit comments

Comments
 (0)