clauth github ↗ Get started

Docs

Run Clauth and connect your first app

Install the server, register an app, sign someone in, check their role. About 30 minutes end to end.

Concepts

Five words cover the whole model.

TermWhat it is
OrganizationA business or team. Has owners, admins, developers and members.
AppSomething people sign in to. Its key (e.g. xpenses) is the token audience.
PermissionAn action the app understands, e.g. expense.approve. Defined by the app.
RoleA named set of permissions, e.g. finance. Defined by the app.
GrantPerson × app × organization → role. Assigned in Clauth.
ℹThe rule: apps define permissions, Clauth assigns roles, apps enforce. Data rules like "only my team" stay in your app.

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
⚠Back up 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.

KeyExampleNotes
APP_URLhttps://auth.example.comWhere Clauth is served
CLAUTH_ISSUERhttps://auth.example.comGoes in every token. Changing it later means updating every app.
DB_*mysql, clauth, …Standard Laravel database settings
MAIL_*smtp, port 587Invites, resets, security emails
SESSION_DOMAIN(empty)Keep empty — required for custom sign-in domains
GOOGLE_CLIENT_ID / _SECRET…apps.googleusercontent.comOptional; 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

  1. Console › Apps › Register app. Pick a key (e.g. xpenses) — it becomes the token audience and can't change.
  2. Choose Web app, add the redirect URL (https://yourapp.com/auth/clauth/callback) and tick the organizations that use it.
  3. Copy the client secret. It's shown once; keep it in your app's environment.
  4. 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

  1. Console › App › Sign-in page › add auth.yourbrand.com.
  2. Create the TXT record Clauth shows (proves you own it) and a CNAME to your Clauth server.
  3. Once it's active, issue a certificate for it (the clauth:domains command prints hosts and nginx config).
  4. Set CLAUTH_LOGIN_URL=https://auth.yourbrand.com in 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

MethodPathUse
GET/.well-known/openid-configurationDiscovery
GET/.well-known/jwks.jsonPublic signing keys
GET/oauth/authorizeStart sign-in
POST/oauth/tokenauthorization_code, refresh_token, client_credentials
POST/oauth/revokeRevoke a token
GET/api/v1/users/{sub}Look up a person (users:read)
GET/api/v1/barClauth bar data
POST/api/v1/release-notesPost release notes (updates:write)
POST/oauth/introspectIs a token still active? (RFC 7662)
*/api/v1/…Management API — see the API reference
*/scim/v2/…SCIM 2.0 provisioning — how
POST/access/v1/evaluationAuthZEN: can this person do X? — how

Scopes & claims

ScopeGives
openidsub, required
profile / emailname, email, email_verified
clauthorgs: roles and permissions in this app, per organization
offline_accessRefresh 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

CommandDoes
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-confCustom sign-in domains and their web-server config
clauth:reset-2fa {email}Break-glass 2-step reset (audited)
clauth:orgs-purgeRemove 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.