Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save phamngsinh/3a7c21a1cad15562607519fe698b71ff to your computer and use it in GitHub Desktop.

Select an option

Save phamngsinh/3a7c21a1cad15562607519fe698b71ff to your computer and use it in GitHub Desktop.
Get Token Authentication For Customer Logged With Facebook & Twitter : Magento 2
/**
* {@inheritdoc}
*/
public function createCustomerAccessToken($username, $password)
{
$this->validatorHelper->validate($username, $password);
$this->getRequestThrottler()->throttle($username, RequestThrottler::USER_TYPE_CUSTOMER);
try {
$customerDataObject = $this->accountManagement->authenticate($username, $password);
} catch (\Exception $e) {
$this->getRequestThrottler()->logAuthenticationFailure($username, RequestThrottler::USER_TYPE_CUSTOMER);
throw new AuthenticationException(
__('You did not sign in correctly or your account is temporarily disabled.')
);
}
$this->getRequestThrottler()->resetAuthenticationFailuresCount($username, RequestThrottler::USER_TYPE_CUSTOMER);
return $this->tokenModelFactory->create()->createCustomerToken($customerDataObject->getId())->getToken();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment