Skip to content

Commit 02f5020

Browse files
committed
docs: add description for logging
1 parent 2424f13 commit 02f5020

File tree

3 files changed

+94
-16
lines changed

3 files changed

+94
-16
lines changed

docs/addons/jwt.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ To use JWT Authentication, you need additional setup and configuration.
3434

3535
```php
3636
<?php
37-
37+
3838
// app/Config/AuthJWT.php
39-
39+
4040
declare(strict_types=1);
4141

4242
namespace Config;
@@ -128,6 +128,19 @@ php -r 'echo base64_encode(random_bytes(32));'
128128

129129
The secret key is used for signing and validating tokens.
130130

131+
### Login Attempt Logging
132+
133+
By default, only failed login attempts are recorded in the `auth_token_logins` table.
134+
135+
```php
136+
public int $recordLoginAttempt = Auth::RECORD_LOGIN_ATTEMPT_FAILURE;
137+
```
138+
139+
If you don't want any logs, set it to `Auth::RECORD_LOGIN_ATTEMPT_NONE`.
140+
141+
If you want to log all login attempts, set it to `Auth::RECORD_LOGIN_ATTEMPT_ALL`.
142+
It means you log all requests.
143+
131144
## Issuing JWTs
132145

133146
To use JWT Authentication, you need a controller that issues JWTs.
@@ -351,3 +364,14 @@ It uses the `secret` and `alg` in the `Config\AuthJWT::$keys['default']`.
351364
It sets the `Config\AuthJWT::$defaultClaims` to the token, and sets
352365
`"iat"` (Issued At) and `"exp"` (Expiration Time) claims automatically even if
353366
you don't pass them.
367+
368+
## Logging
369+
370+
Login attempts are recorded in the `auth_token_logins` table, according to the
371+
configuration above.
372+
373+
When a failed login attempt is logged, the raw token value sent is saved in
374+
the `identifier` column.
375+
376+
When a successful login attempt is logged, the SHA256 hash value of the token
377+
sent is saved in the `identifier` column.

docs/references/authentication/hmac.md

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,6 @@ $token = $user->getHmacTokenById($id);
112112
$tokens = $user->hmacTokens();
113113
```
114114

115-
## HMAC Keys Lifetime
116-
117-
HMAC Keys/Tokens will expire after a specified amount of time has passed since they have been used.
118-
This uses the same configuration value as AccessTokens.
119-
120-
By default, this is set to 1 year. You can change this value by setting the `$unusedTokenLifetime`
121-
value in the **app/Config/AuthToken.php** config file. This is in seconds so that you can use the
122-
[time constants](https://codeigniter.com/user_guide/general/common_functions.html#time-constants)
123-
that CodeIgniter provides.
124-
125-
```php
126-
public $unusedTokenLifetime = YEAR;
127-
```
128-
129115
## HMAC Keys Scopes
130116

131117
Each token (set of keys) can be given one or more scopes they can be used within. These can be thought of as
@@ -219,3 +205,44 @@ authtoken.hmacEncryptionCurrentKey = k2
219205
Depending on the set length of the Secret Key and the type of encryption used, it is possible for the encrypted value to
220206
exceed the database column character limit of 255 characters. If this happens, creation of a new HMAC identity will
221207
throw a `RuntimeException`.
208+
209+
## Configuration
210+
211+
### HMAC Keys Lifetime
212+
213+
HMAC Keys/Tokens will expire after a specified amount of time has passed since they have been used.
214+
This uses the same configuration value as AccessTokens.
215+
216+
By default, this is set to 1 year. You can change this value by setting the `$unusedTokenLifetime`
217+
value in the **app/Config/AuthToken.php** config file. This is in seconds so that you can use the
218+
[time constants](https://codeigniter.com/user_guide/general/common_functions.html#time-constants)
219+
that CodeIgniter provides.
220+
221+
```php
222+
public $unusedTokenLifetime = YEAR;
223+
```
224+
225+
### Login Attempt Logging
226+
227+
By default, only failed login attempts are recorded in the `auth_token_logins` table.
228+
This can be modified in the **app/Config/AuthToken.php** config file.
229+
230+
```php
231+
public int $recordLoginAttempt = Auth::RECORD_LOGIN_ATTEMPT_FAILURE;
232+
```
233+
234+
If you don't want any logs, set it to `Auth::RECORD_LOGIN_ATTEMPT_NONE`.
235+
236+
If you want to log all login attempts, set it to `Auth::RECORD_LOGIN_ATTEMPT_ALL`.
237+
It means you log all requests.
238+
239+
## Logging
240+
241+
Login attempts are recorded in the `auth_token_logins` table, according to the
242+
configuration above.
243+
244+
When a failed login attempt is logged, the raw token value sent is saved in
245+
the `identifier` column.
246+
247+
When a successful login attempt is logged, the token name is saved in the
248+
`identifier` column.

docs/references/authentication/tokens.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,30 @@ if ($user->tokenCant('forums.manage')) {
125125
// do something....
126126
}
127127
```
128+
129+
## Configuration
130+
131+
### Login Attempt Logging
132+
133+
By default, only failed login attempts are recorded in the `auth_token_logins` table.
134+
This can be modified in the **app/Config/AuthToken.php** config file.
135+
136+
```php
137+
public int $recordLoginAttempt = Auth::RECORD_LOGIN_ATTEMPT_FAILURE;
138+
```
139+
140+
If you don't want any logs, set it to `Auth::RECORD_LOGIN_ATTEMPT_NONE`.
141+
142+
If you want to log all login attempts, set it to `Auth::RECORD_LOGIN_ATTEMPT_ALL`.
143+
It means you log all requests.
144+
145+
## Logging
146+
147+
Login attempts are recorded in the `auth_token_logins` table, according to the
148+
configuration above.
149+
150+
When a failed login attempt is logged, the raw token value sent is saved in
151+
the `identifier` column.
152+
153+
When a successful login attempt is logged, the token name is saved in the
154+
`identifier` column.

0 commit comments

Comments
 (0)