Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Passport: Create access token manually

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.

like image 865
Catalin I. Avatar asked Dec 20 '17 10:12

Catalin I.


People also ask

How can I get token in Laravel Passport?

Requesting Tokens Once you have created a password grant client, you may request an access token by issuing a POST request to the /oauth/token route with the user's email address and password. Remember, this route is already registered by the Passport::routes method so there is no need to define it manually.

Where is Laravel Passport token stored?

You can store this token in local storage. This token is also stored in the oauth_access_tokens table. We will be sending a GET request to your URL and we need to send it token as Authorization Header. Above way successive technologies can do API authentication in Laravel Application with a passport.

Does Laravel Passport use JWT?

Passport uses JWT authentication as standard but also implements full OAuth 2.0 authorization.


1 Answers

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);
like image 80
Catalin I. Avatar answered Oct 18 '22 00:10

Catalin I.