nextidp 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.0
4
+
5
+ - `GET <basePath>/login?login_hint=…` passes the hint on to the auth server (OIDC Core
6
+ 3.1.2.1), and pushes it with PAR. Next-Identity Server sends someone whose company signs them
7
+ in straight to the company's sign-in page. It's trimmed; one past 254 characters or with a
8
+ control character is left out.
9
+ - `signInPath(returnTo, { loginHint })` adds it to a sign-in link.
10
+
3
11
  ## 0.5.0
4
12
 
5
13
  ### Managing accounts
package/README.md CHANGED
@@ -267,7 +267,7 @@ All under `basePath` (default `/auth`):
267
267
 
268
268
  | Route | What it does |
269
269
  |---|---|
270
- | `GET /auth/login?returnTo=/path` | Starts a sign-in, and comes back to `returnTo` (paths of this app only). Takes `prompt` and `reauthenticate=false` too ([below](#asking-for-the-password-again)). |
270
+ | `GET /auth/login?returnTo=/path` | Starts a sign-in, and comes back to `returnTo` (paths of this app only). Takes `prompt`, `reauthenticate=false` ([below](#asking-for-the-password-again)) and `login_hint` ([below](#who-is-signing-in)) too. |
271
271
  | `GET /auth/callback` | Finishes it: the redirect URI you registered. |
272
272
  | `POST /auth/logout` | Revokes the refresh token and ends this app's session. With `signOutOfIdp=true`, the auth server's too. |
273
273
  | `POST /auth/refresh` | New tokens now, then back to the form's `returnTo`. |
@@ -279,7 +279,8 @@ The POST routes accept forms from this app's own pages only (they check `Origin`
279
279
  `GET /auth/login?prompt=login` makes the auth server ask for the password even while its own
280
280
  session is still live; `consent` shows the consent screen again; `select_account` asks which
281
281
  account. Several go together, separated by spaces (`prompt=login consent`). Any other value
282
- (`none` included) is left out, and nothing else in the query reaches the auth server.
282
+ (`none` included) is left out, and nothing else in the query reaches the auth server but
283
+ `login_hint`.
283
284
 
284
285
  Signing out of the app alone leaves the auth server's session live, so by default the next
285
286
  sign-in goes straight through: on a shared computer, as the person before. With
@@ -297,7 +298,20 @@ cookie.
297
298
  <a href={auth.signInPath("/settings", { prompt: "consent" })}>Review permissions</a>
298
299
  ```
299
300
 
300
- `auth.signInPath(returnTo, { prompt, reauthenticate })` builds these links.
301
+ `auth.signInPath(returnTo, { prompt, reauthenticate, loginHint })` builds these links.
302
+
303
+ ### Who is signing in
304
+
305
+ `GET /auth/login?login_hint=ada@acme.com` tells the auth server who is signing in, when the app
306
+ already knows (OIDC Core 3.1.2.1): an app that asks for the email first, or a link in an email.
307
+ Next-Identity Server sends someone whose company signs them in (single sign-on) straight to the
308
+ company's sign-in page, without its own. The hint is trimmed, and one longer than an email
309
+ address (254 characters) or with a control character is left out. With PAR it's pushed with the
310
+ rest.
311
+
312
+ ```tsx
313
+ <a href={auth.signInPath("/", { loginHint: email })}>Continue</a>
314
+ ```
301
315
 
302
316
  ### Pushing the sign-in first (PAR)
303
317
 
package/dist/cjs/idp.d.ts CHANGED
@@ -110,6 +110,11 @@ export type SignInPathOptions = {
110
110
  prompt?: string | undefined;
111
111
  /** false: no `prompt=login` from an earlier sign-out (see `reauthenticateAfterSignOut`). */
112
112
  reauthenticate?: boolean | undefined;
113
+ /**
114
+ * Who is signing in, usually their email (`login_hint`). Next-Identity Server sends someone
115
+ * whose company signs them in straight to the company's sign-in.
116
+ */
117
+ loginHint?: string | undefined;
113
118
  };
114
119
  /**
115
120
  * The client for one app. Settings are checked on first use, not here, so a module that
package/dist/cjs/idp.js CHANGED
@@ -45,6 +45,11 @@ function promptFrom(value) {
45
45
  if (values.length === 0 || !values.every((each) => PROMPTS.has(each))) return void 0;
46
46
  return [...new Set(values)].join(" ");
47
47
  }
48
+ function loginHintFrom(value) {
49
+ const hint = value?.trim();
50
+ if (!hint || hint.length > 254 || new RegExp("\\p{Cc}", "u").test(hint)) return void 0;
51
+ return hint;
52
+ }
48
53
  const SIGNED_OUT_MAX_AGE = 30 * 24 * 60 * 60;
49
54
  const INTROSPECTION_CACHE_MS = 6e4;
50
55
  const INTROSPECTION_CACHE_SIZE = 1e3;
@@ -299,6 +304,7 @@ function createIdp(options = {}) {
299
304
  async function login(s, request, url) {
300
305
  const returnTo = (0, import_return_path.safePath)(url.searchParams.get("returnTo")) ?? s.config.afterSignIn;
301
306
  const { prompt, setCookies } = promptOf(s, request, url);
307
+ const loginHint = loginHintFrom(url.searchParams.get("login_hint"));
302
308
  let discovery;
303
309
  try {
304
310
  discovery = await s.discovery();
@@ -317,7 +323,8 @@ function createIdp(options = {}) {
317
323
  code_challenge: await (0, import_pkce.challengeFor)(flow.verifier),
318
324
  code_challenge_method: "S256",
319
325
  ...s.config.resource ? { resource: s.config.resource } : {},
320
- ...prompt ? { prompt } : {}
326
+ ...prompt ? { prompt } : {},
327
+ ...loginHint ? { login_hint: loginHint } : {}
321
328
  });
322
329
  const authorize = new URL(discovery.authorization_endpoint);
323
330
  const push = pushEndpoint(s, discovery);
@@ -595,8 +602,10 @@ function createIdp(options = {}) {
595
602
  const query = new URLSearchParams();
596
603
  const safe = (0, import_return_path.safePath)(returnTo);
597
604
  const prompt = promptFrom(options2.prompt);
605
+ const loginHint = loginHintFrom(options2.loginHint);
598
606
  if (safe) query.set("returnTo", safe);
599
607
  if (prompt) query.set("prompt", prompt);
608
+ if (loginHint) query.set("login_hint", loginHint);
600
609
  if (options2.reauthenticate === false) query.set("reauthenticate", "false");
601
610
  const login2 = `${s.config.basePath}/login`;
602
611
  return query.size > 0 ? `${login2}?${query}` : login2;
package/dist/esm/idp.d.ts CHANGED
@@ -110,6 +110,11 @@ export type SignInPathOptions = {
110
110
  prompt?: string | undefined;
111
111
  /** false: no `prompt=login` from an earlier sign-out (see `reauthenticateAfterSignOut`). */
112
112
  reauthenticate?: boolean | undefined;
113
+ /**
114
+ * Who is signing in, usually their email (`login_hint`). Next-Identity Server sends someone
115
+ * whose company signs them in straight to the company's sign-in.
116
+ */
117
+ loginHint?: string | undefined;
113
118
  };
114
119
  /**
115
120
  * The client for one app. Settings are checked on first use, not here, so a module that
package/dist/esm/idp.js CHANGED
@@ -55,6 +55,11 @@ function promptFrom(value) {
55
55
  if (values.length === 0 || !values.every((each) => PROMPTS.has(each))) return void 0;
56
56
  return [...new Set(values)].join(" ");
57
57
  }
58
+ function loginHintFrom(value) {
59
+ const hint = value?.trim();
60
+ if (!hint || hint.length > 254 || new RegExp("\\p{Cc}", "u").test(hint)) return void 0;
61
+ return hint;
62
+ }
58
63
  const SIGNED_OUT_MAX_AGE = 30 * 24 * 60 * 60;
59
64
  const INTROSPECTION_CACHE_MS = 6e4;
60
65
  const INTROSPECTION_CACHE_SIZE = 1e3;
@@ -309,6 +314,7 @@ function createIdp(options = {}) {
309
314
  async function login(s, request, url) {
310
315
  const returnTo = safePath(url.searchParams.get("returnTo")) ?? s.config.afterSignIn;
311
316
  const { prompt, setCookies } = promptOf(s, request, url);
317
+ const loginHint = loginHintFrom(url.searchParams.get("login_hint"));
312
318
  let discovery;
313
319
  try {
314
320
  discovery = await s.discovery();
@@ -327,7 +333,8 @@ function createIdp(options = {}) {
327
333
  code_challenge: await challengeFor(flow.verifier),
328
334
  code_challenge_method: "S256",
329
335
  ...s.config.resource ? { resource: s.config.resource } : {},
330
- ...prompt ? { prompt } : {}
336
+ ...prompt ? { prompt } : {},
337
+ ...loginHint ? { login_hint: loginHint } : {}
331
338
  });
332
339
  const authorize = new URL(discovery.authorization_endpoint);
333
340
  const push = pushEndpoint(s, discovery);
@@ -605,8 +612,10 @@ function createIdp(options = {}) {
605
612
  const query = new URLSearchParams();
606
613
  const safe = safePath(returnTo);
607
614
  const prompt = promptFrom(options2.prompt);
615
+ const loginHint = loginHintFrom(options2.loginHint);
608
616
  if (safe) query.set("returnTo", safe);
609
617
  if (prompt) query.set("prompt", prompt);
618
+ if (loginHint) query.set("login_hint", loginHint);
610
619
  if (options2.reauthenticate === false) query.set("reauthenticate", "false");
611
620
  const login2 = `${s.config.basePath}/login`;
612
621
  return query.size > 0 ? `${login2}?${query}` : login2;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nextidp",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Sign people in to Next.js, Express, Fastify, Hono and Node apps, and protect NestJS, Express, Fastify, Hono and Next.js APIs, with Next-Identity Server, in one call. Runs on Node and edge runtimes.",
5
5
  "keywords": [
6
6
  "oidc",