I've registered the Vue components as mentioned in the Laravel Passport documentation, and they also do show up in my app:
<passport-clients></passport-clients>
<passport-authorized-clients></passport-authorized-clients>
<passport-personal-access-tokens></passport-personal-access-tokens>
However, they don't show any tokens/clients, and I am not able to create any either, due to my application says I am "unauthorized":
GET http://spa.test/oauth/personal-access-tokens 401
GET http://spa.test/oauth/clients 401 (Unauthorized)
GET http://spa.test/oauth/tokens 401 (Unauthorized)
GET http://spa.test/oauth/scopes 401 (Unauthorized)
This is my AuthServiceProvider.php
public function boot() {
$this->registerPolicies();
Passport::routes();
}
I've also included the trait to my app/User.php
:
use HasApiTokens, Notifiable;
Remember, I am using Laravel as a backend and Vue.js as a frontend, which gives me an SPA.
This is my routes/api.php
:
Route::middleware('auth:api')->group(function () {
Route::get('/user', function (Request $request) {
return $request->user();
});
});
This is my routes.js
:
const routes = [
{
path: '/api/*',
},
/**
* Handle Authentication
*/
{
path: '/',
alias: '/login',
name: 'login',
component: Login,
beforeEnter: ifNotAuthenticated,
}
/**
* Handle logged in pages
*/
{
path: '/dashboard',
name: 'layout',
component: MasterLayout,
beforeEnter: ifAuthenticated,
children: [{
path: '/dashboard',
name: 'dashboard',
component: Dashboard
}, {
path: '/home',
name: 'home',
component: Home
}]
},
];
Update 1:
I see that the problem is that I am authenticated using Passport (auth:api
) All of the passport routes use web Middleware to make sure you are authenticated, which is a session based authentication:
Update 2:
Please see my request header:
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate
Accept-Language: da-DK,da;q=0.9,en-US;q=0.8,en;q=0.7,nb;q=0.6
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImY5OGNiZjBhYmNjZGIyNzk1ZDRhOTllODEwZTQxMzFhMjMwNzhhNzVjYWMzYmM0Y2I2Yzg3NjM3ZDFlMzdkNmI3YzU4YWIzNWM4YmU5MDIxIn0.eyJhdWQiOiIyIiwianRpIjoiZjk4Y2JmMGFiY2NkYjI3OTVkNGE5OWU4MTBlND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ac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36
X-CSRF-TOKEN: v9z5uFoGWPGprc3kJaCMhLpHGbvgQ7usXLwZu11e
X-Requested-With: XMLHttpRequest
X-XSRF-TOKEN: eyJpdiI6IkhrQnB1SCs5dWV4OU8zck10djZRbEE9PSIsInZhbHVlIjoieFwvZTJCUFVRZ0haQWNZVjBvUkJ2Q1FTSGtGTHM5SjBXTndOeXBFc2o2Q3pjclRRbjFqeHVpclJOQ3FPTUdKQ2t4M0g4bE5VUXRcL0twdXFNR25IT1NBdz09IiwibWFjIjoiYjI5MzRkNTEwMWZhNWUzNTI5ZTY2OTg5YTYxODQ3MDBkMTU2ZjJjZTE3YzdhZDc2ODMwNjI0NzlmMmQyZTY1NyJ9
Any idea on how I can still use Vue as a frontend, Laravel as a backend and still use Laravel Passport to handle tokens for 3rd party applications?