0

I found below code on custom API file :

public function orderDetails($params)
{
    $customerID = $this->userContext->getUserId();
    if(empty($customerID)){
        return[[
            'error_code' => 1001,
            "message"=>"Validation Failed",
            'error_desc'   => 'Unable to locate customer'
        ]];
    }
    .........
    .......
}

Few Points :

  • $this->userContext is object of class Magento\Authorization\Model\UserContextInterface

My Questions are :

  • How magento handles authentication in API's.
  • What data we need to send and where so that Magento\Authorization\Model\UserContextInterface can set customer id
  • What data i need to send so that i can get the User Id from UserContextInterface class, like code above

I am not getting how and from where the data are set and retrieve related to user on API's.

  • You need to send bearer token in header. you will get token from rest/VI/integration/customer/token endpoint. – Ramkishan Suthar Feb 6 '19 at 10:35
0

Magento 2 have below 2 API

  1. SOAP
  2. REST

Three types of authentication:

  1. Third-party applications authenticate with OAuth 1.0a.
  2. Mobile applications authenticate using tokens.
  3. Administrators and customers are authenticated with login credentials.

Most common authentication is Token based authentication. To access API you need integration token. As part of authentication you need to use integration token

How to access API you can follow below link

https://devdocs.magento.com/guides/v2.3/get-started/bk-get-started-api.html

For authentication check below link

https://devdocs.magento.com/guides/v2.3/get-started/authentication/gs-authentication.html

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.