Skip to content

Commit db01bfd

Browse files
committed
changes from review
1 parent 38c38c1 commit db01bfd

2 files changed

Lines changed: 80 additions & 80 deletions

File tree

docs/book/v4/core-features/authentication.md

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,79 +3,79 @@
33
Authentication is the process by which an identity is presented to the application. It ensures that the entity
44
making the request has the proper credentials to access the API.
55

6-
DotKernel's API identities are delivered to the application from the client through the `Authorization` request
7-
header.  If it is present, the application tries to find and assign the identity to the application. If it is not presented,
8-
DotKernel's API assigns a default `guest` identity, represented by an instance of the class
6+
DotKernel API identities are delivered to the application from the client through the `Authorization` request
7+
If it is present, the application tries to find and assign the identity to the application. If it is not presented,
8+
DotKernel API assigns a default `guest` identity, represented by an instance of the class
99
`Mezzio\Authentication\UserInterface`.
1010

1111
## Configuration
1212

13-
DotKernel's API authentication is made around `mezzio/mezzio-authentication-oauth2` component and is already configured.
14-
with what is necessary in order to work. But if you want to dig more, the configuration is hold on.
15-
`config/autoload/local.php` under the authentication key.
13+
Authentication in DotKernel API is built around `mezzio/mezzio-authentication-oauth2` component and is already configured
14+
with what is necessary in order to work. But if you want to dig more, the configuration is stored in
15+
`config/autoload/local.php` under the `authentication` key.
1616

1717
> You can check the [mezzio/mezzio-authentication-oauth2](https://docs.mezzio.dev/mezzio-authentication-oauth2/v1/intro/#configuration)
18-
> configuration part for more digging.
18+
> configuration part for more info.
1919
2020
## How it works
2121

22-
DotKernel's API authentication system can be used for SPAs (single-page applications), mobile applications, and
22+
DotKernels API authentication system can be used for SPAs (single-page applications), mobile applications, and
2323
simple, token-based APIs. It allows each user of your application to generate API tokens for their accounts.
2424

2525
The authentication happens through the middleware in the `Api\App\Middleware\AuthenticationMiddleware`.
2626

2727
## Database
2828

2929
When DotKernel API is installed for the first time, and you run the migrations and seeders, all the tables
30-
needed for authentication are automatically created and inserted with the data needed for authentication.
30+
needed for authentication are automatically created and populated with the data needed for authentication.
3131

32-
In DotKernel's API, authentication users can be from the `admin` table and from the `users` table. We choose to keep the admin
32+
In DotKernel API, authenticated users come from either the `admin` or the `users` table. We choose to keep the admin
3333
table separated from the users to prevent users of the application from accessing sensitive data, which only the administrators
3434
of the application should access.
3535

3636
Knowing this, upon migrations, the `oauth_clients` table is pre-populated with the default `admin` and `frontend` clients with
37-
the same password as their names. (you can change those passwords.).
37+
the same password as their names (you can change those passwords).
3838

39-
As you guested each client serves to authenticate `admin` or `users`.
39+
As you guessed each client serves to authenticate `admin` or `users`.
4040

4141
Another table that is pre-populated is the `oauth_scopes` table, with the `api` scope.
4242

4343
### Issuing API Tokens
4444

45-
In DotKernel's API, generating tokens is done using the `password` `grand_type` scenario, which in this case allows authentication
45+
Token generation in DotKernel API is done using the `password` `grand_type` scenario, which in this case allows authentication
4646
to an API using the user's credentials (generally a username and password).
4747

4848
The client sends a POST request to the `/security/generate-token` with the following parameters:
4949

5050
- `grant_type` = password.
51-
- `client_id` with the client name (from `oauth_clients` table).
52-
- `client_secret` with the client secret (password from `oauth_clients` table for the client).
53-
- `scope` with the scope from `oauth_scopes` table.
54-
- `username` with the user’s username.
55-
- `password` with the user’s password.
51+
- `client_id` = column `name` from the `oauth_clients` table
52+
- `client_secret` = column `secret` from the `oauth_clients` table
53+
- `scope` = column `scope` from the `oauth_scopes` table
54+
- `username` = column `identity` from table `admin`/`user`
55+
- `password` = column `password` from table `admin`/`user`
5656

5757
```shell
5858
POST /security/generate-token HTTP/1.1
5959
Accept: application/json
6060
Content-Type: application/json
6161
{
62-
"grant_type": "password",
63-
"client_id": "frontend",
64-
"client_secret": "frontend",
65-
"scope": "api",
66-
"username": "test@dotkernel.com",
67-
"password": "dotkernel"
62+
"grant_type": "password",
63+
"client_id": "frontend",
64+
"client_secret": "frontend",
65+
"scope": "api",
66+
"username": "test@dotkernel.com",
67+
"password": "dotkernel"
6868
}
6969
```
7070

7171
The server responds with a JSON as follows:
7272

73-
```php
73+
```json
7474
{
75-
"token_type": "Bearer",
76-
"expires_in": 86400,
77-
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9...",
78-
"refresh_token": "def5020087199939a49d0f2f818..."
75+
"token_type": "Bearer",
76+
"expires_in": 86400,
77+
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9...",
78+
"refresh_token": "def5020087199939a49d0f2f818..."
7979
}
8080
```
8181

@@ -90,7 +90,7 @@ Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9...
9090

9191
### Refreshing tokens
9292

93-
DotKernel's API provides the ability to refresh the access token, generating a new one.
93+
DotKernel API provides the ability to refresh the access token, by generating a new one using the expired access token's `refresh_token`.
9494

9595
The clients need to send a `POST` request to the `/security/refresh-token` with the following request
9696

@@ -99,21 +99,21 @@ POST /security/refresh-token HTTP/1.1
9999
Accept: application/json
100100
Content-Type: application/json
101101
{
102-
"grant_type": "refresh_token",
103-
"client_id": "frontend",
104-
"client_secret": "frontend",
105-
"scope": "api",
106-
"refresh_token" : "def5020087199939a49d0f2f818..."
102+
"grant_type": "refresh_token",
103+
"client_id": "frontend",
104+
"client_secret": "frontend",
105+
"scope": "api",
106+
"refresh_token" : "def5020087199939a49d0f2f818..."
107107
}
108108
```
109109

110110
The server responds with a JSON as follows:
111111

112-
```php
112+
```json
113113
{
114-
"token_type": "Bearer",
115-
"expires_in": 86400,
116-
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9...",
117-
"refresh_token": "def5020087199939a49d0f2f818..."
114+
"token_type": "Bearer",
115+
"expires_in": 86400,
116+
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9...",
117+
"refresh_token": "def5020087199939a49d0f2f818..."
118118
}
119119
```

docs/book/v4/core-features/authorization.md

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,74 +3,74 @@
33
Authorization is the process by which a system take a validated identity and checks if that identity has access to a
44
given resource.
55

6-
DotKernel's APIs implementation of the authorization uses `Mezzio\Authorization\Rbac\LaminasRbac` as a model of
7-
Role-Based Access Control (RBAC)
6+
DotKernel APIs implementation of authorization uses `Mezzio\Authorization\Rbac\LaminasRbac` as a model of
7+
Role-Based Access Control (RBAC).
88

99
## How it works
1010

11-
In DotKernel's API each authenticatable entity (admin and users) comes in with their roles table where you can define
11+
In DotKernel API each authenticatable entity (admin/user) comes with their roles table where you can define
1212
roles for each entity. RBAC comes in to ensure that each entity has the appropriate role and permission to access a resource.
1313

14-
The authorization happens through the middleware in the `Api\App\Middleware\AuthorizationMiddleware`.
14+
The authorization happens through the `Api\App\Middleware\AuthorizationMiddleware` middleware.
1515

1616
## Configuration
1717

18-
In DotKernel API make use of `mezzio-authorization-rbac` and upon installation all the configuration is already made
18+
DotKernel API makes use of `mezzio-authorization-rbac` and upon installation all the configuration is already made
1919
in order for the authorization to work.
2020

21-
The configuration where you define roles and permission is hold on `config/autoload/authorization.global.php`
21+
The configuration file for the role and permission definitions is `config/autoload/authorization.global.php`.
2222

2323
```php
2424
'mezzio-authorization-rbac' => [
25-
'roles' => [
26-
AdminRole::ROLE_SUPERUSER => [],
27-
AdminRole::ROLE_ADMIN => [
28-
AdminRole::ROLE_SUPERUSER,
29-
],
30-
UserRole::ROLE_GUEST => [
31-
UserRole::ROLE_USER,
32-
],
25+
'roles' => [
26+
AdminRole::ROLE_SUPERUSER => [],
27+
AdminRole::ROLE_ADMIN => [
28+
AdminRole::ROLE_SUPERUSER,
3329
],
34-
'permissions' => [
35-
AdminRole::ROLE_SUPERUSER => [],
36-
AdminRole::ROLE_ADMIN => [
37-
'other.routes'
38-
'admin.list',
39-
'home'
40-
],
41-
UserRole::ROLE_USER => [
42-
'other.routes',
43-
'user.my-account.update',
44-
'user.my-account.view',
45-
],
46-
UserRole::ROLE_GUEST => [
47-
'other.routes',
48-
'security.refresh-token',
49-
'error.report',
50-
'home',
51-
],
30+
UserRole::ROLE_GUEST => [
31+
UserRole::ROLE_USER,
5232
],
5333
],
34+
'permissions' => [
35+
AdminRole::ROLE_SUPERUSER => [],
36+
AdminRole::ROLE_ADMIN => [
37+
'other.routes'
38+
'admin.list',
39+
'home'
40+
],
41+
UserRole::ROLE_USER => [
42+
'other.routes',
43+
'user.my-account.update',
44+
'user.my-account.view',
45+
],
46+
UserRole::ROLE_GUEST => [
47+
'other.routes',
48+
'security.refresh-token',
49+
'error.report',
50+
'home',
51+
],
52+
],
53+
],
5454
```
5555

56-
> You can check [mezzio-authorization-rbac](https://docs.mezzio.dev/mezzio-authorization-rbac/v1/basic-usage/) for more
57-
> in depth
56+
> See [mezzio-authorization-rbac](https://docs.mezzio.dev/mezzio-authorization-rbac/v1/basic-usage/)
57+
> for more information.
5858
5959
## Usage
6060

6161
Based on the configuration file above, we have 2 admins roles (`superuser`, `admin`) and 2 users roles (`user`, `guest`).
6262

63-
A role can inherit the roles of their parent:
63+
Roles inherit the permissions from their parents:
6464

6565
- `superuser` has no parent
6666
- `admin` has `superuser` as a parent which means `superuser` will inherit `admin` permissions
6767
- `user` has no parent
6868
- `guest` has `user` as a parent which means `user` will inherit `guest` permissions
6969

70-
For each role we defined an array of permissions. A permission in DotKernel's is basically a route name.
70+
For each role we defined an array of permissions. A permission in DotKernel API is basically a route name.
7171

72-
As you can see, the `superuser` does not have any permission, because inherit all the permission from `admin`no
73-
need to define permission for him again.
72+
As you can see, the `superuser` does not have it's own permissions, because it inherits all the permissions from `admin`,
73+
no need to define permissions for it unless necessary.
7474

75-
The `user` role, inherit all the permission from `guest` so no need to define that `user` can access `home` route, but
76-
`guest` cannot access `user.my-account.view` route.
75+
The `user` role, inherits all the permission from `guest` so no need to define that `user` can access `home` route, but
76+
`guest` cannot access user-specific routes.

0 commit comments

Comments
 (0)