Single sign-on¶
Email and password sign-up works with no setup. Google and GitHub sign-in each need an OAuth client from that provider, and the Jac runtime does the rest.
How the round trip works¶
sequenceDiagram
autonumber
participant B as Browser
participant A as flowline (jac run)
participant P as Google or GitHub
B->>A: GET /sso/{provider}/login?client_callback=.../auth/callback
A-->>B: 302 to the provider's consent page
B->>P: Sign in and approve
P-->>B: 302 to HOST/sso/{provider}/callback?code=...
B->>A: GET /sso/{provider}/callback
A->>P: Exchange the code for the user's email
A-->>B: 302 to /auth/callback?token=JWT
Note over B: pages/(public)/auth/callback.jac stores the token
An existing account with the same email gets the SSO identity linked to it; a
new email creates an account. Either way the browser ends on /auth/callback
with a JWT, exactly like a password login.
Register the OAuth clients¶
The redirect URL each provider must allow is the runtime's callback endpoint on your public origin:
HOST includes the scheme, for example http://localhost:8000 locally or
https://flowline.example.com in production. Register one client per origin,
or add every origin you use to the same client.
- Open https://console.cloud.google.com/apis/credentials and create an OAuth client ID of type Web application.
- Add
<HOST>/sso/google/callbackunder Authorized redirect URIs. -
Copy the client id and secret into
.env:
- Open https://github.com/settings/developers and create a New OAuth App.
- Set Authorization callback URL to
<HOST>/sso/github/callback. -
Generate a client secret and copy both values into
.env:
This OAuth app only proves who someone is. It is not the GitHub App the integration uses: the runtime discards the sign-in token, so reading issues needs its own credential. See Connect GitHub.
Restart the server after exporting the variables:
What the configuration looks like¶
[scale.sso]
host = "${HOST:-http://localhost:8000}"
client_auth_callback_url = "${HOST:-http://localhost:8000}/auth/callback"
[scale.sso.google]
client_id = "${GOOGLE_CLIENT_ID:-}"
client_secret = "${GOOGLE_CLIENT_SECRET:-}"
[scale.sso.github]
client_id = "${GITHUB_CLIENT_ID:-}"
client_secret = "${GITHUB_CLIENT_SECRET:-}"
Notes and troubleshooting¶
- Use production mode. The hot-reload dev server does not proxy
/sso, so test sign-in withjac run --no-dev main.jac. - Only configured providers get a button. The
:-fallbacks above leave an unset pair empty.components/auth/SsoButtons.jacfinds the configured providers by followingGET /sso/{provider}/callback: the runtime redirects it to[scale.sso] client_auth_callback_url, with?error=SSO_NOT_CONFIGUREDwhen that provider has no credentials. Any other error on the redirect means the provider is set up, and only then does its button render. No page load logs a4xxor5xx, and the browser remembers the answer so a return visit draws the buttons at once. - Both buttons are missing. A missing
client_auth_callback_url, or aHOSTthat does not match the origin the app is served from, breaks that redirect, so neither provider looks configured. Fix the configuration, then open the sign-in page in a new tab: a tab keeps the answer it already got. - Credentials removed while the page was open. Clicking a button checks
the login endpoint first; a
501or422shows "sign-in isn't set up on this server" instead of raw JSON in the address bar. - Why the client builds the login URL itself. The runtime's initiate
endpoint requires a
client_callbackquery parameter, which the stockjacSsoLoginhelper does not send, socomponents/auth/SsoButtons.jacbuilds/sso/<provider>/login?client_callback=<origin>/auth/callbackby hand. The runtime honours that value only for a safe loopback address and otherwise uses[scale.sso] client_auth_callback_url. redirect_uri_mismatchfrom the provider. The registered callback does not match<HOST>/sso/<provider>/callbackexactly: check the scheme, the port and a trailing slash, and thatHOSTwas exported before the server started.