Asked by: TheMysticalWarrior
The error is only occurring when personal access tokens are being used, If I use a Password client to get a token then it goes through fine.
This is the Route that I'm using to test that it is going through
Route::get('/test', function() {
return "hello";
})->middleware('auth:api');
This is the function that I am using to get the access token
public function testToken() {
$user = User::where("id", 12)->first();
$token = $user->createToken("TokenName")->accessToken;
return $token;
}
This is the access token that I'm trying to use (The one gotten from testToken()
)
eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjNlNTliODI1ZWVlZTYzZjRkMjYxZTliMDRiZTdlOGM2OTE2OGIxODIzOWVhZDQ3YjkwODY0ZGQxODU2ZmZkYjc1NmNiNzE2NTRjOGQ1N2U0In0.eyJhdWQiOiI1IiwianRpIjoiM2U1OWI4MjVlZWVlNjNmNGQyNjFlOWIwNGJlN2U4YzY5MTY4YjE4MjM5ZWFkNDdiOTA4NjRkZDE4NTZmZmRiNzU2Y2I3MTY1NGM4ZDU3ZTQiLCJpYXQiOjE0OTk3NzA4ODgsIm5iZiI6MTQ5OTc3MDg4OCwiZXhwIjoxODE1MzAzNjg4LCJzdWIiOiIxMiIsInNjb3BlcyI6W119.TkAanA7Un5Z4BHYVm1tBUtzQXDNl_z26fHcbzC-wNC-7zHg3GCqnWicgKxZsuE5_1zuDikqZj6tKKkRou5K2ftA9A6l3wBMxmyQZy-BZl20CbzyovYw5kfFwOdJYNKeAF5g0jBVXJdFCDvHexiQGrfzoj9b95v9jRNfdDbhrJd-1wHMQpIps7qjn3rtVIupwc2HpajJ4hADgZUCGjcV8YpOpWoaTt8lZocJUlUTbeNE0AwdI_c9tSA48qaSZizOIb1DYLSLZjeqKvRJFHvplAhTQN9glbF598Nws0FqkvnEWk-3nXL8EejJ155EAyNwKkDnc3e6W23JqjdGzXiHsTRmVDdizLrkk86Z-24oj2KJwcdPYMGkcnggqIZ8hn7ikGSoTV73G_nW_VUBOidHzcYKgMgXPQGST2gC3yPgAnQJPmXBUyc98hMz4LbDNkXKYcsMp23kUxC1caO3JYE4LljVLaQaxdhqZlaTBcaus5HtcRYrYMmZhgxaXpy-VOM2fljBW-QgM1rs8D9GwBuxecBmgPvbN6HqnYTlYRwmxbfOtKoeT7H5aK3_a36at1dL1V3K0S176v91ZGfWoxlYLzq_uWxpq_T9SOkaoxjeMfYiVjJyXMDsTbmE7PrQQcEwKNVc9DdcQgJmewd-Sr15O66inhH8j7-4_WPysxS6SXBY
I'm passing the token through in the header (NOTE I'm testing using postman)
Accept:application/json
Authorization:Bearer **TOKEN**
Doing some Googling I found that people have fixed it by setting the expiration date of the token, Though this did not work in my case.
I also found people suggesting to change Passport.php in the providers, but I do not have this file to edit... I don't know if it could be because I installed passport wrong or something like that. I did follow the documentation for the install
Answers
Answered by: Hwong Alex at 2017-07-11 05:13PM
I believe that you will read the document carefully and the problem will be solved. https://laravel.com/docs/5.4/passport#installation https://laravel.com/docs/5.4/passport#personal-access-tokens
This route creates new personal access tokens. It requires two pieces of data: the token's name and the scopes that should be assigned to the token:
const data = {
name: 'Token Name',
scopes: []
};
axios.post('/oauth/personal-access-tokens', data)
.then(response => {
console.log(response.data.accessToken);
})
.catch (response => {
// List errors on response...
});
No comments:
Post a Comment