@owlmeans/client-iam 0.1.18-rc.17 → 0.1.18-rc.18
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 +10 -1
- package/build/append.d.ts.map +1 -1
- package/build/append.js +7 -1
- package/build/append.js.map +1 -1
- package/build/consent.d.ts +34 -0
- package/build/consent.d.ts.map +1 -0
- package/build/consent.js +47 -0
- package/build/consent.js.map +1 -0
- package/build/index.d.ts +1 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -0
- package/build/index.js.map +1 -1
- package/build/login.d.ts +5 -4
- package/build/login.d.ts.map +1 -1
- package/build/login.js +4 -3
- package/build/login.js.map +1 -1
- package/package.json +9 -8
- package/src/append.ts +14 -1
- package/src/consent.ts +60 -0
- package/src/index.ts +1 -0
- package/src/login.ts +8 -4
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
|
package/build/append.d.ts.map
CHANGED
|
@@ -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
|
|
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
|
package/build/append.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"append.js","sourceRoot":"","sources":["../src/append.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,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"}
|
package/build/consent.js
ADDED
|
@@ -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
package/build/index.d.ts.map
CHANGED
|
@@ -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;AAC3B,cAAc,YAAY,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
package/build/index.js.map
CHANGED
|
@@ -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;AAC3B,cAAc,YAAY,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"}
|
package/build/login.d.ts
CHANGED
|
@@ -17,10 +17,11 @@ export declare const setupIam: (entrypoints: CommonEntrypoint[], coguards?: stri
|
|
|
17
17
|
*
|
|
18
18
|
* Re-exported here so an app has one IAM import rather than three, and so the control it renders
|
|
19
19
|
* carries no knowledge of the browsing context it happens to be in — whether the flow can redirect
|
|
20
|
-
* from where it is,
|
|
21
|
-
* selected. See the `login-plugins` guidance
|
|
20
|
+
* from where it is, has to run one window up, or is already answered by a session this document
|
|
21
|
+
* holds, is decided by the login plugin the framework selected. See the `login-plugins` guidance
|
|
22
|
+
* for what that means and how to add a mechanic.
|
|
22
23
|
*/
|
|
23
24
|
export { useLogin, useLogout } from '@owlmeans/client-auth/login';
|
|
24
|
-
export { LoginOutcome } from '@owlmeans/client-auth/login';
|
|
25
|
-
export type { LoginPlugin, LoginRequest, LoginService } from '@owlmeans/client-auth/login';
|
|
25
|
+
export { LoginOutcome, LoginIntent } from '@owlmeans/client-auth/login';
|
|
26
|
+
export type { LoginPlugin, LoginRequest, LogoutRequest, LoginService, LoginPrecondition, LoginMethod, LoginMethodSource, LoginScreenProps, } from '@owlmeans/client-auth/login';
|
|
26
27
|
//# sourceMappingURL=login.d.ts.map
|
package/build/login.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../src/login.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAG5D;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,QAAQ,gBAAiB,gBAAgB,EAAE,aAAa,MAAM,GAAG,MAAM,EAAE,KAAG,IAExF,CAAA;AAED
|
|
1
|
+
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../src/login.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAG5D;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,QAAQ,gBAAiB,gBAAgB,EAAE,aAAa,MAAM,GAAG,MAAM,EAAE,KAAG,IAExF,CAAA;AAED;;;;;;;;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
CHANGED
|
@@ -19,9 +19,10 @@ export const setupIam = (entrypoints, coguards) => {
|
|
|
19
19
|
*
|
|
20
20
|
* Re-exported here so an app has one IAM import rather than three, and so the control it renders
|
|
21
21
|
* carries no knowledge of the browsing context it happens to be in — whether the flow can redirect
|
|
22
|
-
* from where it is,
|
|
23
|
-
* selected. See the `login-plugins` guidance
|
|
22
|
+
* from where it is, has to run one window up, or is already answered by a session this document
|
|
23
|
+
* holds, is decided by the login plugin the framework selected. See the `login-plugins` guidance
|
|
24
|
+
* for what that means and how to add a mechanic.
|
|
24
25
|
*/
|
|
25
26
|
export { useLogin, useLogout } from '@owlmeans/client-auth/login';
|
|
26
|
-
export { LoginOutcome } from '@owlmeans/client-auth/login';
|
|
27
|
+
export { LoginOutcome, LoginIntent } from '@owlmeans/client-auth/login';
|
|
27
28
|
//# sourceMappingURL=login.js.map
|
package/build/login.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login.js","sourceRoot":"","sources":["../src/login.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEtD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,WAA+B,EAAE,QAA4B,EAAQ,EAAE;IAC9F,cAAc,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAA;AACvC,CAAC,CAAA;AAED
|
|
1
|
+
{"version":3,"file":"login.js","sourceRoot":"","sources":["../src/login.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEtD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,WAA+B,EAAE,QAA4B,EAAQ,EAAE;IAC9F,cAAc,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAA;AACvC,CAAC,CAAA;AAED;;;;;;;;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.
|
|
3
|
+
"version": "0.1.18-rc.18",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -22,17 +22,18 @@
|
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@owlmeans/client-auth": "^0.1.18-rc.
|
|
25
|
+
"@owlmeans/client-auth": "^0.1.18-rc.13",
|
|
26
|
+
"@owlmeans/consent": "^0.1.18-rc.2",
|
|
26
27
|
"@owlmeans/context": "^0.1.18-rc.6",
|
|
27
|
-
"@owlmeans/entrypoint": "^0.1.18-rc.
|
|
28
|
-
"@owlmeans/iam": "^0.1.18-rc.
|
|
29
|
-
"@owlmeans/oidc": "^0.1.18-rc.
|
|
30
|
-
"@owlmeans/web-client": "^0.1.18-rc.
|
|
31
|
-
"@owlmeans/web-oidc-rp": "^0.1.18-rc.
|
|
28
|
+
"@owlmeans/entrypoint": "^0.1.18-rc.8",
|
|
29
|
+
"@owlmeans/iam": "^0.1.18-rc.12",
|
|
30
|
+
"@owlmeans/oidc": "^0.1.18-rc.9",
|
|
31
|
+
"@owlmeans/web-client": "^0.1.18-rc.14",
|
|
32
|
+
"@owlmeans/web-oidc-rp": "^0.1.18-rc.15"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
35
|
"@owlmeans/dep-config": "workspace:*",
|
|
35
|
-
"@types/bun": "^1.
|
|
36
|
+
"@types/bun": "^1.4.0",
|
|
36
37
|
"nodemon": "^3.1.14",
|
|
37
38
|
"typescript": "^7.0.2"
|
|
38
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
package/src/login.ts
CHANGED
|
@@ -22,9 +22,13 @@ export const setupIam = (entrypoints: CommonEntrypoint[], coguards?: string | st
|
|
|
22
22
|
*
|
|
23
23
|
* Re-exported here so an app has one IAM import rather than three, and so the control it renders
|
|
24
24
|
* carries no knowledge of the browsing context it happens to be in — whether the flow can redirect
|
|
25
|
-
* from where it is,
|
|
26
|
-
* selected. See the `login-plugins` guidance
|
|
25
|
+
* from where it is, has to run one window up, or is already answered by a session this document
|
|
26
|
+
* holds, is decided by the login plugin the framework selected. See the `login-plugins` guidance
|
|
27
|
+
* for what that means and how to add a mechanic.
|
|
27
28
|
*/
|
|
28
29
|
export { useLogin, useLogout } from '@owlmeans/client-auth/login'
|
|
29
|
-
export { LoginOutcome } from '@owlmeans/client-auth/login'
|
|
30
|
-
export type {
|
|
30
|
+
export { LoginOutcome, LoginIntent } from '@owlmeans/client-auth/login'
|
|
31
|
+
export type {
|
|
32
|
+
LoginPlugin, LoginRequest, LogoutRequest, LoginService, LoginPrecondition,
|
|
33
|
+
LoginMethod, LoginMethodSource, LoginScreenProps,
|
|
34
|
+
} from '@owlmeans/client-auth/login'
|