Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 684fa24

Browse files
author
Harper, Kevin(keharper)
committed
Merge pull request magento#733 from Magento/pubs31_2341
Pubs31 2341 Added section about extension attributes
2 parents f682497 + f07abc9 commit 684fa24

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

guides/v1.0/get-started/authentication/gs-authentication.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,63 @@ Authorization is granted to either an administrator (or an integration) defined
118118
<p>Similarly, self is a special access used if you already have an authenticated session with the system. Self access enables a user to access resources they own. For example, <code>GET /V1/customers/me</code> fetches the logged-in customer's details. This is typically useful for JavaScript-based widgets. </p>
119119
</div>
120120

121+
<h3 id="extension_attrs">Extension attribute authentication</h3>
122+
123+
Individual fields that are defined as extension attributes can be restricted, based on existing permissions. This feature allows extension developers to restrict access to data.
124+
125+
126+
The following [code sample](https://github.corp.ebay.com/magento2/magento2ce/blob/develop/app/code/Magento/CatalogInventory/etc/extension_attributes.xml) defines `stock_item` as an extension attribute of the `CatalogInventory` module. `CatalogInventory` is treated as a “3rd-party extension”. Access to the inventory data is restricted because the quantity of in-stock item may be competitive information.
127+
128+
{% highlight XML %}
129+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Api/etc/extension_attributes.xsd">
130+
<extension_attributes for="Magento\Catalog\Api\Data\ProductInterface">
131+
<attribute code="stock_item" type="Magento\CatalogInventory\Api\Data\StockItemInterface">
132+
<resources>
133+
<resource ref="Magento_CatalogInventory::cataloginventory"/>
134+
</resources>
135+
</attribute>
136+
</extension_attributes>
137+
</config>
138+
{% endhighlight %}
139+
140+
In this example, the `stock_item` attribute is restricted to only the users who have the `Magento_CatalogInventory::cataloginventory` permission. As a result, an anonymous or unauthenticated user issuing a `GET http://store/rest/V1/products/<sku>` request will receive product information similar to the following:
141+
142+
<pre>
143+
{
144+
"sku": “tshirt1”,
145+
“price”: “20.00”,
146+
“description”: “New JSmith design”,
147+
“extension_attributes”: {
148+
“logo size”: “small”
149+
},
150+
“custom_attributes”: {
151+
“artist”: “James Smith”
152+
}
153+
}
154+
</pre>
155+
156+
However, an authenticated user with the permission `Magento_CatalogInventory::cataloginventory` receives the additional `stock_item` field:
157+
158+
<pre>
159+
{
160+
"sku": “tshirt1”,
161+
“price”: “20.00”,
162+
“description”: “New JSmith design”,
163+
“extension_attributes”: {
164+
“logo size”: “small”,
165+
“stock_item” : {
166+
“status” : “in_stock”
167+
“quantity”: 70
168+
}
169+
},
170+
“custom_attributes”: {
171+
“artist”: “James Smith”
172+
}
173+
}
174+
</pre>
175+
176+
This only works for extension attributes (those attributes defined in an `extension_attributes.xml` file). There are no permission restrictions on the rest of the returned data. For example, there is no way to restrict `custom_attributes`.
177+
121178
<h3 id="webapi-clients">Web API clients and authentication methods</h3>
122179
<p>You use a client, such as a mobile application or an external batch job, to access Magento services using web APIs.</p>
123180
<p>Each type of client has a preferred authentication method. To authenticate, use the authentication method for your preferred client:</p>

0 commit comments

Comments
 (0)