Skip to main content
4 of 4
added 8 characters in body
Mohammad Mujassam
  • 2.2k
  • 7
  • 26
  • 29

What I understand from you question is, You have only email (and obviously some network specific secret key to validate i.e facebook key).

So You just need to load the customer by email id as below.

protected function getCustomerToken($emailId){
 /**
* @var \Magento\Customer\Model\Customer $customer */
*/
$customer->loadByEmail($emailId);
if($customer->getId()){
        /**
        * @var \Magento\Integration\Model\Oauth\TokenFactory $tokenModelFactory 
        */
        $customerToken = $this->tokenModelFactory->create();
        $tokenKey = $customerToken->createCustomerToken($customerId)->getToken();
        return $tokenKey;
}
return "YOU MSG FOR CUSTOMER NOT FOUND";
}

The above code should return the token key without password.

Note: Make sure you are doing proper & strong validating before generating the token & rest is already explained in Franck's answer .

Mohammad Mujassam
  • 2.2k
  • 7
  • 26
  • 29