tymondesigns / jwt-auth

🔐 JSON Web Token Authentication for Laravel & Lumen
https://jwt-auth.com
MIT License
11.3k stars 1.54k forks source link

Only authenticates from default Model #1029

Open imranalii opened 7 years ago

imranalii commented 7 years ago

Hi, I've implemented JWT for Laravel 5.4 & its working fine with users model. I need JWT to work for other table "app_users" not users. I've changed "user model namespace" to app_users under config/jwt.php 'user' => 'App\Models\AppUsers', Following is authenticate function: try { // verify the credentials and create a token for the user if (! $token = JWTAuth::attempt($credentials)) { return response()->json(['error' => 'invalid_credentials'], 401); } } catch (JWTException $e) { // something went wrong return response()->json(['error' => 'could_not_create_token'], 500); }

Moreover, config/auth.php 'guards' => [ 'web' => [ 'driver' => 'session', 'provider' => 'users', ], 'api' => [ 'driver' => 'token', 'provider' => 'app_users', ], ], Just wanted to know which guard is called default by JWT. I want it to call "api" guard. Also, driver token for api guard always throw below error. Call to undefined method Illuminate\Auth\TokenGuard::attempt() If I change it to "jwt-auth" it throws follwing error: Auth guard driver [api] is not defined. so let me know which guard to use? Thanks a lot.

juniarta commented 7 years ago

me to same problem

mrABR commented 7 years ago

Same problem, bump

nghiepdev commented 7 years ago

Same problem, bump

danieluyo commented 7 years ago

@tymondesigns :/

tymondesigns commented 7 years ago

What version of jwt-auth are you guys using?

danieluyo commented 7 years ago

@tymondesigns im using 0.5.9

tymondesigns commented 7 years ago

There is no guard support for 0.5. You will need to use one of the latest 1.0.0- versions.

The official docs for 1.0.0 are not complete just yet, but there is a quick setup guide lurking in the issues. I'll link to it when I'm not on my phone...

tymondesigns commented 7 years ago

Actually found it #860

danieluyo commented 7 years ago

👍

Joosshhhh commented 7 years ago

I'm having the same issue for Lumen. Using 1.0.0.* For some reason the JWTAuth::attempt($credentials) keeps giving me a invalid_credentials for a Model that's not having the default users table (my database table is user).

Joosshhhh commented 7 years ago

Nevermind I'm trollin, my password in my database wasn't minimum 60 characters was 45. Works fine thanks for making this for Lumen and Laravel @tymondesigns

stoneworld commented 7 years ago

Same problem, bump bump. have any solution?

afshines commented 7 years ago

Another reason is to use the user object to create a license

$token = JWTAuth::fromUser($user)

try { // attempt to verify the credentials and create a token for the user if (!$token = JWTAuth::fromUser($user)) { return response()->json(['error' => 'invalid_credentials'], 401); } } catch (JWTException $e) { // something went wrong whilst attempting to encode the token return response()->json(['error' => 'could_not_create_token'], 500); }