Collect profile details over time
Ask for one more profile detail at a later sign-in, in place of a long sign-up form.
What it shows
- The organization has two profiling rules. Each rule has a trigger and the fields to ask for.
- At the next sign-in, LumoAuth shows a page with one question, "Job title", before the browser returns to the app.
- The second sign-in asks nothing. The third sign-in asks for the team size, because the trigger of that rule is
login_count >= 3. - The app has no form for these details. Its server reads the answers with the access token of the session.
- No sign-in asks a question that the person has answered.
Before you start
- Check that your plan includes progressive profiling in the plans matrix.
- An organization for tests. The rules count for every person who signs in to the organization.
- A test user with a password, who has not signed in before.
- An API key with the scopes
admin:clients:writeandadmin:settings:write, for the setup script.
| Variable | Value |
|---|---|
LUMOAUTH_URL | The address of LumoAuth: https://app.lumoauth.dev, or https://eu.app.lumoauth.dev for the EU region. |
LUMOAUTH_ORG_ID | Your organization, for example acme-corp. |
LUMOAUTH_API_KEY | For the setup script only: an API key with the scopes admin:clients:write and admin:settings:write. |
LUMOAUTH_CLIENT_ID | The client ID of the application "Acme Onboarding". The setup script prints it. |
The setup script creates the application and turns progressive profiling on with two rules. Run it with the word off at the end to turn profiling off again.
node accounts/progressive-profiling/setup.mjs
setup.mjs
// Creates the application of the recipe and turns progressive profiling on,
// with two rules. Run it again at any time.
//
// node accounts/progressive-profiling/setup.mjs turn it on
// node accounts/progressive-profiling/setup.mjs off turn it off again
//
// The API key needs the scopes admin:clients:write and admin:settings:write.
// The rules count for every person who signs in to the organization, so use
// an organization for tests.
import { call, ensure, printEnv } from '../../_lib/admin.mjs';
const appUrl = process.env.APP_URL ?? 'http://localhost:3000';
// Each rule asks its fields once. The first rule asks at the next sign-in.
// The second rule waits until the third sign-in of the person.
const rules = [
{
id: 'job_title',
trigger: 'always',
fields: [{ key: 'job_title', label: 'Job title', type: 'text', required: true }],
},
{
id: 'team_size',
trigger: 'login_count >= 3',
fields: [{ key: 'team_size', label: 'Team size', type: 'select', options: ['1 to 10', '11 to 50', 'More than 50'], required: true }],
},
];
if (process.argv[2] === 'off') {
await call('PATCH', '/admin/settings/auth', { progressive_profiling: { enabled: false, rules: [] } });
console.log('Progressive profiling is off.');
process.exit(0);
}
// A public application signs in with PKCE and has no secret to keep. It asks
// for abac:read to read the attributes of the signed-in person, and the
// answers are among them.
const scopes = ['openid', 'profile', 'email', 'abac:read'];
const redirectUris = [`${appUrl}/auth/callback`];
const application = await ensure('/admin/clients', (c) => c.name === 'Acme Onboarding', {
name: 'Acme Onboarding',
redirectUris,
scopes,
isConfidential: false,
});
await call('PATCH', `/admin/clients/${application.clientId}`, { redirectUris, scopes });
await call('PATCH', '/admin/settings/auth', { progressive_profiling: { enabled: true, rules } });
console.log('The application "Acme Onboarding" is ready, and progressive profiling is on with two rules.');
printEnv({ LUMOAUTH_CLIENT_ID: application.clientId });
You can also edit the rules in the portal: open Sign-in settings, and open the section Progressive profiling.
Code
Run each command from the recipes folder of the examples repository. Set the folder up once for your language. Every version below was run against a LumoAuth organization. The program ran against an organization with four sign-ins of one test user. The question pages appeared at the first and at the third sign-in. See the note about the return to the app after the second question. A link and a form on another site did not sign the person out.
- Node.js
// A web app that shows the answers that LumoAuth collected at sign-in. The
// app has no form for them: LumoAuth asks the questions on its own page,
// between the sign-in and the return to the app.
//
// node accounts/progressive-profiling/js/app.mjs
//
// Then open http://localhost:3000.
import express from 'express';
import session from 'express-session';
import { randomBytes } from 'node:crypto';
import { LumoAuth } from '@lumoauth/client';
import { lumoAuthMiddleware } from '@lumoauth/express';
const baseUrl = process.env.LUMOAUTH_URL ?? 'https://app.lumoauth.dev';
const organization = process.env.LUMOAUTH_ORG_ID;
const port = process.env.PORT ?? 3000;
const app = express();
app.use(session({ secret: randomBytes(32).toString('hex'), resave: false, saveUninitialized: false }));
// Another site must not be able to sign a person out. This guard runs before
// /auth/logout of the middleware. A GET signs out at once only when the
// browser says that it comes from this app or from a typed address. Any other
// GET gets a page with a button, and a POST must come from this app.
app.all('/auth/logout', (req, res, next) => {
const site = req.get('Sec-Fetch-Site');
if (req.method === 'POST') {
const origin = req.get('Origin');
if (origin && origin !== 'null' ? origin === `${req.protocol}://${req.get('Host')}` : site === 'same-origin') return next();
return res.status(403).send('Sign-out refused: the request did not come from this app.');
}
if (site === 'same-origin' || site === 'none') return next();
res.set({
'Cache-Control': 'no-store',
'X-Content-Type-Options': 'nosniff',
'X-Frame-Options': 'DENY',
'Referrer-Policy': 'same-origin',
'Content-Security-Policy': "default-src 'none'; frame-ancestors 'none'",
});
res.send('<p>Do you want to sign out?</p><form method="post"><button>Sign out</button></form>');
});
// The middleware adds /auth/login, /auth/callback and /auth/logout. The scope
// abac:read lets the app read the attributes of the signed-in person.
app.use(
lumoAuthMiddleware({
baseUrl,
organization,
clientId: process.env.LUMOAUTH_CLIENT_ID,
scope: 'openid profile email abac:read',
}),
);
app.get('/', async (req, res) => {
if (!req.user) {
res.send('<h1>Acme Onboarding</h1><p>Nobody is signed in.</p><p><a href="/auth/login">Sign in</a></p>');
return;
}
// The answers are not claims of the ID token. They are attributes of the
// person, and the server reads them with the access token of the session.
// A browser cannot make this call: the endpoint sends no CORS headers.
const lumo = new LumoAuth({ baseUrl, orgId: organization, token: req.session.__lumoAuth.tokens.access_token });
const { attributes } = await lumo.abac.getMyAttributes();
// An answer that the person typed has the prefix "self_". Nobody verified
// it, so show it, and do not decide access from it.
const jobTitle = attributes.self_job_title ?? 'not asked yet';
const teamSize = attributes.self_team_size ?? 'not asked yet';
console.log(`${req.user.email}: job title "${jobTitle}", team size "${teamSize}"`);
res.send(
`<h1>Acme Onboarding</h1><p>Signed in as ${req.user.email}</p>` +
`<p>Job title: ${jobTitle}</p><p>Team size: ${teamSize}</p><p><a href="/auth/logout">Sign out</a></p>`,
);
});
app.listen(port, () => console.log(`Acme Onboarding: http://localhost:${port}`));
node accounts/progressive-profiling/js/app.mjs
In Chromium, the third sign-in did not return to the app after the answer: the browser blocked the redirect from the question page. The answer was saved, and the next visit to the app showed it.
Check the result
- Open
http://localhost:3000and click Sign in. After the password, LumoAuth asks for the job title. Answer, and click Save and continue. - Click Sign out, and sign in again. LumoAuth asks nothing.
- Sign out and sign in a third time. LumoAuth asks for the team size.
The program prints one line for each visit of the start page:
Acme Onboarding: http://localhost:3000
maya.chen@example.com: job title "Support lead", team size "not asked yet"
maya.chen@example.com: job title "Support lead", team size "not asked yet"
maya.chen@example.com: job title "Support lead", team size "1 to 10"
- The person sees the answers on the hosted page Personal info, under Your answers.
- In the portal, the answers are in the User traits card of the user.
- The app reads an answer as the attribute
self_job_title. The prefixself_marks a value that the person typed. - A link to
/auth/logouton another site shows a page with the question "Do you want to sign out?". A form on another site that posts to the route gets 403. A small guard in the app does this, so that no other site can sign the person out.
Limits
- Nobody verifies an answer. Show it, or use it to adapt the page, and do not decide access from it.
- The answers are not claims of the ID token, and the UserInfo endpoint does not return them.
- A browser cannot call the endpoint for the attributes of the person: it sends no CORS headers. Read the answers on your server.
- A rule asks its fields once. An optional field that the person leaves empty counts as answered.
- A session that "Remember me" restores is not a new sign-in, so it does not count for a trigger with
login_count.