认证
Web API认证概述
 Magento 2允许开发者在在配置文件webapi.xml中定义Web API资源及其权限。
            下面是关于将服务作为Web API的更多细节。
            在启用Web API调用之前,必须验证身份并拥有访问API资源的必要权限(授权)。Magento认证允许识别呼叫者的用户类型。基于用户(管理员,集成,客户或来宾)访问权限,API调用的资源可访问性是确定的。
可访问的资源
您可以访问的资源列表取决于您的用户类型。所有客户都有相同的权限,因此可以访问相同的资源。前面的语句对于客户用户也是正确的。
            每个管理员或用户积分可以有一套独特的权限配置在Magento管理。
            访问特定资源所需的权限在 webapi.xml 文件中定义。
注册用户 webapi.xml示例代码片段:
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">
    <!-- Customer Group -->
    <route url="/V1/customerGroups/:id" method="GET">
        <service class="Magento\Customer\Api\GroupRepositoryInterface" method="getById"/>
        <resources>
            <resource ref="Magento_Customer::group"/>
        </resources>
    </route>
............
.......
.....
    <!-- Customer Account -->
    <route url="/V1/customers/:customerId" method="GET">
        <service class="Magento\Customer\Api\CustomerRepositoryInterface" method="getById"/>
        <resources>
            <resource ref="Magento_Customer::customer"/>
        </resources>
    </route>
    <route url="/V1/customers" method="POST">
        <service class="Magento\Customer\Api\AccountManagementInterface" method="createAccount"/>
        <resources>
            <resource ref="anonymous"/>
        </resources>
    </route>
    <route url="/V1/customers/:id" method="PUT">
        <service class="Magento\Customer\Api\CustomerRepositoryInterface" method="save"/>
        <resources>
            <resource ref="Magento_Customer::manage"/>
        </resources>
    </route>
    <route url="/V1/customers/me" method="PUT">
        <service class="Magento\Customer\Api\CustomerRepositoryInterface" method="save"/>
        <resources>
            <resource ref="self"/>
        </resources>
        <data>
            <parameter name="customer.id" force="true">%customer_id%</parameter>
        </data>
    </route>
..........
.....
...
          下一步
- 移动应用。 Token-based 认证.
 - 第三方应用。 OAuth-based 认证.
 - Magento 2管理或店面的javascript控件。 session-based 认证.
 
相关话题
扩展属性认证