@owlmeans/client-iam 0.1.18-rc.4 → 0.1.18-rc.41

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/build/append.d.ts CHANGED
@@ -1,7 +1,12 @@
1
1
  import type { AppConfig, AppContext } from '@owlmeans/web-client';
2
2
  import type { WithSharedConfig } from '@owlmeans/oidc';
3
+ import type { ConsentLoginOptions } from './consent.js';
3
4
  type IamClientConfig = AppConfig & WithSharedConfig;
4
5
  type IamClientContext<C extends IamClientConfig = IamClientConfig> = AppContext<C>;
6
+ export interface AppendIamOptions {
7
+ /** Consent required before a sign-in flow may start. `{ disabled: true }` turns it off. */
8
+ consent?: ConsentLoginOptions;
9
+ }
5
10
  /**
6
11
  * One-call OIDC RP setup for a web client context.
7
12
  *
@@ -10,7 +15,11 @@ type IamClientContext<C extends IamClientConfig = IamClientConfig> = AppContext<
10
15
  *
11
16
  * The OIDC provider config (discovery URL, clientId, secret) is read from
12
17
  * context.cfg.oidc.providers[] — populate it before calling appendIam().
18
+ *
19
+ * It also installs the consent precondition, so every application gets the "confirm essential
20
+ * cookies before signing in" rule from the line it already writes. An application that sets no
21
+ * cookie at all passes `{ consent: { disabled: true } }`.
13
22
  */
14
- export declare const appendIam: <C extends IamClientConfig, T extends IamClientContext<C>>(context: T) => T;
23
+ export declare const appendIam: <C extends IamClientConfig, T extends IamClientContext<C>>(context: T, opts?: AppendIamOptions) => T;
15
24
  export {};
16
25
  //# sourceMappingURL=append.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"append.d.ts","sourceRoot":"","sources":["../src/append.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAGtD,KAAK,eAAe,GAAG,SAAS,GAAG,gBAAgB,CAAA;AACnD,KAAK,gBAAgB,CAAC,CAAC,SAAS,eAAe,GAAG,eAAe,IAAI,UAAU,CAAC,CAAC,CAAC,CAAA;AAElF;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,eAAe,EAAE,CAAC,SAAS,gBAAgB,CAAC,CAAC,CAAC,WACvE,CAAC,KACT,CAGF,CAAA"}
1
+ {"version":3,"file":"append.d.ts","sourceRoot":"","sources":["../src/append.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAGtD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAEvD,KAAK,eAAe,GAAG,SAAS,GAAG,gBAAgB,CAAA;AACnD,KAAK,gBAAgB,CAAC,CAAC,SAAS,eAAe,GAAG,eAAe,IAAI,UAAU,CAAC,CAAC,CAAC,CAAA;AAElF,MAAM,WAAW,gBAAgB;IAC/B,2FAA2F;IAC3F,OAAO,CAAC,EAAE,mBAAmB,CAAA;CAC9B;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,eAAe,EAAE,CAAC,SAAS,gBAAgB,CAAC,CAAC,CAAC,WACvE,CAAC,SAAS,gBAAgB,KAClC,CAKF,CAAA"}
package/build/append.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { appendOidcGuard } from '@owlmeans/web-oidc-rp';
2
+ import { requireConsentForLogin } from './consent.js';
2
3
  /**
3
4
  * One-call OIDC RP setup for a web client context.
4
5
  *
@@ -7,9 +8,14 @@ import { appendOidcGuard } from '@owlmeans/web-oidc-rp';
7
8
  *
8
9
  * The OIDC provider config (discovery URL, clientId, secret) is read from
9
10
  * context.cfg.oidc.providers[] — populate it before calling appendIam().
11
+ *
12
+ * It also installs the consent precondition, so every application gets the "confirm essential
13
+ * cookies before signing in" rule from the line it already writes. An application that sets no
14
+ * cookie at all passes `{ consent: { disabled: true } }`.
10
15
  */
11
- export const appendIam = (context) => {
16
+ export const appendIam = (context, opts) => {
12
17
  appendOidcGuard(context);
18
+ requireConsentForLogin(context, opts?.consent);
13
19
  return context;
14
20
  };
15
21
  //# sourceMappingURL=append.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"append.js","sourceRoot":"","sources":["../src/append.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAKvD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,OAAU,EACP,EAAE;IACL,eAAe,CAAO,OAAO,CAAC,CAAA;IAC9B,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA"}
1
+ {"version":3,"file":"append.js","sourceRoot":"","sources":["../src/append.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAA;AAWrD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,OAAU,EAAE,IAAuB,EAChC,EAAE;IACL,eAAe,CAAO,OAAO,CAAC,CAAA;IAC9B,sBAAsB,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;IAE9C,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA"}
@@ -0,0 +1,34 @@
1
+ import type { BasicContext } from '@owlmeans/context';
2
+ export declare const CONSENT_LOGIN_PRECONDITION = "consent-before-login";
3
+ export interface ConsentLoginOptions {
4
+ /** The category that must be granted. Defaults to `essential`. */
5
+ category?: string;
6
+ /** Off switch, for an application that genuinely sets no cookie at all. */
7
+ disabled?: boolean;
8
+ }
9
+ /**
10
+ * Refuse to start a sign-in flow until the required consent category is granted, and open the
11
+ * consent dialog in the same gesture so the user can grant it.
12
+ *
13
+ * It sits on `LoginService.begin` rather than on `useLogin`, on a screen, or in a login plugin,
14
+ * and each of those alternatives is wrong for its own reason:
15
+ *
16
+ * - `useLogin` is one of four call sites (a header control, a sign-in-required panel, the
17
+ * dispatcher, and the surrogate screen). Enforcing there means enforcing four times, and the
18
+ * fifth call site somebody adds is unguarded.
19
+ * - a `LoginPlugin` is SELECTED, not chained — `plugin(env)` returns exactly one — so a "consent
20
+ * plugin" would displace the redirect or surrogate plugin rather than run before it, and the
21
+ * flow it was guarding would stop happening at all.
22
+ * - `begin` is the single funnel every mechanic passes through, and it is the one place where the
23
+ * user's gesture is still live, which is what lets the dialog open without being blocked.
24
+ *
25
+ * The check is synchronous because `begin` is: crossing a microtask before a plugin's
26
+ * `window.open` hands the window to the popup blocker.
27
+ *
28
+ * A refusal resolves `begin` as `LoginOutcome.Gesture`, which already means "cannot proceed
29
+ * without a fresh user gesture — render a control". After accepting, the user presses Log in
30
+ * again; that second press is deliberate, not an oversight, because the redirect or popup must
31
+ * originate from a real gesture.
32
+ */
33
+ export declare const requireConsentForLogin: (ctx: BasicContext<any>, opts?: ConsentLoginOptions) => void;
34
+ //# sourceMappingURL=consent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consent.d.ts","sourceRoot":"","sources":["../src/consent.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,eAAO,MAAM,0BAA0B,yBAAyB,CAAA;AAEhE,MAAM,WAAW,mBAAmB;IAClC,kEAAkE;IAClE,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,sBAAsB,QAC5B,YAAY,CAAC,GAAG,CAAC,SAAS,mBAAmB,KACjD,IAoBF,CAAA"}
@@ -0,0 +1,47 @@
1
+ import { CONSENT_ESSENTIAL, consentStore } from '@owlmeans/consent';
2
+ import { ensureLoginService } from '@owlmeans/client-auth/login';
3
+ export const CONSENT_LOGIN_PRECONDITION = 'consent-before-login';
4
+ /**
5
+ * Refuse to start a sign-in flow until the required consent category is granted, and open the
6
+ * consent dialog in the same gesture so the user can grant it.
7
+ *
8
+ * It sits on `LoginService.begin` rather than on `useLogin`, on a screen, or in a login plugin,
9
+ * and each of those alternatives is wrong for its own reason:
10
+ *
11
+ * - `useLogin` is one of four call sites (a header control, a sign-in-required panel, the
12
+ * dispatcher, and the surrogate screen). Enforcing there means enforcing four times, and the
13
+ * fifth call site somebody adds is unguarded.
14
+ * - a `LoginPlugin` is SELECTED, not chained — `plugin(env)` returns exactly one — so a "consent
15
+ * plugin" would displace the redirect or surrogate plugin rather than run before it, and the
16
+ * flow it was guarding would stop happening at all.
17
+ * - `begin` is the single funnel every mechanic passes through, and it is the one place where the
18
+ * user's gesture is still live, which is what lets the dialog open without being blocked.
19
+ *
20
+ * The check is synchronous because `begin` is: crossing a microtask before a plugin's
21
+ * `window.open` hands the window to the popup blocker.
22
+ *
23
+ * A refusal resolves `begin` as `LoginOutcome.Gesture`, which already means "cannot proceed
24
+ * without a fresh user gesture — render a control". After accepting, the user presses Log in
25
+ * again; that second press is deliberate, not an oversight, because the redirect or popup must
26
+ * originate from a real gesture.
27
+ */
28
+ export const requireConsentForLogin = (ctx, opts) => {
29
+ if (opts?.disabled === true) {
30
+ return;
31
+ }
32
+ const category = opts?.category ?? CONSENT_ESSENTIAL;
33
+ ensureLoginService(ctx).registerPrecondition({
34
+ alias: CONSENT_LOGIN_PRECONDITION,
35
+ // Above anything an application adds by default, so a user is never asked to satisfy some
36
+ // other precondition before being told about the one that is actually blocking them.
37
+ priority: 100,
38
+ check: () => {
39
+ if (consentStore.granted(category) && consentStore.get().record != null) {
40
+ return true;
41
+ }
42
+ consentStore.open('login');
43
+ return false;
44
+ },
45
+ });
46
+ };
47
+ //# sourceMappingURL=consent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consent.js","sourceRoot":"","sources":["../src/consent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAGhE,MAAM,CAAC,MAAM,0BAA0B,GAAG,sBAAsB,CAAA;AAShE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,GAAsB,EAAE,IAA0B,EAC5C,EAAE;IACR,IAAI,IAAI,EAAE,QAAQ,KAAK,IAAI,EAAE,CAAC;QAC5B,OAAM;IACR,CAAC;IACD,MAAM,QAAQ,GAAG,IAAI,EAAE,QAAQ,IAAI,iBAAiB,CAAA;IAEpD,kBAAkB,CAAC,GAAG,CAAC,CAAC,oBAAoB,CAAC;QAC3C,KAAK,EAAE,0BAA0B;QACjC,0FAA0F;QAC1F,qFAAqF;QACrF,QAAQ,EAAE,GAAG;QACb,KAAK,EAAE,GAAG,EAAE;YACV,IAAI,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,YAAY,CAAC,GAAG,EAAE,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC;gBACxE,OAAO,IAAI,CAAA;YACb,CAAC;YACD,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;YAE1B,OAAO,KAAK,CAAA;QACd,CAAC;KACF,CAAC,CAAA;AACJ,CAAC,CAAA"}
package/build/index.d.ts CHANGED
@@ -2,4 +2,6 @@ export type * from '@owlmeans/iam';
2
2
  export { hasPermission } from '@owlmeans/iam';
3
3
  export * from './consts.js';
4
4
  export * from './append.js';
5
+ export * from './consent.js';
6
+ export * from './login.js';
5
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,eAAe,CAAA;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,eAAe,CAAA;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA"}
package/build/index.js CHANGED
@@ -1,4 +1,6 @@
1
1
  export { hasPermission } from '@owlmeans/iam';
2
2
  export * from './consts.js';
3
3
  export * from './append.js';
4
+ export * from './consent.js';
5
+ export * from './login.js';
4
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * IAM sign-in is assembled from immutable declarations: decorate the app's protocol tree with
3
+ * {@link withIamGuard}, then append the browser-local {@link iamEntrypoints} bindings.
4
+ */
5
+ export { withOidcGuard as withIamGuard } from '@owlmeans/oidc';
6
+ export { oidcEntrypoints as iamEntrypoints } from '@owlmeans/web-oidc-rp';
7
+ /**
8
+ * How a user signs in and out.
9
+ *
10
+ * Re-exported here so an app has one IAM import rather than three, and so the control it renders
11
+ * carries no knowledge of the browsing context it happens to be in — whether the flow can redirect
12
+ * from where it is, has to run one window up, or is already answered by a session this document
13
+ * holds, is decided by the login plugin the framework selected. See the `login-plugins` guidance
14
+ * for what that means and how to add a mechanic.
15
+ */
16
+ export { useLogin, useLogout } from '@owlmeans/client-auth/login';
17
+ export { LoginOutcome, LoginIntent } from '@owlmeans/client-auth/login';
18
+ export type { LoginPlugin, LoginRequest, LogoutRequest, LoginService, LoginPrecondition, LoginMethod, LoginMethodSource, LoginScreenProps, } from '@owlmeans/client-auth/login';
19
+ //# sourceMappingURL=login.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../src/login.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,aAAa,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC9D,OAAO,EAAE,eAAe,IAAI,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEzE;;;;;;;;GAQG;AACH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAA;AACjE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACvE,YAAY,EACV,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,iBAAiB,EACzE,WAAW,EAAE,iBAAiB,EAAE,gBAAgB,GACjD,MAAM,6BAA6B,CAAA"}
package/build/login.js ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * IAM sign-in is assembled from immutable declarations: decorate the app's protocol tree with
3
+ * {@link withIamGuard}, then append the browser-local {@link iamEntrypoints} bindings.
4
+ */
5
+ export { withOidcGuard as withIamGuard } from '@owlmeans/oidc';
6
+ export { oidcEntrypoints as iamEntrypoints } from '@owlmeans/web-oidc-rp';
7
+ /**
8
+ * How a user signs in and out.
9
+ *
10
+ * Re-exported here so an app has one IAM import rather than three, and so the control it renders
11
+ * carries no knowledge of the browsing context it happens to be in — whether the flow can redirect
12
+ * from where it is, has to run one window up, or is already answered by a session this document
13
+ * holds, is decided by the login plugin the framework selected. See the `login-plugins` guidance
14
+ * for what that means and how to add a mechanic.
15
+ */
16
+ export { useLogin, useLogout } from '@owlmeans/client-auth/login';
17
+ export { LoginOutcome, LoginIntent } from '@owlmeans/client-auth/login';
18
+ //# sourceMappingURL=login.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login.js","sourceRoot":"","sources":["../src/login.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,aAAa,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC9D,OAAO,EAAE,eAAe,IAAI,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEzE;;;;;;;;GAQG;AACH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAA;AACjE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owlmeans/client-iam",
3
- "version": "0.1.18-rc.4",
3
+ "version": "0.1.18-rc.41",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -22,15 +22,18 @@
22
22
  }
23
23
  },
24
24
  "dependencies": {
25
- "@owlmeans/context": "^0.1.18-rc.4",
26
- "@owlmeans/iam": "^0.1.18-rc.4",
27
- "@owlmeans/oidc": "^0.1.18-rc.4",
28
- "@owlmeans/web-client": "^0.1.18-rc.4",
29
- "@owlmeans/web-oidc-rp": "^0.1.18-rc.4"
25
+ "@owlmeans/client-auth": "^0.1.18-rc.33",
26
+ "@owlmeans/consent": "^0.1.18-rc.4",
27
+ "@owlmeans/context": "^0.1.18-rc.20",
28
+ "@owlmeans/entrypoint": "^0.1.18-rc.23",
29
+ "@owlmeans/iam": "^0.1.18-rc.28",
30
+ "@owlmeans/oidc": "^0.1.18-rc.33",
31
+ "@owlmeans/web-client": "^0.1.18-rc.37",
32
+ "@owlmeans/web-oidc-rp": "^0.1.18-rc.39"
30
33
  },
31
34
  "devDependencies": {
32
35
  "@owlmeans/dep-config": "workspace:*",
33
- "@types/bun": "^1.3.14",
36
+ "@types/bun": "^1.4.0",
34
37
  "nodemon": "^3.1.14",
35
38
  "typescript": "^7.0.2"
36
39
  },
package/src/append.ts CHANGED
@@ -1,10 +1,17 @@
1
1
  import type { AppConfig, AppContext } from '@owlmeans/web-client'
2
2
  import type { WithSharedConfig } from '@owlmeans/oidc'
3
3
  import { appendOidcGuard } from '@owlmeans/web-oidc-rp'
4
+ import { requireConsentForLogin } from './consent.js'
5
+ import type { ConsentLoginOptions } from './consent.js'
4
6
 
5
7
  type IamClientConfig = AppConfig & WithSharedConfig
6
8
  type IamClientContext<C extends IamClientConfig = IamClientConfig> = AppContext<C>
7
9
 
10
+ export interface AppendIamOptions {
11
+ /** Consent required before a sign-in flow may start. `{ disabled: true }` turns it off. */
12
+ consent?: ConsentLoginOptions
13
+ }
14
+
8
15
  /**
9
16
  * One-call OIDC RP setup for a web client context.
10
17
  *
@@ -13,10 +20,16 @@ type IamClientContext<C extends IamClientConfig = IamClientConfig> = AppContext<
13
20
  *
14
21
  * The OIDC provider config (discovery URL, clientId, secret) is read from
15
22
  * context.cfg.oidc.providers[] — populate it before calling appendIam().
23
+ *
24
+ * It also installs the consent precondition, so every application gets the "confirm essential
25
+ * cookies before signing in" rule from the line it already writes. An application that sets no
26
+ * cookie at all passes `{ consent: { disabled: true } }`.
16
27
  */
17
28
  export const appendIam = <C extends IamClientConfig, T extends IamClientContext<C>>(
18
- context: T
29
+ context: T, opts?: AppendIamOptions
19
30
  ): T => {
20
31
  appendOidcGuard<C, T>(context)
32
+ requireConsentForLogin(context, opts?.consent)
33
+
21
34
  return context
22
35
  }
package/src/consent.ts ADDED
@@ -0,0 +1,60 @@
1
+ import { CONSENT_ESSENTIAL, consentStore } from '@owlmeans/consent'
2
+ import { ensureLoginService } from '@owlmeans/client-auth/login'
3
+ import type { BasicContext } from '@owlmeans/context'
4
+
5
+ export const CONSENT_LOGIN_PRECONDITION = 'consent-before-login'
6
+
7
+ export interface ConsentLoginOptions {
8
+ /** The category that must be granted. Defaults to `essential`. */
9
+ category?: string
10
+ /** Off switch, for an application that genuinely sets no cookie at all. */
11
+ disabled?: boolean
12
+ }
13
+
14
+ /**
15
+ * Refuse to start a sign-in flow until the required consent category is granted, and open the
16
+ * consent dialog in the same gesture so the user can grant it.
17
+ *
18
+ * It sits on `LoginService.begin` rather than on `useLogin`, on a screen, or in a login plugin,
19
+ * and each of those alternatives is wrong for its own reason:
20
+ *
21
+ * - `useLogin` is one of four call sites (a header control, a sign-in-required panel, the
22
+ * dispatcher, and the surrogate screen). Enforcing there means enforcing four times, and the
23
+ * fifth call site somebody adds is unguarded.
24
+ * - a `LoginPlugin` is SELECTED, not chained — `plugin(env)` returns exactly one — so a "consent
25
+ * plugin" would displace the redirect or surrogate plugin rather than run before it, and the
26
+ * flow it was guarding would stop happening at all.
27
+ * - `begin` is the single funnel every mechanic passes through, and it is the one place where the
28
+ * user's gesture is still live, which is what lets the dialog open without being blocked.
29
+ *
30
+ * The check is synchronous because `begin` is: crossing a microtask before a plugin's
31
+ * `window.open` hands the window to the popup blocker.
32
+ *
33
+ * A refusal resolves `begin` as `LoginOutcome.Gesture`, which already means "cannot proceed
34
+ * without a fresh user gesture — render a control". After accepting, the user presses Log in
35
+ * again; that second press is deliberate, not an oversight, because the redirect or popup must
36
+ * originate from a real gesture.
37
+ */
38
+ export const requireConsentForLogin = (
39
+ ctx: BasicContext<any>, opts?: ConsentLoginOptions
40
+ ): void => {
41
+ if (opts?.disabled === true) {
42
+ return
43
+ }
44
+ const category = opts?.category ?? CONSENT_ESSENTIAL
45
+
46
+ ensureLoginService(ctx).registerPrecondition({
47
+ alias: CONSENT_LOGIN_PRECONDITION,
48
+ // Above anything an application adds by default, so a user is never asked to satisfy some
49
+ // other precondition before being told about the one that is actually blocking them.
50
+ priority: 100,
51
+ check: () => {
52
+ if (consentStore.granted(category) && consentStore.get().record != null) {
53
+ return true
54
+ }
55
+ consentStore.open('login')
56
+
57
+ return false
58
+ },
59
+ })
60
+ }
package/src/index.ts CHANGED
@@ -2,3 +2,5 @@ export type * from '@owlmeans/iam'
2
2
  export { hasPermission } from '@owlmeans/iam'
3
3
  export * from './consts.js'
4
4
  export * from './append.js'
5
+ export * from './consent.js'
6
+ export * from './login.js'
package/src/login.ts ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * IAM sign-in is assembled from immutable declarations: decorate the app's protocol tree with
3
+ * {@link withIamGuard}, then append the browser-local {@link iamEntrypoints} bindings.
4
+ */
5
+ export { withOidcGuard as withIamGuard } from '@owlmeans/oidc'
6
+ export { oidcEntrypoints as iamEntrypoints } from '@owlmeans/web-oidc-rp'
7
+
8
+ /**
9
+ * How a user signs in and out.
10
+ *
11
+ * Re-exported here so an app has one IAM import rather than three, and so the control it renders
12
+ * carries no knowledge of the browsing context it happens to be in — whether the flow can redirect
13
+ * from where it is, has to run one window up, or is already answered by a session this document
14
+ * holds, is decided by the login plugin the framework selected. See the `login-plugins` guidance
15
+ * for what that means and how to add a mechanic.
16
+ */
17
+ export { useLogin, useLogout } from '@owlmeans/client-auth/login'
18
+ export { LoginOutcome, LoginIntent } from '@owlmeans/client-auth/login'
19
+ export type {
20
+ LoginPlugin, LoginRequest, LogoutRequest, LoginService, LoginPrecondition,
21
+ LoginMethod, LoginMethodSource, LoginScreenProps,
22
+ } from '@owlmeans/client-auth/login'