I’m debugging a PHP script for the authentication of users, the users are authenticated via Firebase on the frontend, and each call to the backend contains this in the header;
Authorization: "Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6IjU2OTFhMTk1Y..."
Here is my PHP code in the backend
public static function checkLogin(){
$headers = apache_request_headers();
//var_dump($headers);
// Get the public key
$publicKey = file_get_contents('https://www.googleapis.com/robot/v1/metadata/x509/[email protected]');
$publicKey = json_decode($publicKey, true);
$k = array();
foreach ($publicKey as $key => $value) {
$k[] = $key;
}
// Get the bearer key from the header
if (isset($headers['Authorization']) ){
$jwt = explode(' ', $headers['Authorization'])[1];
} else if (isset($headers['authorization'])) {
$jwt = explode(' ', $headers['authorization'])[1];
}
JWT::$leeway = 60;
// HERE IS THE CRASH
$decoded = JWT::decode($jwt, new Key($k[0], 'HS256'));
$decoded_array = (array) $decoded;
Utilities::debug($decoded_array);
if ($decoded_array['exp'] > time() ) {
return $decoded_array['exp'];
}else {
die(json_encode(array("error" => true, "status" => 401, "message" => "ACCESS DENIED.")));
}
}
I get this error, Fatal error: Uncaught UnexpectedValueException: Incorrect key for this algorithm in C:sourcesvendorfirebasephp-jwtsrcJWT.php on line <i>143</i>
I don’t see any ref of an algorithm in the frontend
Anyone have an idea of what’s wrong?
Ed