Skip to content

Commit dfd100b

Browse files
authored
Merge pull request #779 from cakephp/doc-validation-workflow
Add doc validation workflow + fix linting errors
1 parent aedb109 commit dfd100b

18 files changed

+152
-126
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Documentation Validation
2+
3+
on:
4+
push:
5+
branches:
6+
- 4.x
7+
paths:
8+
- 'docs/**'
9+
- '.github/**'
10+
pull_request:
11+
paths:
12+
- 'docs/**'
13+
- '.github/**'
14+
15+
jobs:
16+
validate:
17+
uses: cakephp/.github/.github/workflows/docs-validation.yml@doc-workflows
18+
with:
19+
docs-path: 'docs'
20+
vitepress-path: 'docs/.vitepress'
21+
enable-config-js-check: true
22+
enable-json-lint: true
23+
enable-toc-check: true
24+
enable-spell-check: true
25+
enable-markdown-lint: true
26+
enable-link-check: true
27+
tools-ref: 'doc-workflows'

docs/en/authentication-component.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ You can use the `AuthenticationComponent` to access the result of
44
authentication, get user identity and logout user. Load the component in your
55
`AppController::initialize()` like any other component:
66

7-
``` php
7+
```php
88
$this->loadComponent('Authentication.Authentication', [
99
'logoutRedirect' => '/users/login' // Default is false
1010
]);
@@ -14,7 +14,7 @@ Once loaded, the `AuthenticationComponent` will require that all actions have an
1414
authenticated user present, but perform no other access control checks. You can
1515
disable this check for specific actions using `allowUnauthenticated()`:
1616

17-
``` php
17+
```php
1818
// In your controller's beforeFilter method.
1919
$this->Authentication->allowUnauthenticated(['view']);
2020
```
@@ -24,13 +24,13 @@ $this->Authentication->allowUnauthenticated(['view']);
2424
You can get the authenticated user identity data using the authentication
2525
component:
2626

27-
``` php
27+
```php
2828
$user = $this->Authentication->getIdentity();
2929
```
3030

3131
You can also get the identity directly from the request instance:
3232

33-
``` php
33+
```php
3434
$user = $request->getAttribute('identity');
3535
```
3636

@@ -39,7 +39,7 @@ $user = $request->getAttribute('identity');
3939
You can check if the authentication process was successful by accessing the
4040
result object:
4141

42-
``` php
42+
```php
4343
// Using Authentication component
4444
$result = $this->Authentication->getResult();
4545

@@ -73,7 +73,7 @@ the included authenticators don't put anything in here.
7373

7474
To log an identity out just do:
7575

76-
``` php
76+
```php
7777
$this->Authentication->logout();
7878
```
7979

@@ -83,13 +83,13 @@ in either case.
8383

8484
Alternatively, instead of the component you can also use the service to log out:
8585

86-
``` php
86+
```php
8787
$return = $request->getAttribute('authentication')->clearIdentity($request, $response);
8888
```
8989

9090
The result returned will contain an array like this:
9191

92-
``` php
92+
```php
9393
[
9494
'response' => object(Cake\Http\Response) { ... },
9595
'request' => object(Cake\Http\ServerRequest) { ... },
@@ -108,7 +108,7 @@ By default `AuthenticationComponent` will automatically enforce an identity to
108108
be present during the `Controller.startup` event. You can have this check
109109
applied during the `Controller.initialize` event instead:
110110

111-
``` php
111+
```php
112112
// In your controller's initialize() method.
113113
$this->loadComponent('Authentication.Authentication', [
114114
'identityCheckEvent' => 'Controller.initialize',
@@ -118,6 +118,6 @@ $this->loadComponent('Authentication.Authentication', [
118118
You can also disable identity checks entirely with the `requireIdentity`
119119
option or by calling `disableIdentityCheck` from the controller's `beforeFilter()` method itself:
120120

121-
``` php
121+
```php
122122
$this->Authentication->disableIdentityCheck();
123123
```

docs/en/authenticators.md

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ With only the ID stored, the invalidation due to objects being modified will als
3030
A default `TokenIdentifier` is provided that looks up users by their `id` field,
3131
so minimal configuration is required:
3232

33-
``` php
33+
```php
3434
$service->loadAuthenticator('Authentication.PrimaryKeySession');
3535
```
3636

@@ -43,15 +43,15 @@ Configuration options:
4343
For custom lookup fields, the `idField` and `identifierKey` options propagate
4444
to the default identifier automatically:
4545

46-
``` php
46+
```php
4747
$service->loadAuthenticator('Authentication.PrimaryKeySession', [
4848
'idField' => 'uuid',
4949
]);
5050
```
5151

5252
You can also provide a fully custom identifier configuration if needed:
5353

54-
``` php
54+
```php
5555
$service->loadAuthenticator('Authentication.PrimaryKeySession', [
5656
'identifier' => [
5757
'Authentication.Token' => [
@@ -109,7 +109,7 @@ Configuration options:
109109

110110
An example of getting a token from a header, or query string would be:
111111

112-
``` php
112+
```php
113113
$service->loadAuthenticator('Authentication.Token', [
114114
'queryParam' => 'token',
115115
'header' => 'Authorization',
@@ -122,7 +122,7 @@ as long as the token was preceded by `Token` and a space.
122122

123123
The token will always be passed to the configured identifier as follows:
124124

125-
``` php
125+
```php
126126
[
127127
'token' => '{token-value}',
128128
]
@@ -158,7 +158,7 @@ the value of `Cake\Utility\Security::salt()` as encryption key.
158158
For enhanced security one can instead use the `RS256` asymmetric key algorithm.
159159
You can generate the required keys for that as follows:
160160

161-
``` text
161+
```text
162162
# generate private key
163163
openssl genrsa -out config/jwt.key 1024
164164
# generate public key
@@ -175,7 +175,7 @@ for token verification.
175175

176176
Add the following to your `Application` class:
177177

178-
``` php
178+
```php
179179
public function getAuthenticationService(ServerRequestInterface $request): AuthenticationServiceInterface
180180
{
181181
$service = new AuthenticationService();
@@ -193,7 +193,7 @@ public function getAuthenticationService(ServerRequestInterface $request): Authe
193193

194194
In your `UsersController`:
195195

196-
``` php
196+
```php
197197
use Firebase\JWT\JWT;
198198

199199
public function login(): void
@@ -221,7 +221,7 @@ public function login(): void
221221

222222
Using a JWKS fetched from an external JWKS endpoint is supported as well:
223223

224-
``` php
224+
```php
225225
// Application.php
226226
public function getAuthenticationService(ServerRequestInterface $request): AuthenticationServiceInterface
227227
{
@@ -257,7 +257,7 @@ prepared to handle signing key rotations.
257257
Beside from sharing the public key file to external application, you can
258258
distribute it via a JWKS endpoint by configuring your app as follows:
259259

260-
``` php
260+
```php
261261
// config/routes.php
262262
$builder->setExtensions('json');
263263
$builder->connect('/.well-known/{controller}', [
@@ -375,7 +375,7 @@ after their session expires for as long as the cookie is valid. If a user is
375375
explicitly logged out via `AuthenticationComponent::logout()` the
376376
authentication cookie is **also destroyed**. An example configuration would be:
377377

378-
``` php
378+
```php
379379
// In Application::getAuthenticationService()
380380

381381
// Reuse fields in multiple authenticators.
@@ -404,7 +404,7 @@ $service->loadAuthenticator('Authentication.Cookie', [
404404

405405
You'll also need to add a checkbox to your login form to have cookies created:
406406

407-
``` php
407+
```php
408408
// In your login view
409409
<?= $this->Form->control('remember_me', ['type' => 'checkbox']);
410410
```
@@ -420,7 +420,7 @@ environment variables exposed by the webserver. This enables authentication via
420420
[Shibboleth](https://shibboleth.atlassian.net/wiki/spaces/CONCEPT/overview)
421421
and similar SAML 1.1 implementations. An example configuration is:
422422

423-
``` php
423+
```php
424424
// Configure a token identifier that maps `USER_ID` to the
425425
// username column
426426
$identifier = [
@@ -442,7 +442,6 @@ $service->loadAuthenticator('Authentication.Environment', [
442442
]);
443443
```
444444

445-
446445
## Events
447446

448447
There is only one event that is fired by authentication:
@@ -505,7 +504,7 @@ page](url-checkers).
505504
After a user has been authenticated you may want to inspect or interact with the
506505
Authenticator that successfully authenticated the user:
507506

508-
``` php
507+
```php
509508
// In a controller action
510509
$service = $this->request->getAttribute('authentication');
511510

@@ -515,7 +514,7 @@ $authenticator = $service->getAuthenticationProvider();
515514

516515
You can also get the identifier that identified the user as well:
517516

518-
``` php
517+
```php
519518
// In a controller action
520519
$service = $this->request->getAttribute('authentication');
521520

@@ -530,7 +529,7 @@ you should remember that these authenticators will halt the request when
530529
authentication credentials are missing or invalid. This is necessary as these
531530
authenticators must send specific challenge headers in the response:
532531

533-
``` php
532+
```php
534533
use Authentication\AuthenticationService;
535534

536535
// Instantiate the service
@@ -569,7 +568,7 @@ authenticated. You can convert this exception into a redirect using the
569568
You can also pass the current request target URI as a query parameter
570569
using the `queryParam` option:
571570

572-
``` php
571+
```php
573572
// In the getAuthenticationService() method of your src/Application.php
574573

575574
$service = new AuthenticationService();
@@ -584,7 +583,7 @@ $service->setConfig([
584583
Then in your controller's login method you can use `getLoginRedirect()` to get
585584
the redirect target safely from the query string parameter:
586585

587-
``` php
586+
```php
588587
public function login(): ?\Cake\Http\Response
589588
{
590589
$result = $this->Authentication->getResult();
@@ -613,7 +612,7 @@ authentication for your API, but sessions for your web interface. To support
613612
this flow you can return different authentication services based on the URL
614613
path, or any other request attribute:
615614

616-
``` php
615+
```php
617616
public function getAuthenticationService(
618617
ServerRequestInterface $request
619618
): AuthenticationServiceInterface {

docs/en/contents.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Contents
22

3-
### CakePHP Authentication
3+
## CakePHP Authentication
44

55
- [Quick Start](index)
66
- [Authenticators](authenticators)

docs/en/identifiers.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Identifiers will identify a user or service based on the information
44
that was extracted from the request by the authenticators. A holistic example of
55
using the Password Identifier looks like:
66

7-
``` php
7+
```php
88
$identifier = [
99
'Authentication.Password' => [
1010
'fields' => [
@@ -118,7 +118,7 @@ Configuration options:
118118

119119
Callback identifiers can either return `null|ArrayAccess` for simple results, or an `Authentication\Authenticator\Result` if you want to forward error messages:
120120

121-
``` php
121+
```php
122122
// A simple callback identifier
123123
$identifier = [
124124
'Authentication.Callback' => [
@@ -185,7 +185,7 @@ reside under `App\Identifier\Resolver` namespace.
185185

186186
Resolver can be configured using `resolver` config option:
187187

188-
``` php
188+
```php
189189
$identifier = [
190190
'Authentication.Password' => [
191191
'resolver' => [
@@ -200,7 +200,7 @@ $identifier = [
200200

201201
Or pass the constructed resolver directly into the identifier configuration:
202202

203-
``` php
203+
```php
204204
$resolver = new \App\Identifier\Resolver\CustomResolver();
205205
$identifier = [
206206
'Authentication.Password' => [

docs/en/identity-object.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ called to get the primary id value of the current log in identity.
77
The reason this object exists is to provide an interface that makes it
88
implementations/sources:
99

10-
``` php
10+
```php
1111
// Service
1212
$authenticationService
1313
->getIdentity()
@@ -28,7 +28,7 @@ The identity object provides ArrayAccess but as well a `get()` method to
2828
access data. It is strongly recommended to use the `get()` method over array
2929
access because the get method is aware of the field mapping:
3030

31-
``` php
31+
```php
3232
$identity->get('email');
3333
$identity->get('username');
3434
```
@@ -38,7 +38,7 @@ The `get()` method can also be type-hinted via IDE meta file, e.g. through
3838

3939
If you want, you can use property access, however:
4040

41-
``` text
41+
```text
4242
$identity->email;
4343
$identity->username;
4444
```
@@ -48,7 +48,7 @@ is pretty useful if the identifier of the identity is a non-conventional
4848
`id` field or if you want to map other fields to more generic and
4949
common names:
5050

51-
``` php
51+
```php
5252
$identity = new Identity($data, [
5353
'fieldMap' => [
5454
'id' => 'uid',
@@ -69,7 +69,7 @@ create your own identity object, your object must implement the
6969
If you’d like to continue using your existing User class with this
7070
plugin you can implement the `Authentication\IdentityInterface`:
7171

72-
``` php
72+
```php
7373
namespace App\Model\Entity;
7474

7575
use Authentication\IdentityInterface;
@@ -103,7 +103,7 @@ If your identifiers cannot have their resulting objects modified to
103103
implement the `IdentityInterface` you can implement a custom decorator
104104
that implements the required interface:
105105

106-
``` php
106+
```php
107107
// You can use a callable...
108108
$identityResolver = function ($data) {
109109
return new MyCustomIdentity($data);

0 commit comments

Comments
 (0)