13:06:54 28/4/2024 - 1 views -Programming
public function VerifyToken($jwt = null)
{
$headers = getallheaders();
if(false == isset($headers['Authorization'])
&& false == isset($headers['authorization']))
{
return [
'status' => 401,
'message' => "Authorization's not received"
];
}
$headerAuthor = isset($headers['Authorization']) ? $headers['Authorization'] : $headers['authorization'];
$jwt = $headerAuthor;
$jwt = str_replace("Bearer ", "", $jwt);
This way is not good when using Laravel. Because when I write a Feature test, getallheaders() returns an empty array, so we go to the next way
public function VerifyToken($jwt = null)
{
$jwt = request()->headers->get('authorization');
if($jwt === null)
{
return [
'status' => 401,
'message' => "Authorization's not received"
];
}
$jwt = str_replace("Bearer ", "", $jwt);