Skip to content

Commit 57a91f8

Browse files
committed
Add Credentials Auth
1 parent 096e1f1 commit 57a91f8

File tree

18 files changed

+264
-9
lines changed

18 files changed

+264
-9
lines changed
Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
---
2+
title: Credentials
3+
description: Learn how to use the built-in Credentials Auth extension for Username/Password auth, user management, and account security features in your llms .py application
4+
---
5+
6+
The built-in [credentials](https://github.com/ServiceStack/llms/tree/main/llms/extensions/credentials) extension enables Username/Password authentication for your Application, including a Sign In page, user registration, role assignment, and account locking.
7+
8+
It provides full user management through both the CLI and a web-based Admin UI, along with account self-service for all authenticated users.
9+
10+
## Enable Credentials Auth
11+
12+
Credentials is the **default** Auth Provider (`LLMS_AUTH=credentials`) which is automatically enabled when **at least one user** has been created. If no users exist, the extension disables itself and the app runs as the **default** user without authentication.
13+
14+
## Getting Started
15+
16+
Create your **admin** user from the CLI to enable authentication, the **"admin"** username automatically gets the `Admin` role:
17+
18+
```bash
19+
llms --adduser admin
20+
# Enter password when prompted
21+
22+
# Start server
23+
llms --serve 8000
24+
```
25+
26+
When you start the server, authentication will now be enabled since at least one user exists and you'll be presented with the Sign In page.
27+
28+
<Screenshot src="/img/auth/signin.webp" alt="Sign In Page" />
29+
30+
After logging in as `admin`, you can create additional users from the **Manage Users** page which can be accessed from the user menu.
31+
32+
## UI Features
33+
34+
### User Menu
35+
36+
After signing in, the user avatar dropdown shows:
37+
38+
- **Username** and **My Account** link
39+
- **Manage Users** link (Admin only)
40+
- **Sign Out** button
41+
42+
<Screenshot src="/img/auth/manage-users.webp" alt="Manage Users Page" />
43+
44+
<Tip>Only users with the `Admin` role can access the **Manage Users** page</Tip>
45+
46+
### Manage Users (Admin only)
47+
48+
Accessible at `/admin` for users with the Admin role. Provides a table of all
49+
users showing:
50+
51+
| Column | Description |
52+
|------------|------------------------------------------|
53+
| Username | Account name |
54+
| Roles | Assigned roles (Admin badge highlighted) |
55+
| Status | Active or Locked (with lock icon) |
56+
| Created | Account creation date |
57+
| Last Login | IP address and relative timestamp |
58+
| Actions | Per-user action buttons |
59+
60+
Click **Create User** to create a new user account with password and optional `Admin` role.
61+
62+
**Available actions per user:**
63+
64+
- **Change Password** - Set a new password for any user (modal dialog)
65+
- **Lock** - Suspend the account with confirmation (not available for admins or yourself)
66+
- **Unlock** - Restore a locked account
67+
- **Delete** - Permanently remove the account with confirmation (cannot delete yourself)
68+
69+
<ScreenshotsGallery className="mb-8" gridClass="grid grid-cols-1 md:grid-cols-2 gap-4" images={{
70+
'Create User': '/img/auth/create-user.webp',
71+
'Change Password': '/img/auth/change-password.webp',
72+
'Lock User': '/img/auth/lock-user.webp',
73+
'Delete User': '/img/auth/delete-user.webp',
74+
}} />
75+
76+
### My Account
77+
78+
Accessible at `/account` for all authenticated users. Shows your profile
79+
information (avatar, username, roles) and provides a **Change Password** button
80+
that requires your current password for verification.
81+
82+
<Screenshot src="/img/auth/my-account.webp" alt="My Account Page" />
83+
84+
Users can also change their avatar by clicking on their profile picture and uploading a new image:
85+
86+
<Screenshot src="/img/auth/settings-avatar.webp" alt="Settings Page" />
87+
88+
After uploading, the new avatar is displayed across the app, including the user menu and My Account page:
89+
90+
<Screenshot src="/img/auth/my-account-avatar.webp" alt="Custom Avatar" />
91+
92+
## CLI Commands
93+
94+
All commands operate on the user store at `~/.llms/credentials/users.json`.
95+
96+
### `--adduser USERNAME`
97+
98+
Create a new user or update an existing user's password. Prompts for password
99+
with confirmation.
100+
101+
```bash
102+
# Create a regular user
103+
llms --adduser alice
104+
105+
# Create an admin (the username "admin" auto-assigns the Admin role)
106+
llms --adduser admin
107+
```
108+
109+
### `--removeuser USERNAME`
110+
111+
Delete a user and invalidate all their active sessions.
112+
113+
```bash
114+
llms --removeuser alice
115+
```
116+
117+
### `--listusers`
118+
119+
List all users with their creation date and lock status.
120+
121+
```bash
122+
llms --listusers
123+
# admin (created: 2025-03-15 10:30:00)
124+
# alice (created: 2025-03-15 11:00:00)
125+
# bob (created: 2025-03-16 09:15:00) LOCKED: Account suspended
126+
```
127+
128+
### `--lockuser [USERNAME]`
129+
130+
Lock a user account, preventing them from signing in. All active sessions are
131+
immediately invalidated. Prompts for a lock reason (defaults to "Account suspended").
132+
133+
```bash
134+
# Lock a specific user
135+
llms --lockuser bob
136+
137+
# List users with lock status (omit username)
138+
llms --lockuser
139+
```
140+
141+
### `--unlockuser USERNAME`
142+
143+
Restore access for a locked user account.
144+
145+
```bash
146+
llms --unlockuser bob
147+
```
148+
149+
## How To
150+
151+
### Set up authentication for the first time
152+
153+
```bash
154+
# 1. Create an admin user
155+
llms --adduser admin
156+
# Enter and confirm password
157+
158+
# 2. Start the server
159+
llms
160+
161+
# 3. Sign in at the web UI, then use Manage Users to create more accounts
162+
```
163+
164+
### Create multiple users from the CLI
165+
166+
```bash
167+
llms --adduser admin
168+
llms --adduser alice
169+
llms --adduser bob
170+
```
171+
172+
### Reset a user's password from the CLI
173+
174+
Re-running `--adduser` with an existing username updates their password:
175+
176+
```bash
177+
llms --adduser alice
178+
# "User 'alice' already exists. Updating password."
179+
# Enter new password
180+
```
181+
182+
### Reset a user's password from the UI
183+
184+
Sign in as an Admin, go to **Manage Users** (`/admin`), and click the key icon
185+
next to the user to open the Change Password dialog.
186+
187+
### Temporarily disable a user
188+
189+
```bash
190+
# Lock the account
191+
llms --lockuser bob
192+
# Reason: "On vacation until March"
193+
194+
# Later, restore access
195+
llms --unlockuser bob
196+
```
197+
198+
Or from the UI: go to **Manage Users**, click the lock icon next to the user,
199+
and confirm.
200+
201+
### Change your own password
202+
203+
Sign in, click your avatar, select **My Account**, and click **Change Password**.
204+
You'll need to enter your current password first.
205+
206+
### Switch to a different auth provider
207+
208+
```bash
209+
# Use GitHub OAuth instead
210+
llms --auth github_auth
211+
212+
# Or disable auth entirely
213+
llms --auth none
214+
```
215+
216+
## Password Storage
217+
218+
Passwords are never stored in plain text. Each password is hashed using **SHA-256**
219+
with a unique random salt:
220+
221+
1. A 16-byte random salt is generated via `secrets.token_hex(16)`
222+
2. The salt is prepended to the password and the combination is SHA-256 hashed
223+
3. The result is stored as `salt:hex_digest` in the `password_hash` field of `users.json`
224+
225+
Verification re-hashes the provided password with the stored salt and compares the
226+
result against the stored digest.
227+
228+
## Session Details
229+
230+
- Sessions are stored in memory and persisted to `~/.llms/credentials/sessions/`
231+
- Sessions expire after **30 days**
232+
- Sessions survive server restarts (loaded from disk on startup)
233+
- The session token is stored in an HTTP-only cookie (`llms-token`)
234+
- Locking or deleting a user immediately invalidates all their sessions

content/docs/deployment/github-oauth.mdx renamed to content/docs/authentication/github-auth.mdx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: GitHub OAuth Setup
2+
title: GitHub Auth
33
description: Secure your llms.py deployment with GitHub OAuth authentication
44
---
55

@@ -17,13 +17,26 @@ The [github_auth](https://github.com/ServiceStack/llms/tree/main/llms/extensions
1717
- ✅ Optional user access restrictions
1818
- ✅ Environment variable support
1919

20+
## Enable GitHub Auth Provider
21+
22+
GitHub Auth can either be enabled via environment `LLMS_AUTH` variable:
23+
24+
```bash
25+
export LLMS_AUTH=github_auth
26+
```
27+
28+
Or with the `--auth github_auth` flag when starting the server:
29+
30+
```bash
31+
llms --auth github_auth
32+
```
33+
2034
## Configuration
2135

2236
Create a config file at `~/.llms/users/default/github_auth/config.json`:
2337

2438
```json
2539
{
26-
"enabled": true,
2740
"client_id": "GITHUB_CLIENT_ID",
2841
"client_secret": "GITHUB_CLIENT_SECRET",
2942
"redirect_uri": "http://localhost:8000/auth/github/callback",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"title": "Authentication",
3+
"defaultOpen": true,
4+
"pages": [
5+
"credentials",
6+
"github-auth"
7+
]
8+
}

content/docs/deployment/meta.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"pages": [
55
"index",
66
"docker",
7-
"custom-build",
8-
"github-oauth"
7+
"custom-build"
98
]
109
}

content/docs/mcp/meta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"title": "Model Context Protocol",
3-
"defaultOpen": true,
3+
"defaultOpen": false,
44
"pages": [
55
"fast_mcp",
66
"gemini_gen_mcp",

content/docs/media-generation/meta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"title": "Media Generation",
3-
"defaultOpen": true,
3+
"defaultOpen": false,
44
"pages": [
55
"image-generation",
66
"audio-generation",

content/docs/meta.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
"v3",
77
"getting-started",
88
"features",
9-
"multimodal",
10-
"media-generation",
119
"extensions",
1210
"mcp",
11+
"multimodal",
12+
"media-generation",
1313
"cli",
14+
"authentication",
1415
"configuration",
1516
"deployment"
1617
]

content/docs/multimodal/meta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"title": "Multimodal",
3-
"defaultOpen": true,
3+
"defaultOpen": false,
44
"pages": [
55
"index",
66
"image",
53 KB
Loading

public/img/auth/create-user.webp

44.3 KB
Loading

0 commit comments

Comments
 (0)