Ferdigheter · Tilgang og sikkerhet
Sign in with your organisation
Let an app sign people in itself with OpenID Connect against the organisation's accounts, read the SKYBU_OIDC_* variables, handle the callback, and use sub, skybu_role and groups.
In this access mode the app gets its own OpenID Connect client in Skybu and signs people in itself, with any standard OIDC library. Skybu puts nothing in front of the app: pages the app does not protect are open, webhooks reach it, and the app decides what needs sign-in. People sign in with their account in the organisation, which for an organisation with single sign-on is their Entra ID or Google Workspace account. Members of the organisation and the app's guests get in; nobody else does.
Use it when the app has public and signed-in pages, takes calls from other systems, needs a stable user id, roles or groups, or keeps its own session. When every page is for staff and the app needs no code, members-only is simpler (skill://access/members-only-apps). For customers or anyone else outside the organisation, use Better Auth in the app (skill://playbooks/add-login).
In short
get_app_accessto see the app's mode now.- An owner turns it on:
set_app_accesswith"access": "app". - Read
SKYBU_OIDC_ISSUER,SKYBU_OIDC_CLIENT_ID,SKYBU_OIDC_CLIENT_SECRETandSKYBU_OIDC_REDIRECT_URIin the app. - Add
/login, the callback route and/logout, with authorization code and PKCE. Validate the ID token. - Key users on
sub, never on email. Checkskybu_roleandgroupswhere the app needs them. - Deploy and sign in on a preview or the app's address.
localhostis not a valid callback.
Step 1: what the app uses now
{ "name": "get_app_access", "arguments": { "appId": "<app id>" } }
{
"access": "app",
"organisation": "public",
"effective": "app",
"allowed": null,
"signIn": {
"configured": true,
"issuer": "https://platform.skybu.no",
"clientId": "skybu-app-<app id>",
"redirectUri": "https://timeliste.nordlys.skybu.app/auth/callback",
"redirectUris": ["https://timeliste.nordlys.skybu.app/auth/callback"],
"callbacks": ["/auth/callback"],
"offlineAccess": false,
"rotatedAt": null,
"previousSecretValidUntil": null
}
}
| Field | Meaning |
|---|---|
access | The app's own setting: public, members, app, or null when it follows the organisation. |
organisation | The organisation's default: public or members. app is only set per app. |
effective | What applies now. This is the one that counts. |
allowed | The groups and people the app is limited to, or null for every member (skill://access/guests-and-groups). |
signIn | Only in app mode: the client id, issuer, the exact redirect URIs, callback paths and whether refresh tokens are on. configured: false means the installation cannot give the app its variables yet. |
Step 2: turning it on
Only owners of the organisation can change who may open an app. With an owner's connection and projects:write:
{
"name": "set_app_access",
"arguments": { "appId": "<app id>", "access": "app", "signInCallbacks": ["/auth/callback"], "offlineAccess": false }
}
| Argument | Meaning |
|---|---|
access | public, members, app, or inherit to follow the organisation. |
signInCallbacks | 1 to 5 paths on the app's own addresses, each starting with /, without ? or #. The first becomes SKYBU_OIDC_REDIRECT_URI. Default /auth/callback. |
offlineAccess | true gives refresh tokens to an app that asks for offline_access. Off by default. |
The answer is the same as get_app_access. If the user is not an owner, it is refused (owner_only); tell them to ask one, or to use the app's Settings tab in the dashboard ("Hvem kan åpne appen" → "Logg inn med organisasjonen") or skybu app access <app> app --callback /auth/callback. Other refusals: invalid_sign_in_callbacks, invalid_offline_access, and sign_in_needs_https on an installation where Skybu itself is not on HTTPS.
Step 3: the variables
The app (and its previews) gets these at runtime. They are not in list_env_vars, and set_env_vars refuses names starting with SKYBU_ (reserved_env_name).
| Variable | Value |
|---|---|
SKYBU_OIDC_ISSUER | The issuer, https://platform.skybu.no. Discovery is at /.well-known/openid-configuration under it. |
SKYBU_OIDC_CLIENT_ID | skybu-app-<app id>. Previews use their app's client. |
SKYBU_OIDC_CLIENT_SECRET | The client secret. |
SKYBU_OIDC_REDIRECT_URI | The app's own Skybu address (a preview's own) with the first callback path. |
You never need to see the secret: the code reads it from the environment. There is no agent tool to read or rotate it. A person can read it with skybu app credentials <app> or in the dashboard; every read is logged (app.sign_in_secret_read). An owner rotates it with skybu app rotate <app> or "Lag ny hemmelighet": the app restarts with the new one and the old one keeps working for 24 hours.
Step 4: the protocol
Point the library at SKYBU_OIDC_ISSUER and let it discover the rest.
- Authorization code flow with PKCE (
S256) is required. Sendstateandnonceas well. - The secret may go as
client_secret_basicorclient_secret_post; libraries differ and both work. - There is no consent page.
- Do not send
resource: app clients are refused withinvalid_target. - Redirect URIs are exactly the app's addresses (its Skybu address, verified custom domains, previews' addresses) times the callback paths.
signIn.redirectUrislists them. A custom domain is in the list, butSKYBU_OIDC_REDIRECT_URIuses the Skybu address, so an app served on its own domain builds the redirect URI from that domain and the path. - After sign-out Skybu sends people back only to one of the addresses with
/.
Scopes and what they give, in the ID token and from userinfo:
| Scope | Claims |
|---|---|
openid | sub |
email | email, email_verified |
profile | name |
organisation | skybu_org ({ id, name, slug }), skybu_role: owner, member or guest |
groups | groups: display names of the person's groups from SCIM; an empty list when there are none |
offline_access | A refresh token, only when offlineAccess is on |
Ask for openid email profile organisation groups, and add offline_access only when refresh tokens are on.
Token lifetimes: ID and access tokens last 15 minutes. The access token is opaque and only good for userinfo; the ID token is the JWT, with aud = the client id. A refresh token lasts at most 12 hours after sign-in; after that the person signs in again.
Step 5: a Node app with openid-client
package.json dependencies, as in Skybu's own example app:
{ "express": "5.2.1", "openid-client": "6.9.1" }
server.js. The session is a signed cookie, keyed from the client secret so it needs no other variable:
import { createHmac, timingSafeEqual } from "node:crypto";
import express from "express";
import * as oidc from "openid-client";
const ISSUER = process.env.SKYBU_OIDC_ISSUER;
const CLIENT_ID = process.env.SKYBU_OIDC_CLIENT_ID;
const CLIENT_SECRET = process.env.SKYBU_OIDC_CLIENT_SECRET;
const REDIRECT_URI = process.env.SKYBU_OIDC_REDIRECT_URI;
const SCOPE = "openid email profile organisation groups";
const COOKIE_KEY = createHmac("sha256", CLIENT_SECRET ?? "").update("session-cookie").digest();
const SESSION_HOURS = 8;
let config;
async function client() {
config ??= await oidc.discovery(new URL(ISSUER), CLIENT_ID, CLIENT_SECRET);
return config;
}
function seal(value) {
const body = Buffer.from(JSON.stringify(value)).toString("base64url");
return `${body}.${createHmac("sha256", COOKIE_KEY).update(body).digest("base64url")}`;
}
function unseal(sealed) {
const [body, mac] = (sealed ?? "").split(".");
if (!body || !mac) return null;
const wanted = Buffer.from(createHmac("sha256", COOKIE_KEY).update(body).digest("base64url"));
const given = Buffer.from(mac);
if (wanted.length !== given.length || !timingSafeEqual(wanted, given)) return null;
return JSON.parse(Buffer.from(body, "base64url").toString());
}
const cookie = (req, name) => req.headers.cookie?.split(";").map((part) => part.trim()).find((part) => part.startsWith(`${name}=`))?.slice(name.length + 1);
const setCookie = (res, name, value, seconds) => res.cookie(name, value, { httpOnly: true, secure: true, sameSite: "lax", maxAge: seconds * 1000 });
function currentUser(req) {
const session = unseal(cookie(req, "session"));
return session && session.expiresAt > Date.now() ? session : null;
}
const app = express();
app.get("/login", async (_req, res) => {
const verifier = oidc.randomPKCECodeVerifier();
const state = oidc.randomState();
const nonce = oidc.randomNonce();
const url = oidc.buildAuthorizationUrl(await client(), {
redirect_uri: REDIRECT_URI,
scope: SCOPE,
code_challenge: await oidc.calculatePKCECodeChallenge(verifier),
code_challenge_method: "S256",
state,
nonce,
});
setCookie(res, "sign-in", seal({ verifier, state, nonce }), 600);
res.redirect(url.href);
});
app.get(new URL(REDIRECT_URI).pathname, async (req, res) => {
const pending = unseal(cookie(req, "sign-in"));
if (!pending) return res.redirect("/login");
const tokens = await oidc.authorizationCodeGrant(await client(), new URL(req.originalUrl, REDIRECT_URI), {
pkceCodeVerifier: pending.verifier,
expectedState: pending.state,
expectedNonce: pending.nonce,
});
const claims = tokens.claims();
const user = { id: claims.sub, email: claims.email, name: claims.name, role: claims.skybu_role, groups: claims.groups ?? [] };
setCookie(res, "sign-in", "", 0);
setCookie(res, "session", seal({ user, idToken: tokens.id_token, expiresAt: Date.now() + SESSION_HOURS * 3600 * 1000 }), SESSION_HOURS * 3600);
res.redirect("/");
});
app.get("/logout", async (req, res) => {
const session = currentUser(req);
setCookie(res, "session", "", 0);
if (!session) return res.redirect("/");
const url = oidc.buildEndSessionUrl(await client(), {
id_token_hint: session.idToken,
post_logout_redirect_uri: new URL("/", REDIRECT_URI).href,
});
res.redirect(url.href);
});
app.use("/app", (req, res, next) => {
const session = currentUser(req);
if (!session) return res.redirect("/login");
req.user = session.user;
next();
});
app.get("/app/me", (req, res) => res.json(req.user));
app.listen(Number(process.env.PORT ?? 3000));
authorizationCodeGrantchecksiss,aud, expiry andnoncein the ID token. The token comes straight from Skybu over TLS, so openid-client does not check its signature by default; calloidc.enableNonRepudiationChecks(config)after discovery if you also want the JWKS check.tokens.claims()is the validated ID token.oidc.fetchUserInfo(config, tokens.access_token, claims.sub)returns the same claims from userinfo within the access token's 15 minutes.- The session cookie holds the ID token for logout. Keep it
HttpOnlyandSecure; Skybu ends TLS before the app, so the browser sees HTTPS.
Step 6: who the user is
- Key users on
sub. It is the same for a person in every app of the organisation, different in other organisations' apps, never the Skybu account id, and it stays when the person's email changes. Store it as the owner of the user's rows; never key on email. skybu_roleisowner,memberorguest. A guest is someone outside the organisation an owner invited to this app;skybu_orgis still the app's organisation. Decide what guests may see.groupscomes from Entra ID through SCIM. Compare display names the user gives you ("Lønn"), and expect an empty list in organisations without SCIM groups.list_groupsshows the organisation's groups.- To keep people out entirely rather than in code, an owner limits the app to groups or people (
skill://access/guests-and-groups).
Step 7: refresh and logout
Refresh tokens only exist when an owner has set offlineAccess: true and the app asked for offline_access:
const renewed = await oidc.refreshTokenGrant(await client(), refreshToken);
Each refresh token lasts at most 12 hours after the original sign-in. Turning offlineAccess off revokes those given. Without refresh tokens, send the user through /login again when the app wants fresh claims; their Skybu session usually makes that a redirect without a form.
Logout goes to end_session_endpoint from discovery with id_token_hint and a post_logout_redirect_uri that is one of the app's addresses with / (above). That ends the Skybu session. The app ends its own session itself; Skybu cannot.
Other stacks
Any standard OpenID Connect client works: set the issuer (or discovery URL <issuer>/.well-known/openid-configuration), client id, client secret and redirect URI from the variables, response type code, PKCE S256, and the scopes above. Only openid-client is exercised by Skybu's own tests; tell the user when a library is untested here.
Things to know
- The app must exist before it can change access: deploy it once first (
skill://apps/deploy-an-app). - Test sign-in on a preview or the app's address; callbacks on
localhostare refused. - When someone is removed from the organisation (by an owner, by SCIM, or by deleting their account), Skybu deletes their access and refresh tokens for every app of the organisation. A session the app gave them stays until it expires, so keep app sessions reasonably short.
- An owner can switch back to
membersorpublicat any time; switching back toapplater gives the samesubs. - Every change is in the audit log:
app.access_changed,app.sign_in_enabled,app.sign_in_changed,app.sign_in_secret_read,app.sign_in_secret_rotated.