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.