Skip to content

Commit c447c1b

Browse files
committed
Improve the authenticator docs
Was doing an update for the PrimaryKeySession authenticator deprecation and found the current docs missing information.
1 parent 377e8b6 commit c447c1b

1 file changed

Lines changed: 32 additions & 23 deletions

File tree

docs/en/authenticators.md

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,47 @@
11
# Authenticators
22

33
Authenticators handle converting request data into an authentication
4-
operations. They leverage [Identifiers](identifiers) to find a
5-
known [Identity Objects](identity-object).
4+
operation. They leverage [Identifiers](identifiers) to find a
5+
known [Identity](identity-object). During an authentication operation, each
6+
configured authenticator is called in order, until a successful result is found,
7+
or all authenticators do not accept the request.
68

79
## Session
810

9-
This authenticator will check the session if it contains user data or
10-
credentials. When using any stateful authenticators like `Form` listed
11-
below, be sure to load `Session` authenticator first so that once
12-
logged in user data is fetched from session itself on subsequent
13-
requests.
11+
This authenticator will check the session for an identity or credentials. When
12+
using any stateful authenticators like `Form` listed below, be sure to load
13+
`Session` authenticator first so that once logged in user data is fetched from
14+
session itself on subsequent requests.
1415

1516
Configuration options:
1617

17-
- **sessionKey**: The session key for the user data, default is
18-
`Auth`
18+
- **sessionKey**: The key in the session where the identity is stored. Default
19+
is `Auth`.
20+
- **identify**: Whether or not the identity should be reloaded via the linked
21+
identifier on each request. This option is deprecated in favour of using
22+
`PrimaryKeySession`.
1923

2024
## PrimaryKeySession
2125

22-
This is an improved version of Session that will only store the primary key.
23-
This way the data will always be fetched fresh from the DB and issues like
24-
having to update the identity when updating account data should be gone.
26+
This is an improved version of Session authentication that only stores the
27+
primary key of the identity. On each request, the identity is looked up via the
28+
configured identifier. This ensures that data in the request's `identity` is
29+
always current.
2530

26-
It also helps to avoid session invalidation.
27-
Session itself stores the entity object including nested objects like DateTime or enums.
28-
With only the ID stored, the invalidation due to objects being modified will also dissolve.
29-
30-
A default `TokenIdentifier` is provided that looks up users by their `id` field,
31-
so minimal configuration is required:
31+
By default a `TokenIdentifier` that looks up users by their `id` field is
32+
configured for this authenticator. The minimal configuration is required:
3233

3334
```php
3435
$service->loadAuthenticator('Authentication.PrimaryKeySession');
3536
```
3637

3738
Configuration options:
3839

39-
- **idField**: The field in the database table to look up. Default is `id`.
40-
- **identifierKey**: The key used to store/retrieve the primary key from session data.
40+
- **idField**: The field of the entity that is stored in the session under
41+
`sessionKey`.
42+
- **sessionKey**: The key in the session where the identifier is stored. Default
43+
is `Auth`.
44+
- **identifierKey**: The key used to build data used to `identify()` the user.
4145
Default is `key`.
4246

4347
For custom lookup fields, the `idField` and `identifierKey` options propagate
@@ -46,17 +50,22 @@ to the default identifier automatically:
4650
```php
4751
$service->loadAuthenticator('Authentication.PrimaryKeySession', [
4852
'idField' => 'uuid',
53+
'identifierKey' => 'key',
4954
]);
5055
```
5156

52-
You can also provide a fully custom identifier configuration if needed:
57+
This will store the ``uuid`` field of your identity objects in the session, and supply
58+
`['key' => $uuid]` to the identifier linked to `PrimaryKeySessionAuthenticator`.
59+
60+
You can customize the identifier configuration if needed:
5361

5462
```php
5563
$service->loadAuthenticator('Authentication.PrimaryKeySession', [
64+
'idField' => 'uuid',
5665
'identifier' => [
5766
'className' => 'Authentication.Token',
58-
'tokenField' => 'id',
59-
'dataField' => 'key',
67+
'tokenField' => 'uuid',
68+
'dataField' => 'token',
6069
'resolver' => 'Authentication.Orm',
6170
],
6271
]);

0 commit comments

Comments
 (0)