2

I'm trying to setup JWT using Laravel.

I'm basically following the info form the jwt package and another page: https://github.com/tymondesigns/jwt-auth https://scotch.io/tutorials/token-based-authentication-for-angularjs-and-laravel-apps

I've got a few differences, mainly user model is called Human, but for the most part I'm following the examples above

The issue is that I can't validate a user. Whenever I hit the route with a post request I get the 401 Error. So I did some investigating in the php artisan tinker console. If I select the first user in my database check their password hash it's fine, this works:

$human = App\Human::first();
Hash::check('12345', $human['password']); // true

But if I try to generate a JWT, it fails.

JWTAuth::attempt(['email' => $human['email'], 'password' => '12345']); // false

I'm not sure where to go from here to debug this.

UPDATE: The key to this is that my 'user' table is actually called 'humans'. I had a user table hanging around in my database and as soon I removed it I got an error that the user table doesn't exist.

I did change this this line in my jwt config:

'user' => 'App\Human',

To reflect that my 'user' model is called Human, and I went into the laravel auth.php and set my model there also. Still when I call the JWTAuth attempt method it tries to access the 'users' table and not the 'humans' table where the passwords are actually stored.

Obviously I could change the table name but that makes another part of the application ugly. So I guess what I need is a way to configure jwt-auth to look at a different table.

3
  • have you find a working solution? Commented Jul 13, 2015 at 21:50
  • We have moved our 'users' back to the 'App/User' model. I'd prefer to use a table called 'humans' and use a model called 'App\Human', but I can't figure out how to configure the JWT package to do this yet. Commented Jul 15, 2015 at 11:07
  • did u fixed this issue? Commented Aug 22, 2015 at 20:55

1 Answer 1

1

It may be ok when hashing the password, try this

JWTAuth::attempt(['email' => $human['email'], 'password' => bcrypt('12345')]);
Sign up to request clarification or add additional context in comments.

1 Comment

All the example send the password to the attempt method unencrypted. I added an update with more info.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.