在 Magento 2 Rest API 中收到令牌后,如何获取当前签名的用户信息
How can I get the current signed user info after the token has been receive in Magento 2 Rest API
查看 Magento 2 REST 基于令牌的身份验证系统后。成功登录后,我收到了一个授权令牌,但我不知道如何使用该令牌获取当前客户的详细信息,以便我知道当前用户。
这是我遵循的获取令牌的说明。
http://devdocs.magento.com/guides/v2.0/get-started/authentication/gs-authentication-token.html
您可以使用这些方法接收有关您自己的信息(我猜您是以客户身份登录的)
检索给定客户 ID 的默认账单地址:
GET http://Magento-2-0/index.php/rest/V1/customers/me/billingAddress
检索给定客户 ID 的默认送货地址:
GET http://Magento-2-0/index.php/rest/V1/customers/me/shippingAddress
要检索您应该使用的常见客户信息:
GET http://Magento-2-0/index.php/rest/V1/customers/me
响应应该是这样的:
{
"id": 0,
"groupId": 0,
"defaultBilling": "string",
"defaultShipping": "string",
"confirmation": "string",
"createdAt": "string",
"updatedAt": "string",
"createdIn": "string",
"dob": "string",
"email": "string",
"firstname": "string",
"lastname": "string",
"middlename": "string",
"prefix": "string",
"suffix": "string",
"gender": 0,
"storeId": 0,
"taxvat": "string",
"websiteId": 0,
"addresses": [
{
"id": 0,
"customerId": 0,
"region": {
"regionCode": "string",
"region": "string",
"regionId": 0,
"extensionAttributes": {}
},
"regionId": 0,
"countryId": "string",
"street": [
"string"
],
"company": "string",
"telephone": "string",
"fax": "string",
"postcode": "string",
"city": "string",
"firstname": "string",
"lastname": "string",
"middlename": "string",
"prefix": "string",
"suffix": "string",
"vatId": "string",
"defaultShipping": true,
"defaultBilling": true,
"extensionAttributes": {},
"customAttributes": [
{
"attributeCode": "string",
"value": "string"
}
]
}
],
"disableAutoGroupChange": 0,
"extensionAttributes": {},
"customAttributes": [
{
"attributeCode": "string",
"value": "string"
}
]
}
每个调用应该有 header "Authorization":"Bearer token"
查看 Magento 2 REST 基于令牌的身份验证系统后。成功登录后,我收到了一个授权令牌,但我不知道如何使用该令牌获取当前客户的详细信息,以便我知道当前用户。
这是我遵循的获取令牌的说明。 http://devdocs.magento.com/guides/v2.0/get-started/authentication/gs-authentication-token.html
您可以使用这些方法接收有关您自己的信息(我猜您是以客户身份登录的)
检索给定客户 ID 的默认账单地址:
GET http://Magento-2-0/index.php/rest/V1/customers/me/billingAddress
检索给定客户 ID 的默认送货地址:
GET http://Magento-2-0/index.php/rest/V1/customers/me/shippingAddress
要检索您应该使用的常见客户信息:
GET http://Magento-2-0/index.php/rest/V1/customers/me
响应应该是这样的:
{
"id": 0,
"groupId": 0,
"defaultBilling": "string",
"defaultShipping": "string",
"confirmation": "string",
"createdAt": "string",
"updatedAt": "string",
"createdIn": "string",
"dob": "string",
"email": "string",
"firstname": "string",
"lastname": "string",
"middlename": "string",
"prefix": "string",
"suffix": "string",
"gender": 0,
"storeId": 0,
"taxvat": "string",
"websiteId": 0,
"addresses": [
{
"id": 0,
"customerId": 0,
"region": {
"regionCode": "string",
"region": "string",
"regionId": 0,
"extensionAttributes": {}
},
"regionId": 0,
"countryId": "string",
"street": [
"string"
],
"company": "string",
"telephone": "string",
"fax": "string",
"postcode": "string",
"city": "string",
"firstname": "string",
"lastname": "string",
"middlename": "string",
"prefix": "string",
"suffix": "string",
"vatId": "string",
"defaultShipping": true,
"defaultBilling": true,
"extensionAttributes": {},
"customAttributes": [
{
"attributeCode": "string",
"value": "string"
}
]
}
],
"disableAutoGroupChange": 0,
"extensionAttributes": {},
"customAttributes": [
{
"attributeCode": "string",
"value": "string"
}
]
}
每个调用应该有 header "Authorization":"Bearer token"