You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In both these adapters, we used the **route name** as resource. This means, you
45
-
can specify if a role is authorized to access a specific HTTP route or not.
46
-
This is just a general idea for implementing an authorization system. You can
47
-
create your own system implementing the[AuthorizationInterface](https://github.com/zendframework/zend-expressive-authorization/blob/master/src/AuthorizationInterface.php),
48
-
as reported above.
55
+
In each adapter, we use the **route name** as the resource. This means you
56
+
can specify if a role is authorized to access a specific HTTP _route_.
57
+
However, this is just one approach to implementing an authorization system; you
This component provides authorization abstraction middleware for [PSR-7](https://www.php-fig.org/psr/psr-7/)
4
-
applications.
3
+
This component provides authorization middleware for [PSR-7](https://www.php-fig.org/psr/psr-7/)
4
+
and [PSR-15](https://www.php-fig.org/psr/psr-15/)applications.
5
5
6
-
An authorization system needs authentication first. To verify that an identity
7
-
has access to something (i.e. is authorized) we need to have an identity,
8
-
if authenticated.
6
+
An authorization system first needs authentication: to verify that an identity
7
+
has access to something (i.e., is authorized) we first need the _identity_, which
8
+
is provided during authentication.
9
9
10
-
You can easily implement an authentication system using [zend-expressive-authentication](https://github.com/zendframework/zend-expressive-authentication)
11
-
library. This library provides an `AuthenticationMiddleware` class that verify
12
-
credentials using the HTTP request and store an identity as [PSR-7 attribute](https://docs.zendframework.com/zend-expressive/v2/cookbook/passing-data-between-middleware/).
That library provides an `AuthenticationMiddleware` class that verify
13
+
credentials using the HTTP request, and stores the identity via a [PSR-7 request attribute](https://docs.zendframework.com/zend-expressive/v2/cookbook/passing-data-between-middleware/).
13
14
14
-
The identity attribute generated by [zend-expressive-authentication](https://github.com/zendframework/zend-expressive-authentication)
15
-
is named`Zend\Expressive\Authentication\UserInterface`and it contains a
16
-
`UserInterface`object.
15
+
The identity generated by zend-expressive-authentication is stored as the
16
+
request attribute`Zend\Expressive\Authentication\UserInterface`as a
17
+
`UserInterface`implementation. That interface looks like the following:
17
18
18
19
```php
19
20
namespace Zend\Expressive\Authentication;
@@ -24,34 +25,39 @@ interface UserInterface
24
25
* Get the unique user identity (id, username, email address or ...)
25
26
*/
26
27
public function getIdentity() : string;
28
+
27
29
/**
28
30
* Get all user roles
29
31
*
30
32
* @return Iterable
31
33
*/
32
34
public function getRoles() : iterable;
35
+
33
36
/**
34
37
* Get a detail $name if present, $default otherwise
35
38
*/
36
39
public function getDetail(string $name, $default = null);
40
+
37
41
/**
38
42
* Get all the details, if any
39
43
*/
40
44
public function getDetails() : array;
41
45
}
42
46
```
43
47
44
-
**Zend Expressive Authorization** consumes this identity attribute.
45
-
It checks if a user's role (of the `UserInterface` object) is authorized
46
-
(granted) to execute the HTTP request.
48
+
zend-expressive-authorization consumes this identity attribute. It checks if a
49
+
user's role (as retrieved from the `UserInterface` object) is authorized
50
+
(granted) to the perform the current HTTP request.
51
+
52
+
Authorization is performed using the `isGranted()` method of the
The authorization is performed using the `isGranted()` function of the [AuthorizationInterface](https://github.com/zendframework/zend-expressive-authorization/blob/master/src/AuthorizationInterface.php).
55
+
We offer two adapters:
49
56
50
-
We offer two adapters: [zend-expressive-authorization-rbac](https://github.com/zendframework/zend-expressive-authorization-rbac)
51
-
for implementing a Role-Based Access Control ([RBAC](https://en.wikipedia.org/wiki/Role-based_access_control))
0 commit comments