12

I'm trying to find a way to create an access token manually in Laravel 5.5 using Passport and can't seem to figure it out.

I have 2 applications, one that holds the frontend and one api. The user receives an invitation via mail, and when he accesses the link, i wish to create the auth token and send it back in the response.

Any ideas on how to do this ? Thanks.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Catalin I.
  • 331
  • 1
  • 2
  • 6

1 Answers1

21

Solved it myself. It seems that the HasApiTokens trait that you put on the users model has a method to create a token

$user->createToken($name, $scopes);
linktoahref
  • 7,812
  • 3
  • 29
  • 51
Catalin I.
  • 331
  • 1
  • 2
  • 6
  • 2
    It don't seems to, it's a fact and described here https://laravel.com/docs/5.5/passport (search for _createToken_) – Matz Dec 20 '17 at 10:47
  • 2
    Note that according to the docs: Personal access tokens are always long-lived. Their lifetime is not modified when using the tokensExpireIn or refreshTokensExpireIn methods. – Yahya Uddin Apr 12 '18 at 11:38