Concepts
Five words cover the whole model.
| Term | What it is |
|---|---|
| Organization | A business or team. Has owners, admins, developers and members. |
| App | Something people sign in to. Its key (e.g. xpenses) is the token audience. |
| Permission | An action the app understands, e.g. expense.approve. Defined by the app. |
| Role | A named set of permissions, e.g. finance. Defined by the app. |
| Grant | Person × app × organization → role. Assigned in Clauth. |
Install the server
Requirements
- PHP 8.2 or newer (tested on 8.5) with the usual Laravel extensions
- MySQL 8 (SQLite works for local development)
- Composer, a web server pointing at
public/, and HTTPS - An SMTP account for invite and password-reset emails
Steps
# 1. Code and dependencies git clone https://github.com/wdonayre/clauth-core.git cd clauth composer install --no-dev --optimize-autoloader # 2. Environment cp .env.example .env php artisan key:generate # 3. Database php artisan migrate --force # 4. Signing keys — check, then create if none is active php artisan clauth:keys status # 5. Your first owner (gets a one-time setup link: password + 2-step) php artisan clauth:owner you@example.com --name="Your Name" # 6. Cache config for production php artisan config:cache && php artisan route:cache
Scheduler
Clauth runs housekeeping (expired tokens, deleted organizations) on Laravel's scheduler. Add one cron line:
* * * * * cd /path/to/clauth && php artisan schedule:run >> /dev/null 2>&1
APP_KEY and the database off the server. The app key decrypts the token signing keys — lose either and everyone is signed out of every app.Configuration
Everything lives in .env. Run php artisan config:cache after any change.
| Key | Example | Notes |
|---|---|---|
APP_URL | https://auth.example.com | Where Clauth is served |
CLAUTH_ISSUER | https://auth.example.com | Goes in every token. Changing it later means updating every app. |
DB_* | mysql, clauth, … | Standard Laravel database settings |
MAIL_* | smtp, port 587 | Invites, resets, security emails |
SESSION_DOMAIN | (empty) | Keep empty — required for custom sign-in domains |
GOOGLE_CLIENT_ID / _SECRET | …apps.googleusercontent.com | Optional; shows "Continue with Google" |
Google sign-in (optional)
Create an OAuth client of type Web application in Google Cloud, with one redirect URI:
https://auth.example.com/login/google/callback
Put the client ID and secret in .env and cache the config. The button appears only when both are set. Clauth stays invite-only: Google signs in people who already have an account, matched by a linked Google account or a Google-verified email. Custom sign-in domains need no extra Google setup — they hop to the main domain for the callback.
Register an app
- Console › Apps › Register app. Pick a key (e.g.
xpenses) — it becomes the token audience and can't change. - Choose Web app, add the redirect URL (
https://yourapp.com/auth/clauth/callback) and tick the organizations that use it. - Copy the client secret. It's shown once; keep it in your app's environment.
- Settings tab: add after-sign-out URLs. Sign-in page tab: logo, style, accent color.
The sign-in flow
Standard Authorization Code with PKCE. Clauth requires both PKCE (S256) and a nonce.
# 1. Send the browser to Clauth GET https://auth.example.com/oauth/authorize ?response_type=code &client_id=… &redirect_uri=https://yourapp.com/auth/clauth/callback &scope=openid%20email%20profile%20clauth &state=…&nonce=… &code_challenge=…&code_challenge_method=S256 # 2. Exchange the code on your server POST https://auth.example.com/oauth/token grant_type=authorization_code&code=…&code_verifier=… &client_id=…&client_secret=…&redirect_uri=… # 3. Verify the ID token against /.well-known/jwks.json # (iss, aud = your app key, exp, nonce), then read "orgs".
Refresh the session token at least every 15 minutes so role changes land and disabled people are signed out.
Permissions manifest
Serve this from your app. Clauth reads it when an admin syncs the app, so roles can be given in the console.
// GET https://yourapp.com/.well-known/clauth.json { "permissions": ["expense.submit", "expense.approve", "expense.view"], "roles": { "staff": ["expense.submit"], "finance": ["expense.approve", "expense.view"] } }
The Clauth bar
Every connected app shows the Clauth bar: app switcher, release notes, account, sign out. Laravel: add @clauthBar to your layout. Other stacks: load /bar/v1 and fetch /api/v1/bar through your own server with the user's token.
Custom sign-in domains
- Console › App › Sign-in page › add
auth.yourbrand.com. - Create the TXT record Clauth shows (proves you own it) and a CNAME to your Clauth server.
- Once it's active, issue a certificate for it (the
clauth:domainscommand prints hosts and nginx config). - Set
CLAUTH_LOGIN_URL=https://auth.yourbrand.comin the app. The issuer doesn't change.
Phone apps & APIs
Phone apps and SPAs sign in through your server or with PKCE as public clients, then send the access token as Authorization: Bearer …. Your API verifies it against JWKS — no call to Clauth per request. Server-to-server jobs use client_credentials with users:read or updates:write.
To manage Clauth itself from code — invite people, give access profiles, register apps, read the audit log — use the management API with an API client or a personal token.
Endpoints
| Method | Path | Use |
|---|---|---|
GET | /.well-known/openid-configuration | Discovery |
GET | /.well-known/jwks.json | Public signing keys |
GET | /oauth/authorize | Start sign-in |
POST | /oauth/token | authorization_code, refresh_token, client_credentials |
POST | /oauth/revoke | Revoke a token |
GET | /api/v1/users/{sub} | Look up a person (users:read) |
GET | /api/v1/bar | Clauth bar data |
POST | /api/v1/release-notes | Post release notes (updates:write) |
POST | /oauth/introspect | Is a token still active? (RFC 7662) |
* | /api/v1/… | Management API — see the API reference |
* | /scim/v2/… | SCIM 2.0 provisioning — how |
POST | /access/v1/evaluation | AuthZEN: can this person do X? — how |
Scopes & claims
| Scope | Gives |
|---|---|
openid | sub, required |
profile / email | name, email, email_verified |
clauth | orgs: roles and permissions in this app, per organization |
offline_access | Refresh tokens |
amr tells you how someone signed in: pwd (password), fed (Google), plus otp after a 2-step code.
{
"iss": "https://auth.example.com", "aud": "xpenses", "sub": "01JC9…",
"email": "maria@example.com", "amr": ["fed", "otp"],
"orgs": { "acme": { "roles": ["finance"], "permissions": ["expense.approve", "expense.view"] } }
}
Artisan commands
| Command | Does |
|---|---|
clauth:owner {email} --name= | Create an owner with a one-time setup link |
clauth:keys status|stage|activate --kid= | Inspect and rotate signing keys |
clauth:domains list|hosts|nginx-conf | Custom sign-in domains and their web-server config |
clauth:reset-2fa {email} | Break-glass 2-step reset (audited) |
clauth:orgs-purge | Remove organizations past their 30-day grace period |
Troubleshooting
Discovery or JWKS returns 404
Some hosting panels serve /.well-known/ as static files. Add a web-server rule that passes openid-configuration, jwks.json and clauth.json to Laravel.
Signed in on one domain but not another
Leave SESSION_DOMAIN empty so the session cookie is host-only; each sign-in domain then checks with the main domain.
Role changes don't show up
Apps see changes when they refresh the token — at most 15 minutes with the kits. Sign out and in to see it at once.
Stuck? Ask in GitHub Discussions or open an issue.