Skip to content

Commit 6189f9e

Browse files
authored
Merge pull request #845 from kenjis/move-config-items
refactor: move config items
2 parents cbaa02f + cc5d01f commit 6189f9e

19 files changed

Lines changed: 156 additions & 125 deletions

File tree

UPGRADING.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
## Version 1.0.0-beta.6 to 1.0.0-beta.7
44

5-
### Install New Config AuthToken.php
5+
### Mandatory Config Changes
6+
7+
#### New Config\AuthToken
68

79
A new Config file **AuthToken.php** has been introduced. Run `php spark shield:setup`
810
again to install it into **app/Config/**, or install it manually.
@@ -11,6 +13,16 @@ Then change the default settings as necessary. When using Token authentication,
1113
the default value has been changed from all accesses to be recorded in the
1214
``token_logins`` table to only accesses that fail authentication to be recorded.
1315

16+
#### Config\Auth
17+
18+
The following items have been moved. They are no longer used and should be removed.
19+
20+
- `$authenticatorHeader` and `$unusedTokenLifetime` are moved to `Config\AuthToken`.
21+
22+
The following items have been added. Copy the properties in **src/Config/Auth.php**.
23+
24+
- `$usernameValidationRules` and `$emailValidationRules` are added.
25+
1426
## Version 1.0.0-beta.3 to 1.0.0-beta.4
1527

1628
### Important Password Changes

docs/addons/jwt.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ class LoginController extends BaseController
215215
return setting('Validation.login') ?? [
216216
'email' => [
217217
'label' => 'Auth.email',
218-
'rules' => config(AuthSession::class)->emailValidationRules,
218+
'rules' => config('Auth')->emailValidationRules,
219219
],
220220
'password' => [
221221
'label' => 'Auth.password',

docs/getting_started/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ This section describes the major Config items that are not described elsewhere.
2020

2121
### Access Token Lifetime
2222

23-
By default, Access Tokens can be used for 1 year since the last use. This can be easily modified in the **app/Config/Auth.php** config file.
23+
By default, Access Tokens can be used for 1 year since the last use. This can be easily modified in the **app/Config/AuthToken.php** config file.
2424

2525
```php
2626
public int $unusedTokenLifetime = YEAR;

docs/guides/api_hmac_keys.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ API. When making requests using HMAC keys, the token should be included in the `
1010

1111
> **Note**
1212
> By default, `$authenticatorHeader['hmac']` is set to `Authorization`. You can change this value by
13-
> setting the `$authenticatorHeader['hmac']` value in the **app/Config/Auth.php** config file.
13+
> setting the `$authenticatorHeader['hmac']` value in the **app/Config/AuthToken.php** config file.
1414
1515
Tokens are issued with the `generateHmacToken()` method on the user. This returns a
1616
`CodeIgniter\Shield\Entities\AccessToken` instance. These shared keys are saved to the database in plain text. The

docs/guides/api_tokens.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Access Tokens can be used to authenticate users for your own site, or when allowing third-party developers to access your API. When making requests using access tokens, the token should be included in the `Authorization` header as a `Bearer` token.
44

55
> **Note**
6-
> By default, `$authenticatorHeader['tokens']` is set to `Authorization`. You can change this value by setting the `$authenticatorHeader['tokens']` value in the **app/Config/Auth.php** config file.
6+
> By default, `$authenticatorHeader['tokens']` is set to `Authorization`. You can change this value by setting the `$authenticatorHeader['tokens']` value in the **app/Config/AuthToken.php** config file.
77
88
Tokens are issued with the `generateAccessToken()` method on the user. This returns a `CodeIgniter\Shield\Entities\AccessToken` instance. Tokens are hashed using a SHA-256 algorithm before being saved to the database. The access token returned when you generate it will include a `raw_token` field that contains the plain-text, un-hashed, token. You should display this to your user at once so they have a chance to copy it somewhere safe, as this is the only time this will be available. After this request, there is no way to get the raw token.
99

docs/guides/mobile_apps.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class LoginController extends BaseController
2626
$rules = setting('Validation.login') ?? [
2727
'email' => [
2828
'label' => 'Auth.email',
29-
'rules' => config('AuthSession')->emailValidationRules,
29+
'rules' => config('Auth')->emailValidationRules,
3030
],
3131
'password' => [
3232
'label' => 'Auth.password',
@@ -70,6 +70,6 @@ When making all future requests to the API, the mobile client should return the
7070

7171
> **Note**
7272
>
73-
> By default, `$authenticatorHeader['tokens']` is set to `Authorization`. You can change the header name by setting the `$authenticatorHeader['tokens']` value in the **app/Config/Auth.php** config file.
73+
> By default, `$authenticatorHeader['tokens']` is set to `Authorization`. You can change the header name by setting the `$authenticatorHeader['tokens']` value in the **app/Config/AuthToken.php** config file.
7474
>
7575
> e.g. if `$authenticatorHeader['tokens']` is set to `PersonalAccessCodes` then the mobile client should return the raw token in the `PersonalAccessCodes` header as a `Bearer` token.

docs/references/authentication/hmac.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ HMAC Keys/Tokens will expire after a specified amount of time has passed since t
117117
This uses the same configuration value as AccessTokens.
118118

119119
By default, this is set to 1 year. You can change this value by setting the `$unusedTokenLifetime`
120-
value in the `Auth` config file. This is in seconds so that you can use the
120+
value in the **app/Config/AuthToken.php** config file. This is in seconds so that you can use the
121121
[time constants](https://codeigniter.com/user_guide/general/common_functions.html#time-constants)
122122
that CodeIgniter provides.
123123

docs/references/authentication/tokens.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ $tokens = $user->accessTokens();
8181

8282
Tokens will expire after a specified amount of time has passed since they have been used.
8383
By default, this is set to 1 year. You can change this value by setting the `$unusedTokenLifetime`
84-
value in the `Auth` config file. This is in seconds so that you can use the
84+
value in the **app/Config/AuthToken.php** config file. This is in seconds so that you can use the
8585
[time constants](https://codeigniter.com/user_guide/general/common_functions.html#time-constants)
8686
that CodeIgniter provides.
8787

src/Authentication/Authenticators/AccessTokens.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ public function check(array $credentials): Result
124124
if (! array_key_exists('token', $credentials) || empty($credentials['token'])) {
125125
return new Result([
126126
'success' => false,
127-
'reason' => lang('Auth.noToken', [config('Auth')->authenticatorHeader['tokens']]),
127+
'reason' => lang(
128+
'Auth.noToken',
129+
[config('AuthToken')->authenticatorHeader['tokens']]
130+
),
128131
]);
129132
}
130133

@@ -149,7 +152,9 @@ public function check(array $credentials): Result
149152
// Hasn't been used in a long time
150153
if (
151154
$token->last_used_at
152-
&& $token->last_used_at->isBefore(Time::now()->subSeconds(config('Auth')->unusedTokenLifetime))
155+
&& $token->last_used_at->isBefore(
156+
Time::now()->subSeconds(config('AuthToken')->unusedTokenLifetime)
157+
)
153158
) {
154159
return new Result([
155160
'success' => false,
@@ -188,7 +193,9 @@ public function loggedIn(): bool
188193
$request = service('request');
189194

190195
return $this->attempt([
191-
'token' => $request->getHeaderLine(config('Auth')->authenticatorHeader['tokens']),
196+
'token' => $request->getHeaderLine(
197+
config('AuthToken')->authenticatorHeader['tokens']
198+
),
192199
])->isOK();
193200
}
194201

@@ -246,7 +253,7 @@ public function getBearerToken(): ?string
246253
/** @var IncomingRequest $request */
247254
$request = service('request');
248255

249-
$header = $request->getHeaderLine(config('Auth')->authenticatorHeader['tokens']);
256+
$header = $request->getHeaderLine(config('AuthToken')->authenticatorHeader['tokens']);
250257

251258
if (empty($header)) {
252259
return null;

src/Authentication/Authenticators/HmacSha256.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ public function check(array $credentials): Result
124124
if (! array_key_exists('token', $credentials) || $credentials['token'] === '') {
125125
return new Result([
126126
'success' => false,
127-
'reason' => lang('Auth.noToken', [config('Auth')->authenticatorHeader['hmac']]),
127+
'reason' => lang(
128+
'Auth.noToken',
129+
[config('AuthToken')->authenticatorHeader['hmac']]
130+
),
128131
]);
129132
}
130133

@@ -161,7 +164,9 @@ public function check(array $credentials): Result
161164
// Hasn't been used in a long time
162165
if (
163166
isset($token->last_used_at)
164-
&& $token->last_used_at->isBefore(Time::now()->subSeconds(config('Auth')->unusedTokenLifetime))
167+
&& $token->last_used_at->isBefore(
168+
Time::now()->subSeconds(config('AuthToken')->unusedTokenLifetime)
169+
)
165170
) {
166171
return new Result([
167172
'success' => false,
@@ -200,7 +205,9 @@ public function loggedIn(): bool
200205
$request = service('request');
201206

202207
return $this->attempt([
203-
'token' => $request->getHeaderLine(config('Auth')->authenticatorHeader['hmac']),
208+
'token' => $request->getHeaderLine(
209+
config('AuthToken')->authenticatorHeader['hmac']
210+
),
204211
])->isOK();
205212
}
206213

@@ -260,7 +267,7 @@ public function getFullHmacToken(): ?string
260267
/** @var IncomingRequest $request */
261268
$request = service('request');
262269

263-
$header = $request->getHeaderLine(config('Auth')->authenticatorHeader['hmac']);
270+
$header = $request->getHeaderLine(config('AuthToken')->authenticatorHeader['hmac']);
264271

265272
if ($header === '') {
266273
return null;

0 commit comments

Comments
 (0)