John Mellor
John Mellor

Reputation: 2503

Laravel passport: Manually create access token

I'm building an SPA using VueJS and Laravel.

I'm using Laravel passport for logins which works fine.

However I would like the ability to send users magic links to log in with. However I'm not sure how to create an access token without sending a request with the password to the oauth route.

It seems like it should be really easy to do, just inserting the right rows into oauth_access_tokens and oauth_refresh_tokens.

But i've been trawling through the code in the Passport repo and Google results and everything seems way more complicated.

What I would like is be able to do something like this:

$user = User::findFromMagicLink($link);
$token = $user->createAccessToken();
return response()->json(['access_token' => $token->token, 'refresh_token' => $token->refresh_token])

I'm guessing that's not possible otherwise it would be documented somewhere. But if it's something more complicated than that I can't figure it out.

Can anyone point me in the right direction?

Upvotes: 3

Views: 5672

Answers (1)

bhavinjr
bhavinjr

Reputation: 1763

Try this You can create access token like

$user = User::findFromMagicLink($link)
$token  = $user->createToken('UserToken', ['*']);
//or directly access
$token  = $user->createToken('UserToken', ['*'])->accessToken;

For more info Read: Manage personal access token

Upvotes: 5

Related Questions