Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel JWT and socialite plugin

I am using Laravel's JWT plugin for user login/authentication. This works fine for my users table:enter image description here when he specifically registers into my website, entering a password, email etc.

In the jwt, i am checking for email(which is unique) and password.

I would like to also implement the Laravel's socialite plugin, to enable login using google/facebook etc, using oauth2 .

Could anybody tell me how to use both ?

I have set an authentication middleware , that checks for the authentication token(generated by JWT plugin). But I am not sure how that will work if I login using g+ etc

like image 479
harveyslash Avatar asked Dec 09 '22 00:12

harveyslash


1 Answers

If you are using JWTAuth https://github.com/tymondesigns/jwt-auth , it also supports Socialite login. After Socialite returns an authenticated user, you can lookup the DB by email or create if not exists. Then you can generate token using

$token = JWTAuth::fromUser($user)

More discussions can be found at this link https://laracasts.com/discuss/channels/laravel/how-would-one-use-jwt-json-web-tokens-with-laravel-socialite

like image 185
notnotundefined Avatar answered Dec 26 '22 09:12

notnotundefined