Skip to content

Commit 1cd2bb7

Browse files
committed
Validate grant types and adapt documentation.
1 parent 8b4b28c commit 1cd2bb7

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

inc/endpoints/class-authorization.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use WP_Error;
66
use WP\OAuth2;
7+
use WP\OAuth2\Types\Type;
78

89
class Authorization {
910
const LOGIN_ACTION = 'oauth2_authorize';
@@ -26,6 +27,7 @@ public function handle_request() {
2627
// Match type to a handler.
2728
$grant_types = OAuth2\get_grant_types();
2829
if ( $grant_types ) {
30+
/** @var Type $type_handler */
2931
foreach ( array_reverse( $grant_types ) as $type_handler ) {
3032
if ( $type_handler->get_response_type_code() === $type ) {
3133
$handler = $type_handler;

plugin.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace WP\OAuth2;
1111

12+
use WP\OAuth2\Types\Type;
1213
use WP_REST_Response;
1314

1415
bootstrap();
@@ -63,7 +64,7 @@ function rest_oauth2_load_authorize_page() {
6364
/**
6465
* Get valid grant types.
6566
*
66-
* @return array Map of grant type to handler object.
67+
* @return Type[] Map of grant type to handler object.
6768
*/
6869
function get_grant_types() {
6970
/**
@@ -73,9 +74,14 @@ function get_grant_types() {
7374
* Note that additional grant types must follow the extension policy in the
7475
* OAuth 2 specification.
7576
*
76-
* @param array $grant_types Map of grant type to handler object.
77+
* @param Type[] $grant_types Map of grant type to handler object.
7778
*/
78-
return apply_filters( 'oauth2.grant_types', array() );
79+
$grant_types = apply_filters( 'oauth2.grant_types', array() );
80+
81+
return array_filter( $grant_types, function ( $type ) {
82+
83+
return $type instanceof Type;
84+
} );
7985
}
8086

8187
/**

0 commit comments

Comments
 (0)