Always got "message": "Unauthenticated." - Laravel Passport
In the event you’ve tried everything and nothing seems to work, try clearing your configuration cache. I spent two days reinstalling passport, following a billion tutorials, creating test projects etc. all to eventually realise I needed to clear my cache
php artisan config:cache
In order to get detail error message of the causes, you need to go to CheckClientCredentials
class detail as below
public function handle($request, Closure $next, ...$scopes)
{
$psr = (new DiactorosFactory)->createRequest($request);
try {
$psr = $this->server->validateAuthenticatedRequest($psr);
} catch (OAuthServerException $e) {
error_log($e->getHint()); // add this line to know the actual error
throw new AuthenticationException;
}
$this->validateScopes($psr, $scopes);
return $next($request);
}
Based on the error message. in my question.
The solution is adding this to .htaccess
of root folder (not only inside the public folder)
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
There's also a note in the official documents refer here
Without above configuration, the Authorization
header will be ignored during call from anywhere to app. Once ignored, inside class will unable to retrieve this header data
In Ubuntu, do the following.
Enable the rewrite mode.
sudo a2enmod rewrite
Go to cd /etc/apache2
Then open apache2.conf nano apache2.conf
and find out the following line and change AllowOverride None to AllowOverride All as shown below.
# /etc/apache2/apache2.conf
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Finally, restart apache2 server
sudo service apache2 restart