Skip to content

Commit 003aff3

Browse files
committed
docs: vitepress conversion
1 parent c84b868 commit 003aff3

Some content is hidden

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

78 files changed

+4956
-7398
lines changed

Dockerfile

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
1-
# Basic docker based environment
2-
# Necessary to trick dokku into building the documentation
3-
# using dockerfile instead of herokuish
4-
FROM ubuntu:22.04
5-
6-
# Add basic tools
7-
RUN apt-get update && \
8-
apt-get install -y build-essential \
9-
software-properties-common \
10-
curl \
11-
git \
12-
libxml2 \
13-
libffi-dev \
14-
libssl-dev
15-
16-
# Prevent interactive timezone input
17-
ENV DEBIAN_FRONTEND=noninteractive
18-
RUN LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php && \
19-
apt-get update && \
20-
apt-get install -y php8.1-cli php8.1-mbstring php8.1-xml php8.1-zip php8.1-intl php8.1-opcache php8.1-sqlite
21-
22-
WORKDIR /code
23-
24-
VOLUME ["/code"]
25-
26-
CMD [ '/bin/bash' ]
1+
# ----------------------
2+
# 1. Build stage
3+
# ----------------------
4+
FROM node:22-alpine AS builder
5+
6+
# Git is required because docs/package.json pulls a dependency from GitHub.
7+
RUN apk add --no-cache git openssh-client
8+
9+
WORKDIR /app/docs
10+
11+
# Copy dependency manifests first to preserve Docker layer caching.
12+
COPY docs/ ./
13+
RUN npm ci
14+
15+
# Increase max-old-space-size to avoid memory issues during build
16+
ENV NODE_OPTIONS="--max-old-space-size=8192"
17+
18+
# Build the site.
19+
RUN npm run docs:build
20+
21+
# ----------------------
22+
# 2. Runtime stage (nginx)
23+
# ----------------------
24+
FROM nginx:1.27-alpine AS runner
25+
26+
# Copy built files
27+
COPY --from=builder /app/docs/.vitepress/dist /usr/share/nginx/html
28+
29+
# Expose port
30+
EXPOSE 80
31+
32+
# Health check (optional)
33+
HEALTHCHECK CMD wget --quiet --tries=1 --spider http://localhost:80/ || exit 1
34+
35+
# Start nginx
36+
CMD ["nginx", "-g", "daemon off;"]

docs.Dockerfile

Lines changed: 0 additions & 25 deletions
This file was deleted.

docs/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
*/public/
3+
.vitepress/cache
4+
.vitepress/dist

docs/.vitepress/config.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import baseConfig from '@cakephp/docs-skeleton/config'
2+
3+
import { createRequire } from "module";
4+
const require = createRequire(import.meta.url);
5+
const toc_en = require("./toc_en.json");
6+
7+
const versions = {
8+
text: "4.x",
9+
items: [
10+
{ text: "4.x (current)", link: "https://book.cakephp.org/authentication/4/en/", target: '_self' },
11+
{ text: "3.x", link: "https://book.cakephp.org/authentication/3/en/", target: '_self' },
12+
{ text: "2.x", link: "https://book.cakephp.org/authentication/2/en/", target: '_self' },
13+
],
14+
};
15+
16+
// This file contains overrides for .vitepress/config.js
17+
export default {
18+
extends: baseConfig,
19+
srcDir: 'en',
20+
title: 'Authentication plugin',
21+
description: 'Authentication - CakePHP Authentication Plugin Documentation',
22+
base: "/authentication/4/en/",
23+
rewrites: {
24+
"en/:slug*": ":slug*",
25+
},
26+
sitemap: {
27+
hostname: "https://book.cakephp.org/authentication/4/en/",
28+
},
29+
themeConfig: {
30+
socialLinks: [
31+
{ icon: "github", link: "https://github.com/cakephp/authentication" },
32+
],
33+
editLink: {
34+
pattern: "https://github.com/cakephp/authentication/edit/4.x/docs/:path",
35+
text: "Edit this page on GitHub",
36+
},
37+
sidebar: toc_en,
38+
nav: [
39+
{ text: "CakePHP Book", link: "https://book.cakephp.org/" },
40+
{ ...versions },
41+
],
42+
},
43+
substitutions: {},
44+
locales: {
45+
root: {
46+
label: "English",
47+
lang: "en",
48+
},
49+
},
50+
};

docs/.vitepress/theme/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from '@cakephp/docs-skeleton'

docs/.vitepress/toc_en.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"/": [
3+
{
4+
"text": "Getting Started",
5+
"collapsed": false,
6+
"items": [
7+
{ "text": "Quick Start", "link": "/index" }
8+
]
9+
},
10+
{
11+
"text": "Core Concepts",
12+
"collapsed": false,
13+
"items": [
14+
{ "text": "Authenticators", "link": "/authenticators" },
15+
{ "text": "Identifiers", "link": "/identifiers" },
16+
{ "text": "Identity Object", "link": "/identity-object" },
17+
{ "text": "Password Hashers", "link": "/password-hashers" }
18+
]
19+
},
20+
{
21+
"text": "Integration",
22+
"collapsed": false,
23+
"items": [
24+
{ "text": "Middleware", "link": "/middleware" },
25+
{ "text": "Authentication Component", "link": "/authentication-component" },
26+
{ "text": "View Helper", "link": "/view-helper" },
27+
{ "text": "Testing", "link": "/testing" }
28+
]
29+
},
30+
{
31+
"text": "Advanced Topics",
32+
"collapsed": true,
33+
"items": [
34+
{ "text": "User Impersonation", "link": "/impersonation" },
35+
{ "text": "Redirect Validation", "link": "/redirect-validation" },
36+
{ "text": "URL Checkers", "link": "/url-checkers" },
37+
{ "text": "Migration from the AuthComponent", "link": "/migration-from-the-authcomponent" }
38+
]
39+
},
40+
{
41+
"text": "Upgrade Guides",
42+
"collapsed": true,
43+
"items": [
44+
{ "text": "Upgrading from 2.x to 3.x", "link": "/upgrade-2-to-3" },
45+
{ "text": "Upgrading from 3.x to 4.x", "link": "/upgrade-3-to-4" }
46+
]
47+
}
48+
]
49+
}

docs/config/__init__.py

Whitespace-only changes.

docs/config/all.py

Lines changed: 0 additions & 48 deletions
This file was deleted.
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# Authentication Component
2+
3+
You can use the `AuthenticationComponent` to access the result of
4+
authentication, get user identity and logout user. Load the component in your
5+
`AppController::initialize()` like any other component:
6+
7+
``` php
8+
$this->loadComponent('Authentication.Authentication', [
9+
'logoutRedirect' => '/users/login' // Default is false
10+
]);
11+
```
12+
13+
Once loaded, the `AuthenticationComponent` will require that all actions have an
14+
authenticated user present, but perform no other access control checks. You can
15+
disable this check for specific actions using `allowUnauthenticated()`:
16+
17+
``` php
18+
// In your controller's beforeFilter method.
19+
$this->Authentication->allowUnauthenticated(['view']);
20+
```
21+
22+
## Accessing the logged in user
23+
24+
You can get the authenticated user identity data using the authentication
25+
component:
26+
27+
``` php
28+
$user = $this->Authentication->getIdentity();
29+
```
30+
31+
You can also get the identity directly from the request instance:
32+
33+
``` php
34+
$user = $request->getAttribute('identity');
35+
```
36+
37+
## Checking the login status
38+
39+
You can check if the authentication process was successful by accessing the
40+
result object:
41+
42+
``` php
43+
// Using Authentication component
44+
$result = $this->Authentication->getResult();
45+
46+
// Using request object
47+
$result = $request->getAttribute('authentication')->getResult();
48+
49+
if ($result->isValid()) {
50+
$user = $request->getAttribute('identity');
51+
} else {
52+
$this->log($result->getStatus());
53+
$this->log($result->getErrors());
54+
}
55+
```
56+
57+
The result sets objects status returned from `getStatus()` will match one of
58+
these constants in the Result object:
59+
60+
- `ResultInterface::SUCCESS`, when successful.
61+
- `ResultInterface::FAILURE_IDENTITY_NOT_FOUND`, when identity could not be found.
62+
- `ResultInterface::FAILURE_CREDENTIALS_INVALID`, when credentials are invalid.
63+
- `ResultInterface::FAILURE_CREDENTIALS_MISSING`, when credentials are missing in the request.
64+
- `ResultInterface::FAILURE_OTHER`, on any other kind of failure.
65+
66+
The error array returned by `getErrors()` contains **additional** information
67+
coming from the specific system against which the authentication attempt was
68+
made. For example LDAP or OAuth would put errors specific to their
69+
implementation in here for easier logging and debugging the cause. But most of
70+
the included authenticators don't put anything in here.
71+
72+
## Logging out the identity
73+
74+
To log an identity out just do:
75+
76+
``` php
77+
$this->Authentication->logout();
78+
```
79+
80+
If you have set the `logoutRedirect` config, `Authentication::logout()` will
81+
return that value else will return `false`. It won't perform any actual redirection
82+
in either case.
83+
84+
Alternatively, instead of the component you can also use the service to log out:
85+
86+
``` php
87+
$return = $request->getAttribute('authentication')->clearIdentity($request, $response);
88+
```
89+
90+
The result returned will contain an array like this:
91+
92+
``` php
93+
[
94+
'response' => object(Cake\Http\Response) { ... },
95+
'request' => object(Cake\Http\ServerRequest) { ... },
96+
]
97+
```
98+
99+
> [!NOTE]
100+
> This will return an array containing the request and response
101+
> objects. Since both are immutable you'll get new objects back. Depending on your
102+
> context you're working in you'll have to use these instances from now on if you
103+
> want to continue to work with the modified response and request objects.
104+
105+
## Configure Automatic Identity Checks
106+
107+
By default `AuthenticationComponent` will automatically enforce an identity to
108+
be present during the `Controller.startup` event. You can have this check
109+
applied during the `Controller.initialize` event instead:
110+
111+
``` php
112+
// In your controller's initialize() method.
113+
$this->loadComponent('Authentication.Authentication', [
114+
'identityCheckEvent' => 'Controller.initialize',
115+
]);
116+
```
117+
118+
You can also disable identity checks entirely with the `requireIdentity`
119+
option or by calling `disableIdentityCheck` from the controller's `beforeFilter()` method itself:
120+
121+
``` php
122+
$this->Authentication->disableIdentityCheck();
123+
```

0 commit comments

Comments
 (0)