Reputation: 10068
I have the following api route:
Route::get('/user/get', function(Request $request) {
return Auth::user();
})->middleware('auth:api');
Client application to test the above:
$access_token = 'd3f7333f7602c67e03cab2ab5171e893aeb731af0524d47864fb9d517de46f359a9dc6377195d46e';
$ch = curl_init();
$url = 'http://127.0.0.1:8000/api/user/get';
$header = array(
'Accept: application/json',
'Authorization: Bearer '. $access_token
);
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$result = curl_exec($ch);
curl_close($ch);
$response = json_decode($result);
var_dump($result);
var_dump result is always: Unauthorized.
I've copied the access_token from the database table and it's neither revoked nor expired and theres only one access_token in the table.
So why is the above not working - any ideas what I'm doing wrong?
Upvotes: 1
Views: 230
Reputation: 10068
ok looks like token inside database table is encrypted or something which is probably why it doesn't work. When I use the token as returned from http://127.0.0.1:8000/oauth/token then it works.
Upvotes: 1