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
Copy file name to clipboardExpand all lines: docs/references/authentication/hmac.md
+56-1Lines changed: 56 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -97,6 +97,58 @@ You can revoke all HMAC Keys with the `revokeAllHmacTokens()` method.
97
97
$user->revokeAllHmacTokens();
98
98
```
99
99
100
+
## Expiring HMAC Keys
101
+
102
+
By default, the HMAC keys don't expire unless they meet the HMAC Keys lifetime expiration after their last used date.
103
+
104
+
HMAC keys can be set to expire through the `generateHmacToken()` method. This takes the expiration date as the $expiresAt argument. It's also possible to update an existing HMAC key using `setHmacTokenExpirationById($HmacTokenID, $expiresAt)`
105
+
106
+
`$expiresAt` Accepts DateTime string formatted as 'Y-m-d h:i:s' or [DateTime relative formats](https://www.php.net/manual/en/datetime.formats.php#datetime.formats.relative) unit symbols (1 day, 2 weeks, 6 months, 1 year) to be added to DateTime 'now'
`hasHmacTokenExpired(AccessToken $HmacToken)` - Checks if the given HMAC key has expired. Returns `true` if the HMAC key has expired, `false` if not, and `null` if the expire date is null.
`getHmacTokenTimeToExpire(AccessToken $accessToken, string $format = "date" | "human")` - Checks if the given HMAC key has expired. Returns `true` if HMAC key has expired, `false` if not, and `null` if the expire date is not set.
$this->user->getHmacTokenTimeToExpire($token, 'human'); // in 1 year
144
+
```
145
+
146
+
You can also easily set all existing HMAC keys/tokens as expired with the `spark` command:
147
+
```
148
+
php spark shield:hmac expireAll
149
+
```
150
+
**Careful!** This command 'expires' _all_ keys for _all_ users.
151
+
100
152
## Retrieving HMAC Keys
101
153
102
154
The following methods are available to help you retrieve a user's HMAC keys:
@@ -217,7 +269,7 @@ Configure **app/Config/AuthToken.php** for your needs.
217
269
218
270
### HMAC Keys Lifetime
219
271
220
-
HMAC Keys/Tokens will expire after a specified amount of time has passed since they have been used.
272
+
HMAC Keys will expire after a specified amount of time has passed since they have been used.
221
273
222
274
By default, this is set to 1 year. You can change this value by setting the `$unusedTokenLifetime`
223
275
value. This is in seconds so that you can use the
@@ -228,6 +280,9 @@ that CodeIgniter provides.
228
280
public $unusedTokenLifetime = YEAR;
229
281
```
230
282
283
+
### HMAC Keys Expiration vs Lifetime
284
+
Expiration and Lifetime are different concepts. The lifetime is the maximum time allowed for the HMAC Key to exist since its last use. HMAC Key expiration, on the other hand, is a set date in which the HMAC Key will cease to function.
285
+
231
286
### Login Attempt Logging
232
287
233
288
By default, only failed login attempts are recorded in the `auth_token_logins` table.
Copy file name to clipboardExpand all lines: docs/references/authentication/tokens.md
+51-1Lines changed: 51 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -125,7 +125,7 @@ Configure **app/Config/AuthToken.php** for your needs.
125
125
126
126
### Access Token Lifetime
127
127
128
-
Tokens will expire after a specified amount of time has passed since they have been used.
128
+
Tokens will expire after a specified amount of time has passed since they last have been used.
129
129
130
130
By default, this is set to 1 year.
131
131
You can change this value by setting the `$unusedTokenLifetime` value. This is
@@ -137,6 +137,56 @@ that CodeIgniter provides.
137
137
public $unusedTokenLifetime = YEAR;
138
138
```
139
139
140
+
141
+
## Expiring Access Tokens
142
+
143
+
By default, the Access Tokens don't expire unless they meet the Access Token lifetime expiration after their last used date.
144
+
145
+
Access Tokens can be set to expire through the `generateAccessToken()` method. This takes the expiration date as the $expiresAt argument. It's also possible to update an existing HMAC key using `setAccessTokenById($HmacTokenID, $expiresAt)`
146
+
147
+
`$expiresAt` Accepts DateTime string formatted as 'Y-m-d h:i:s' or [DateTime relative formats](https://www.php.net/manual/en/datetime.formats.php#datetime.formats.relative) unit symbols (1 day, 2 weeks, 6 months, 1 year) to be added to DateTime 'now'
`hasAccessTokenExpired(AccessToken $accessToken)` - Checks if the given Access Token has expired. Returns `true` if the Access Token has expired, `false` if not, and `null` if the expire date is not set.
`getAccessTokenTimeToExpire(AccessToken $accessToken, string $format = "date" | "human")` - Checks if the given Access Token has expired. Returns `true` if Access Token has expired, `false` if not, and `null` if the expire date is null.
$this->user->getAccessTokenTimeToExpire($token, 'human'); // in 1 year
185
+
```
186
+
187
+
### Access Token Expiration vs Lifetime
188
+
Expiration and Lifetime are different concepts. The lifetime is the maximum time allowed for the token to exist since its last use. Token expiration, on the other hand, is a set date in which the Access Token will cease to function.
189
+
140
190
### Login Attempt Logging
141
191
142
192
By default, only failed login attempts are recorded in the `auth_token_logins` table.
0 commit comments