-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validate grant types #14
Conversation
Whoops, let me go back and answer :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we instead just specify function ( Type $type )
and have PHP validate for us? 🤔
plugin.php
Outdated
$grant_types = apply_filters( 'oauth2.grant_types', array() ); | ||
|
||
return array_filter( $grant_types, function ( $type ) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for the blank line here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed (aka fixed).
No, not really. PHP would not validate (and discard invalid) types, like the code that I suggested, but rather expect correct implementations, and fatal error if encountered anything else. return array_filter( $types, function ( Type $type ) {
return true;
} ); So, in fact, we wouldn't really need the callback('s body), but just PHP that kicks in for checking (and fatal erroring because of) the type. To be honest, I would rather keep my code (or something along the lines). But like I said, the bahavior would be discard invalid types. If you want PHP to jump the user into their face, we can do that. 😀 Does this make sense? 🤔 |
I'd rather not silently drop objects; it makes debugging a pain for developers. If not the fatal error, we should at least fire a |
Makes sense. Should I adapt the closure accordingly? |
That'd be great, thanks :) |
Inform user when they are doing it wrong. Since it is PHP 5.6, we cannot use array_filter() with the ARRAY_FILTER_USE_BOTH flag, can we? Thus, use a regular foreach loop.
I just updated the validation code, again. If only we could use PHP 5.6+... :) Comments? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👍
Hi again,
@rmccue didn't comment on my What's Left list in #8, but since this was no big deal, I just created this pull request with a proposed validation for grant type( handler)s.
The result of the grant type filter,
oauth2.grant_types
, will be validated, and onlyWP\OAuth2\Types\Type
implementations make it to the consumer.Comments?
Cheers,
Thorsten