Protecting a PHP API Using OAuth

Eduardo Riquelme

Thanks for this tutorial, it was really easy to implement and test. Just got a problem with JWK after I add the token authorization to the API. To solve this i had to:

1. Install firebase/php-jwt composer require firebase/php-jwt and dump autoloader composer dump-autoload
2. Add this 2 lines on top of index.php use Firebase\JWT\JWT; and use Firebase\JWT\JWK;
3. (Optional) Add catch error when token expires:
try{
$result = JWT::decode($token, $publicKey, array(‘RS256’));
}catch(\Firebase\JWT\ExpiredException $e){
echo 'Caught exception: ', $e->getMessage(), “\n”;
}

Hope this helps!