Skip to content

Instantly share code, notes, and snippets.

@justingreerbbi
Created November 15, 2019 00:55
Show Gist options
  • Select an option

  • Save justingreerbbi/8587d270cab2328bcd45f717b11336f6 to your computer and use it in GitHub Desktop.

Select an option

Save justingreerbbi/8587d270cab2328bcd45f717b11336f6 to your computer and use it in GitHub Desktop.
Check Before Authorizing a User in WordPress OAuth after using Authorization Code Grant Type.
add_action( 'wo_authorization_code_authorize', 'before_authorization_test' );
function before_authorization_test( $user_id ) {
$user_id = $user_id[0];
$authorized = true;
// Do user check and authorize if allowed
// Present error is the user is not authorized
if ( $authorized == false ) {
$response = new WPOAuth2\Response();
$response->setError( 400, 'unauthorized_user', 'Unauthorized User' );
$response->send();
exit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment