Quickstart
Sign someone in to a web app with Nod, in about ten minutes.
1. Run Nod
You need Rust, and PostgreSQL 15 or later (or TwilightDB). For a first look, the memory store needs nothing, but it forgets everything on exit.
git clone ssh://_lunaor_gitea@git.lunaor.com:2222/lunaor/nod.git && cd nod
cargo build --release -p nod-server
export NOD_STORE='postgres:host=localhost user=harpora dbname=harpora'
export NOD_SECRET_KEY="$(openssl rand -base64 32)" # keep this: it seals keys and secrets at rest
2. Make a realm and register your app
target/release/harpora realm create acme --name "Acme"
target/release/harpora client register acme my-web-app --confidential \
--redirect http://localhost:3000/auth/callback --post-logout http://localhost:3000/
# prints the client secret once: keep it with your app's configuration
Redirect URIs must be https, except for localhost, 127.0.0.1 and [::1] during development.
3. Serve
target/release/harpora serve --public-url http://localhost:8090 --listen 127.0.0.1:8090
Check http://localhost:8090/acme/.well-known/openid-configuration. In production, serve https, either directly with --tls-cert and --tls-key or behind a proxy that terminates TLS, and set --public-url to the https URL people use (Running Nod).
4. Sign in from your app
Any standard OpenID Connect library works. Give it the issuer (http://localhost:8090/acme), the client id and secret, the redirect URI, and the scopes openid profile email. It will use the authorization code flow with PKCE.
Node (openid-client):
import * as client from "openid-client";
const config = await client.discovery(new URL("http://localhost:8090/acme"), "my-web-app", process.env.CLIENT_SECRET);
// start: redirect the browser here, keeping code_verifier and state in the user's session
const code_verifier = client.randomPKCECodeVerifier();
const url = client.buildAuthorizationUrl(config, {
redirect_uri: "http://localhost:3000/auth/callback",
scope: "openid profile email",
code_challenge: await client.calculatePKCECodeChallenge(code_verifier),
code_challenge_method: "S256",
state: client.randomState(),
});
// callback: exchange the code
const tokens = await client.authorizationCodeGrant(config, currentUrl, { pkceCodeVerifier: code_verifier, expectedState: state });
console.log(tokens.claims()); // sub, name, email, …
Python (Authlib):
oauth.register("harpora", server_metadata_url="http://localhost:8090/acme/.well-known/openid-configuration",
client_id="my-web-app", client_secret=CLIENT_SECRET,
client_kwargs={"scope": "openid profile email", "code_challenge_method": "S256"})
The first person to arrive sees Nod's sign-in page. They choose Create an account, pick a username, and make a passkey with their device. After that, they sign in with that passkey.
5. What your app gets
- The ID token's claims:
sub(the user's id, stable: use it as your key),name,preferred_username,emailandemail_verifiedwhen known,auth_time, andacr, which says how they signed in (urn:harpora:passkey,urn:harpora:password,urn:harpora:password-otp,urn:harpora:federated). - An access token for userinfo:
GET <issuer>/userinfowithAuthorization: Bearer …. - A refresh token, for confidential clients and for
offline_access. It rotates on every use, so always store the new one.
To sign out, send the browser to <issuer>/logout?client_id=my-web-app&post_logout_redirect_uri=http://localhost:3000/.