Files
Authentik/README.md
2026-05-01 18:55:17 +03:00

131 lines
3.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Million Miles Auth
Локальный POC с `Authentik` и кастомным frontend:
- регистрация пользователя на своей форме
- вход пользователя на своей форме
- Authentik используется как backend авторизации
- после входа frontend показывает данные из `id_token`
## Что в проекте
- `docker-compose.yml` поднимает `postgresql`, `redis`, `authentik`, `authentik-worker` и `frontend`
- `authentik/blueprints/mm-custom-authentication-flow.yaml` создаёт flow, provider и application
- `frontend/server.js` содержит UI и логику регистрации/входа
## Порты
- frontend: `http://localhost:3000`
- Authentik admin: `http://localhost:9000`
## Быстрый старт
```bash
docker compose up --build
```
Если нужно полностью пересобрать проект с чистыми данными:
```bash
docker compose down -v
docker compose up --build
```
Первый запуск Authentik может занять несколько минут. Нужно дождаться, пока `authentik-worker` применит blueprint.
## Удобный локальный `.env` для теста
Для быстрого ручного тестирования можно использовать такие локальные значения в `.env`:
```env
AUTHENTIK_IMAGE=docker.io/authentik/server
AUTHENTIK_TAG=2026.2.2
PG_DB=authentik
PG_USER=authentik
PG_PASS=authentik
AUTHENTIK_SECRET_KEY=change-me-local-secret
AUTHENTIK_BOOTSTRAP_EMAIL=admin@millionmiles.local
AUTHENTIK_BOOTSTRAP_PASSWORD=admin123456
AUTHENTIK_BOOTSTRAP_TOKEN=local-bootstrap-token-change-me
APP_URL=http://localhost:3000
SESSION_SECRET=local-session-secret-change-me
AUTHENTIK_PUBLIC_URL=http://localhost:9000
AUTHENTIK_INTERNAL_URL=http://host.docker.internal:9000
AUTHENTIK_API_TOKEN=local-bootstrap-token-change-me
AUTHENTIK_LOGIN_FLOW=mm-custom-authentication-flow
OIDC_CLIENT_ID=mm-custom-frontend
OIDC_CLIENT_SECRET=mm-custom-secret
OIDC_ISSUER=http://localhost:9000/application/o/mm-custom-frontend/
OIDC_REDIRECT_URI=http://localhost:3000/auth/callback
AUTH_DEBUG=false
```
## Как зайти в админку Authentik
```txt
http://localhost:9000
```
Логин администратора берётся из `.env`:
- email: значение `AUTHENTIK_BOOTSTRAP_EMAIL`
- password: значение `AUTHENTIK_BOOTSTRAP_PASSWORD`
Или
```txt
admin@millionmiles.local
admin123456
```
## Что создаётся автоматически
Blueprint создаёт:
```txt
Flow: Million Miles Custom Authentication
Slug: mm-custom-authentication-flow
OAuth2/OIDC Provider: Million Miles Custom Frontend
Application slug: mm-custom-frontend
Client ID: mm-custom-frontend
Client Secret: mm-custom-secret
Redirect URI: http://localhost:3000/auth/callback
```
## Как быстро всё протестировать
1. Открой `http://localhost:3000/register`
2. Зарегистрируй нового пользователя
3. После регистрации тебя перекинет на `/login`
4. Войди с только что созданными `email/password`
5. После успешного входа откроется `/dashboard`
6. На dashboard увидишь данные пользователя из JWT `id_token`
## Что проверить в админке
```txt
Applications -> Applications -> Million Miles
Applications -> Providers -> Million Miles Custom Frontend
Flows and Stages -> Flows -> Million Miles Custom Authentication
Directory -> Users
```
## Если OIDC provider ещё не применился
Если frontend пишет, что провайдер ещё не готов, проверь worker:
```bash
docker compose logs -f authentik-worker
```