hasib32 / rest-api-with-lumen

Rest API boilerplate for Lumen micro-framework.
486 stars 144 forks source link

Invalid Credentials #28

Closed jossydeleon closed 7 years ago

jossydeleon commented 7 years ago

I am running your tutorial, but I could not get the accessToken. This is the response that I received. I am trying with severals of emails registered in the database (fake data) with the password: test-password but i am getting this response

{ "error": "invalid_credentials", "message": "The user credentials were incorrect." }

hasib32 commented 7 years ago

Is your password hashed?

jossydeleon commented 7 years ago

Yes is hashed

hasib32 commented 7 years ago

Also, make sure you have grant_type password and you are also using correct client_secret. if you don't have client_secret make sure to run this command: php artisan passport:install

jossydeleon commented 7 years ago

I am using grant_type = password and client_id = 2 with its correct cliente secrect generated

hasib32 commented 7 years ago

try using client_id = 1 and it's correct client_secret

jossydeleon commented 7 years ago

When I used client_id = 1 we got this: { "error": "invalid_client", "message": "Client authentication failed" }

hasib32 commented 7 years ago

make sure you have client_id =1 in oauth_clients table

jossydeleon commented 7 years ago

This is what we have in oauth_clients:

mysql> select * from oauth_clients; +----+---------+-------------------------+------------------------------------------+------------------+------------------------+-----------------+---------+---------------------+---------------------+ | id | user_id | name | secret | redirect | personal_access_client | password_client | revoked | created_at | updated_at | +----+---------+-------------------------+------------------------------------------+------------------+------------------------+-----------------+---------+---------------------+---------------------+ | 1 | NULL | Personal Access Client | EsmawsokHjfy5eTBqVPE86Moqg13JxWzONC75vsk | http://localhost | 1 | 0 | 0 | 2017-07-25 16:26:27 | 2017-07-25 16:26:27 | | 2 | NULL | Password Grant Client | tATASGXt5FiJWSJWXqp5jBvSAo7BP0VO2VaFPpzm | http://localhost | 0 | 1 | 0 | 2017-07-25 16:26:27 | 2017-07-25 16:26:27 |

hasib32 commented 7 years ago

so, you should use client_id 2 for password grant. another catch, even though we are using username when we are creating access_token it's actually email field in users table. so, make sure you have that email address.

hasib32 commented 7 years ago

Did it work?

jossydeleon commented 7 years ago

We were using the email as username, but still is not working

hasib32 commented 7 years ago

Then, make sure your password is properly hashed.

limaho commented 7 years ago

Can I use this API to login user from an Android app?

hasib32 commented 7 years ago

@limaho yes.

jossydeleon commented 7 years ago

@hasib32 now is working, was my bad. I had a blank space in password. Thanks. Now I am doing some test. Thanks again