Skip to content

Commit 434e5a0

Browse files
authored
Merge pull request #959 from codeigniter4/develop
1.0.0-beta.8 Ready code
2 parents 5e4ebad + f8bec97 commit 434e5a0

File tree

225 files changed

+3399
-374
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

225 files changed

+3399
-374
lines changed

.github/workflows/docs.yml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,18 @@ jobs:
99
deploy:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v4
13-
- uses: actions/setup-python@v4
12+
- name: Checkout Repository
13+
uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
- name: Setup Python
17+
uses: actions/setup-python@v4
1418
with:
1519
python-version: 3.x
16-
- run: pip3 install mkdocs-material
17-
- run: pip3 install mkdocs-git-revision-date-localized-plugin
18-
- run: pip3 install mkdocs-redirects
19-
- run: mkdocs gh-deploy --force
20+
- name: Install Dependencies
21+
run: |
22+
pip3 install mkdocs-material
23+
pip3 install mkdocs-git-revision-date-localized-plugin
24+
pip3 install mkdocs-redirects
25+
- name: Publish Shiled Documentation
26+
run: mkdocs gh-deploy --force

.github/workflows/no-merge-commits.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ name: Detect Merge Commits
22

33
on:
44
pull_request:
5+
branches:
6+
- develop
57

68
permissions:
79
contents: read

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ phpunit
6464
vendor/
6565
composer.lock
6666

67+
#-------------------------
68+
# MkDocs
69+
#-------------------------
70+
site/
71+
6772
#-------------------------
6873
# IDE / Development Files
6974
#-------------------------

.php-cs-fixer.dist.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
declare(strict_types=1);
44

5+
/**
6+
* This file is part of CodeIgniter Shield.
7+
*
8+
* (c) CodeIgniter Foundation <[email protected]>
9+
*
10+
* For the full copyright and license information, please view
11+
* the LICENSE file that was distributed with this source code.
12+
*/
13+
514
use CodeIgniter\CodingStandard\CodeIgniter4;
615
use Nexus\CsConfig\Factory;
716
use PhpCsFixer\Finder;
@@ -28,4 +37,8 @@
2837
'cacheFile' => 'build/.php-cs-fixer.cache',
2938
];
3039

31-
return Factory::create(new CodeIgniter4(), $overrides, $options)->forProjects();
40+
return Factory::create(new CodeIgniter4(), $overrides, $options)->forLibrary(
41+
'CodeIgniter Shield',
42+
'CodeIgniter Foundation',
43+
44+
);

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ and authorization purposes in web applications.
5858
* Flexible Groups-based access control (think Roles, but more flexible)
5959
* Users can be granted additional Permissions
6060

61-
See the [An Official Auth Library](https://codeigniter.com/news/shield) for more Info.
61+
See the [An Official Auth Library](https://forum.codeigniter.com/showthread.php?tid=82003) for more Info.
6262

6363
## Getting Started
6464

UPGRADING.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,72 @@
11
# Upgrade Guide
22

3+
## Version 1.0.0-beta.7 to 1.0.0-beta.8
4+
5+
### Mandatory Config Changes
6+
7+
#### Helper Autoloading
8+
9+
Helper autoloading has been changed to be done by CodeIgniter's autoloader
10+
instead of Composer.
11+
12+
So you need to update the settings. Run `php spark shield:setup` again, and the
13+
following steps will be done.
14+
15+
1. Add `auth` and `setting` to the `$helpers` array in **app/Config/Autoload.php**:
16+
17+
```php
18+
public $helpers = ['auth', 'setting'];
19+
```
20+
21+
2. Remove the following code in the `initController()` method in
22+
`**app/Controllers/BaseController.php**:
23+
24+
```php
25+
$this->helpers = array_merge($this->helpers, ['setting']);
26+
```
27+
28+
#### Config\Auth
29+
30+
The following items have been added. Copy the properties in **src/Config/Auth.php**.
31+
32+
- `permission_denied` and `group_denied` are added to `Config\Auth::$redirects`.
33+
- `permissionDeniedRedirect()` and `groupDeniedRedirect()` are added.
34+
35+
### Fix Custom Filter If extends `AbstractAuthFilter`
36+
37+
If you have written a custom filter that extends `AbstractAuthFilter`, now you need to add and implement the `redirectToDeniedUrl()` method to your custom filter.
38+
The following example is related to the above explanation for **group** filter.
39+
40+
```php
41+
/**
42+
* If the user does not belong to the group, redirect to the configured URL with an error message.
43+
*/
44+
protected function redirectToDeniedUrl(): RedirectResponse
45+
{
46+
return redirect()->to(config('Auth')->groupDeniedRedirect())
47+
->with('error', lang('Auth.notEnoughPrivilege'));
48+
}
49+
```
50+
51+
### Fix to HMAC Secret Key Encryption
52+
53+
#### Config\AuthToken
54+
55+
If you are using the HMAC authentication you need to update the encryption settings in **app/Config/AuthToken.php**.
56+
You will need to update and set the encryption key in `$hmacEncryptionKeys`. This should be set using **.env** and/or
57+
system environment variables. Instructions on how to do that can be found in the
58+
[Setting Your Encryption Key](https://codeigniter.com/user_guide/libraries/encryption.html#setting-your-encryption-key)
59+
section of the CodeIgniter 4 documentation and in [HMAC SHA256 Token Authenticator](./docs/references/authentication/hmac.md#hmac-secret-key-encryption).
60+
61+
You also may wish to adjust the default Driver `$hmacEncryptionDefaultDriver` and the default Digest
62+
`$hmacEncryptionDefaultDigest`, these currently default to `'OpenSSL'` and `'SHA512'` respectively.
63+
64+
#### Encrypt Existing Keys
65+
66+
After updating the key in `$hmacEncryptionKeys` value, you will need to run `php spark shield:hmac encrypt` in order
67+
to encrypt any existing HMAC tokens. This only needs to be run if you have existing unencrypted HMAC secretKeys in
68+
stored in the database.
69+
370
## Version 1.0.0-beta.6 to 1.0.0-beta.7
471

572
### The minimum CodeIgniter version

admin/RELEASE.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,41 +36,43 @@ the changelog.
3636

3737
## Preparation
3838

39-
* Clone **codeigniter4/shield** and resolve any necessary PRs
39+
* [ ] Clone **codeigniter4/shield** and resolve any necessary PRs
4040
```console
4141
git clone [email protected]:codeigniter4/shield.git
4242
```
43-
* Merge any Security Advisory PRs in private forks
43+
* [ ] Merge any Security Advisory PRs in private forks
4444

4545
## Process
4646

4747
> **Note** Most changes that need noting in the User Guide and docs should have
4848
> been included with their PR, so this process assumes you will not be
4949
> generating much new content.
5050

51-
* Create a new branch `release-1.x.x`
52-
* Update **src/Auth.php** with the new version number:
51+
* [ ] Create a new branch `release-1.x.x`
52+
* [ ] Update **src/Auth.php** with the new version number:
5353
`const SHIELD_VERSION = '1.x.x';`
54-
* Commit the changes with "Prep for 1.x.x release" and push to origin
55-
* Create a new PR from `release-1.x.x` to `develop`:
54+
* [ ] Commit the changes with "Prep for 1.x.x release" and push to origin
55+
* [ ] Create a new PR from `release-1.x.x` to `develop`:
5656
* Title: "Prep for 1.x.x release"
5757
* Description: "Updates version references for `1.x.x`." (plus checklist)
58-
* Let all tests run, then review and merge the PR
59-
* Create a new PR from `develop` to `master`:
58+
* [ ] Let all tests run, then review and merge the PR
59+
* [ ] Create a new PR from `develop` to `master`:
6060
* Title: "1.x.x Ready code"
6161
* Description: blank
62-
* Merge the PR
63-
* Create a new Release:
62+
* [ ] Merge the PR
63+
* [ ] Create a new Release:
6464
* Version: "v1.x.x"
6565
* Target: master
6666
* Title: "v1.x.x"
6767
* Click the "Generate release notes" button
6868
* Remove "### Others (Only for checking. Remove this category)" section
69+
* Add important notes if necessary
70+
* Add link to Upgrade Guide if necessary
6971
* Check "Create a discussion for this release"
7072
* Click the "Publish release" button
71-
* Watch for the "docs" action and verify that the user guide updated:
73+
* [ ] Watch for the "docs" action and verify that the user guide updated:
7274
* [docs](https://github.com/codeigniter4/shield/actions/workflows/docs.yml)
73-
* Fast-forward `develop` branch to catch the merge commit from `master`
75+
* [ ] Fast-forward `develop` branch to catch the merge commit from `master`
7476
(note: pushing to `develop` is restricted to administrators):
7577
```console
7678
git fetch origin
@@ -82,9 +84,9 @@ the changelog.
8284
**At this point, `master` must be merged into `develop`.** Otherwise, the
8385
GitHub-generated release note from `develop` for the next release will not be
8486
generated correctly.
85-
* Publish any Security Advisories that were resolved from private forks
87+
* [ ] Publish any Security Advisories that were resolved from private forks
8688
(note: publishing is restricted to administrators)
87-
* Announce the release on the forums and Slack channel
89+
* [ ] Announce the release on the forums and Slack channel
8890
(note: this forum is restricted to administrators):
8991
* Make a new topic in the "News & Discussion" forums:
9092
https://forum.codeigniter.com/forum-2.html

composer.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"mockery/mockery": "^1.0",
3838
"phpstan/extension-installer": "^1.3",
3939
"phpstan/phpstan-strict-rules": "^1.5",
40-
"rector/rector": "0.18.5"
40+
"rector/rector": "0.18.10"
4141
},
4242
"provide": {
4343
"codeigniter4/authentication-implementation": "1.0"
@@ -52,9 +52,6 @@
5252
"psr-4": {
5353
"CodeIgniter\\Shield\\": "src"
5454
},
55-
"files": [
56-
"src/Helpers/auth_helper.php"
57-
],
5855
"exclude-from-classmap": [
5956
"**/Database/Migrations/**"
6057
]

docs/addons/jwt.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ To use JWT Authentication, you need additional setup and configuration.
3333
2. Copy the **AuthJWT.php** from **vendor/codeigniter4/shield/src/Config/** into your project's config folder and update the namespace to `Config`. You will also need to have these classes extend the original classes. See the example below.
3434

3535
```php
36-
// new file - app/Config/AuthJWT.php
3736
<?php
3837

38+
// app/Config/AuthJWT.php
39+
3940
declare(strict_types=1);
4041

4142
namespace Config;
@@ -127,6 +128,19 @@ php -r 'echo base64_encode(random_bytes(32));'
127128

128129
The secret key is used for signing and validating tokens.
129130

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+
130144
## Issuing JWTs
131145

132146
To use JWT Authentication, you need a controller that issues JWTs.
@@ -140,7 +154,10 @@ $routes->post('auth/jwt', '\App\Controllers\Auth\LoginController::jwtLogin');
140154
```
141155

142156
```php
157+
<?php
158+
143159
// app/Controllers/Auth/LoginController.php
160+
144161
declare(strict_types=1);
145162

146163
namespace App\Controllers\Auth;
@@ -260,6 +277,7 @@ file itself:
260277
$routes->group('api', ['filter' => 'jwt'], static function ($routes) {
261278
// ...
262279
});
280+
263281
$routes->get('users', 'UserController::list', ['filter' => 'jwt']);
264282
```
265283

@@ -346,3 +364,14 @@ It uses the `secret` and `alg` in the `Config\AuthJWT::$keys['default']`.
346364
It sets the `Config\AuthJWT::$defaultClaims` to the token, and sets
347365
`"iat"` (Issued At) and `"exp"` (Expiration Time) claims automatically even if
348366
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.

0 commit comments

Comments
 (0)