magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Rest api getting customer token does not work

Open sheldonli999 opened this issue 10 years ago • 47 comments

Steps to reproduce

  1. curl to magento 2.0.5 installation to get customer token
  2. curl -X POST "http://youdomain/index.php/rest/V1/integration/customer/token"
    -H "Content-Type:application/json"
    -d '{"username":"[email protected]", "password":"xxxxxxxx1"}'

Expected result

  1. a token return

Actual result

  1. get the following msg: {"message":"You did not sign in correctly or your account is temporarily disabled."}

sheldonli999 avatar May 09 '16 09:05 sheldonli999

looks like the issue occurs inside event Manager.php. Any quick fix?

sheldonli999 avatar May 09 '16 16:05 sheldonli999

Hi @sheldonli999 I could not reproduce this, I was able to get the customer token. Please make sure that you are entering the correct email & password to the request because the message you provided is the one that gets returned when an incorrect email or password is entered.

hshar7 avatar May 16 '16 19:05 hshar7

Hello,

I got the same issue. After few successful times (in which I could get token), it starts return above message.

tukhoi avatar Jul 04 '16 07:07 tukhoi

I also got the same issue... keep repeating the correct username and password. Still not getting any.

rbo13 avatar Jul 19 '16 07:07 rbo13

You guys sure the admin account you're trying to login to is not locked? you can try unlocking it using bin/magento

hshar7 avatar Jul 19 '16 14:07 hshar7

I confirm the same issue. I can login to admin, unlock says The user account "********" was not locked or could not be unlocked, and the rest api request says {'message': 'You did not sign in correctly or your account is temporarily disabled.'}

signalprime avatar Aug 18 '16 18:08 signalprime

this suddenly stopped working on my system. I created a second user to test with same results. I'm testing from the admin so my test is like: curl -X POST "http://youdomain/index.php/rest/V1/integration/admin/token" \ -H "Content-Type:application/json" \ -d '{"username":"[email protected]", "password":"xxxxxxxx1"}'

signalprime avatar Aug 18 '16 20:08 signalprime

same problem

vaimeo avatar Oct 13 '16 14:10 vaimeo

Has no one found a solution to this yet? Why is there no simple way to unlock customer? For anyone who faces this problem and needed to move ahead first, just head over to vendor/magento/module-integration/Model/CustomerTokenService.php Put this $this->getRequestThrottler()->resetAuthenticationFailuresCount($username, RequestThrottler::USER_TYPE_CUSTOMER);

before $this->getRequestThrottler()->throttle($username, RequestThrottler::USER_TYPE_CUSTOMER);

And when you have 1 request done, remove that part of code.

Magento community has been very slow in fixing this type of low priority bug.

shoguniphicus avatar Oct 14 '16 06:10 shoguniphicus

A lot of comments here. Reopening

hshar7 avatar Oct 14 '16 13:10 hshar7

As @shoguniphicus hinted, the problem resides with the authentication failure/throttling mechanism that is part of the REST API authentication flow. At least that's what happened in the case I had access to.

It keeps track of failed attempts to get a token with an email and the wrong password (in the oauth_token_request_log table). If the failures_count column reaches the max allowed value (which is 6 by default, and supposed to be configurable in the store configuration, though it doesn't seem to be exposed in the admin panel). then authentication fails. A lock_expires_at timestamp is set to some time in the future (equally configurable, by default a few minutes, it seems).

The problem is the timestamp is not checked by the throttling mechanism, which just checks the failure count. The way a locked email is supposed to be cleaned up is via a cron job defined in: module-integration/Cron/CleanExpiredAuthenticationFailures.php which, in turn, calls the clearExpiredFailures method in module-integration/Model/ResourceModel/Oauth/Token/RequestLog.php which deletes all records with lock_expires_at older than the current time.

So this should work as expected, if the cron job was run as intended. I added logging to the above cron job, so I can see that its execute method is not called at all. I don't know how Magento finds what cron jobs to run or why it's not finding this one (some missing registration step perhaps?) , but it seems to me if this problem was fixed, the permanent locking of users from authentication would go away.

A temporary solution would be to run your own cron job that does this cleanup on the database.

fechever avatar Oct 28 '16 16:10 fechever

{ "message": "You did not sign in correctly or your account is temporarily disabled.", "trace": "#0 /home/public_html/shop/vendor/magento/module-integration/Model/AdminTokenService.php(81): Magento\Integration\Model\Oauth\Token\RequestThrottler->throttle('admin ', 3)\n#1 [internal function]: Magento\Integration\Model\AdminTokenService->createAdminAccessToken(

I have same issue.

srinathweb avatar Nov 03 '16 05:11 srinathweb

The same issue here. Magento 2.1.1 Manual clearing oauth_token_request_log table helps.

rzinnatullin avatar Nov 03 '16 11:11 rzinnatullin

yes The same issue here. Magento 2.1.1 Manual clearing oauth_token_request_log table fixed my issue

srinathweb avatar Nov 25 '16 02:11 srinathweb

I was facing the issue and clearing out the oauth_token_request_log table helped and now i can get the token.

altafhussain10 avatar Dec 19 '16 07:12 altafhussain10

I can confirm Magento 2.1.2 still not fixed

pyyick avatar Jan 05 '17 10:01 pyyick

the same issue here. Magento 2

dajdouj10 avatar Jan 19 '17 08:01 dajdouj10

Hello I can confirm that Magento 2.1.5 still not fixed.

It is a blocking issue when this API call is used to log admin customer to an internal application without the possibility to reactive this account.

Thanks to provide a fix.

franckgarnier21 avatar Mar 09 '17 13:03 franckgarnier21

I also had same issue. But i found i am using wrong values. May be I am wrong but below is my finding

  1. The token api will not work for a customer. Customer and admin accounts are managed separately in magento.
  2. For getting token need to use username and password, not email and password.

nikhilzoom avatar Apr 21 '17 06:04 nikhilzoom

Having the same issue here, Magento 2.1.5, suddenly unable to authenticate through API with rest/V1/integration/admin/token. Can authenticate through Admin Panel. The user is active, it's not blocked.

Responding {"message":"You did not sign in correctly or your account is temporarily disabled."}

gastondisacco avatar Apr 21 '17 19:04 gastondisacco