2

When I request an access token at oauth/token using the password grant, I get a token back. However this token is the same every time and doesn't match any token in the database. Where are these tokens stored? And how can I use this token to retrieve my user data in an AJAX call?

kajdehoop
  • 517
  • 8
  • 22
  • Please take a look at this [answer](https://stackoverflow.com/questions/50254237/laravel-passport-are-apis-tokens-stored-on-the-server-and-where) – Sabine Dec 11 '19 at 10:07

2 Answers2

3

After installing passport. you need to run command php artisan migrate. this command will create 4 tables.

  • oauth_access_tokens
  • oauth_auth_codes
  • oauth_personal_access_clients
  • oauth_refresh_tokens

PASSPORT ACCESS TOKENS ARE STORED IN oauth_access_tokens table. in this table id column is used to store token.

MAX POWER
  • 5,213
  • 15
  • 89
  • 141
Sai Kumar
  • 31
  • 4
0

The token generated by oauth server is unique and you have to store it somewhere like cookies or user table. You can pass the access_token through authorization header.

Ajax call :

var token = "Your access_token";
$.ajax({
url:"someurl.com/api/auth/getuser",
dataType: 'json',
headers: {
  'Authorization': 'Bearer ' + token
},
success: function(data, status) {
   return console.log("The returned data", data);
}
});
Wellwisher
  • 472
  • 2
  • 8