Public guide
How to connect a new app to this login system
This page shows the whole setup in plain English. Start in the admin panel. Then add the login flow to your app. Follow the steps in order.
Your app sends the user here to sign in. This system checks who they are. Then it sends the user back to your app.
Before you start
Simple words
Set up a new app in the admin panel
Do this first. It gives your app the details it needs.
Go to the service area
Sign in as an admin. Open `Admin`, then open `Services`, then click `Register service`.
Enter the app name
Use a clear name people will recognise. Example: `Recipe Board`.
Enter the slug
Use a short lowercase label with hyphens only. Example: `recipe-board`.
Enter the client ID
Use a stable ID for code and settings. Example: `recipes-web`. Keep it short and clear.
Choose the app type
Pick `Confidential client` for a normal PHP app that runs on your server. Pick `Public client` only if the app cannot safely store a secret.
Add the redirect URL
Enter the page on your app that receives the user after sign-in. Example: `https://recipes.example.com/auth/callback`.
Add any extra redirect URLs
If you have a local test app too, add that as another line. Example: `http://localhost:8000/auth/callback`.
Add the role list
Enter the role names your app will use. Example: `admin`, `editor`, `user`, `viewer`.
Save the app
Click `Register service`. If the app uses a secret, the system will show it once after save.
Copy the values you need
Copy the `Client ID`. If a secret was shown, copy that too and store it in your app settings or `.env` file right away.
Keep the secret safe
Do not send the client secret to the browser. Keep it only on the server, like a database password.
Check the app is active
Open the service again and make sure its status says `active`. If it says `disabled`, switch it back on.
Give users access
Open `Users`, open the user you want, then add the new service in the `Assign service access` area.
Choose their role
Pick the role they should get in that app. Example: give one person `admin` and another person `viewer`.
Test with one real user
Before you tell everyone, test the login once with a user who has access.
Example values
Set up login on your app
Do this on the app that wants to use the shared login.
Collect the app settings
From the admin panel, copy the `Client ID`, the `Client secret` if your app has one, and the exact redirect URL you saved.
Add them to your app config
Put them in your app `.env` file or config file. Keep the secret on the server only.
Add the auth server URL
Also add the main login system URL. Example: `https://auth.example.com`.
Use the shared client library
The easiest path is to use the files in `shared-client-lib`. They already know how to start login, handle the callback, and check the user role.
Add a login button
Make a button or link that sends the user to your `/login` route. That route should call the SSO helper and send the user to the central sign-in page.
Add the callback route
Create a route like `/auth/callback`. This route receives the user after sign-in.
Handle the return from the login system
On the callback route, read the `code` and `state` values from the URL. Then pass them to the shared callback handler.
Swap the code for user details
The shared helper sends the code back to the login system from your server. It gets back the user details your app needs.
Create your app session
After the helper gives you the user details, save them in your own app session. This is what keeps the user logged in on your app.
Read the user details
Use the returned values like `email`, `name`, `role`, and `access_status` to decide what the user should see.
Allow or deny access
If `access_status` is not `active`, stop there and show a simple message. If the role is not allowed for a page, block that page too.
Protect your pages
On private pages, check that the user has a valid session before showing anything. For admin pages, also check the role.
Test with a real user
Try the full flow: click login, sign in, come back to your app, and confirm the right role is loaded.
Test a user without access
Try with a user who does not have the app assigned. Make sure they are blocked cleanly.
Test logout
Log out from your app and check that the app session is cleared. The current shared helper clears the local app session.