@softistx/janus-social 0.0.0-stage → 0.8.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/LICENSE +21 -0
- package/README.md +356 -2
- package/dist/authorization-url.d.ts +21 -0
- package/dist/authorization-url.d.ts.map +1 -0
- package/dist/check-options.d.ts +22 -0
- package/dist/check-options.d.ts.map +1 -0
- package/dist/claims.d.ts +15 -0
- package/dist/claims.d.ts.map +1 -0
- package/dist/code-exchange.d.ts +79 -0
- package/dist/code-exchange.d.ts.map +1 -0
- package/dist/connections/abort.d.ts +8 -0
- package/dist/connections/abort.d.ts.map +1 -0
- package/dist/connections/at-hash.d.ts +24 -0
- package/dist/connections/at-hash.d.ts.map +1 -0
- package/dist/connections/body-limit.d.ts +15 -0
- package/dist/connections/body-limit.d.ts.map +1 -0
- package/dist/connections/build.d.ts +7 -0
- package/dist/connections/build.d.ts.map +1 -0
- package/dist/connections/check.d.ts +25 -0
- package/dist/connections/check.d.ts.map +1 -0
- package/dist/connections/claims.d.ts +16 -0
- package/dist/connections/claims.d.ts.map +1 -0
- package/dist/connections/discovery.d.ts +20 -0
- package/dist/connections/discovery.d.ts.map +1 -0
- package/dist/connections/domain.d.ts +15 -0
- package/dist/connections/domain.d.ts.map +1 -0
- package/dist/connections/guarded-fetch.d.ts +49 -0
- package/dist/connections/guarded-fetch.d.ts.map +1 -0
- package/dist/connections/id-token-steps.d.ts +15 -0
- package/dist/connections/id-token-steps.d.ts.map +1 -0
- package/dist/connections/id-token.d.ts +63 -0
- package/dist/connections/id-token.d.ts.map +1 -0
- package/dist/connections/index.d.ts +11 -0
- package/dist/connections/index.d.ts.map +1 -0
- package/dist/connections/ip.d.ts +14 -0
- package/dist/connections/ip.d.ts.map +1 -0
- package/dist/connections/issuer-cache.d.ts +40 -0
- package/dist/connections/issuer-cache.d.ts.map +1 -0
- package/dist/connections/issuer.d.ts +4 -0
- package/dist/connections/issuer.d.ts.map +1 -0
- package/dist/connections/key-flights.d.ts +16 -0
- package/dist/connections/key-flights.d.ts.map +1 -0
- package/dist/connections/memory.d.ts +10 -0
- package/dist/connections/memory.d.ts.map +1 -0
- package/dist/connections/oidc-connections.d.ts +71 -0
- package/dist/connections/oidc-connections.d.ts.map +1 -0
- package/dist/connections/provider.d.ts +25 -0
- package/dist/connections/provider.d.ts.map +1 -0
- package/dist/connections/server.d.ts +55 -0
- package/dist/connections/server.d.ts.map +1 -0
- package/dist/connections/types.d.ts +87 -0
- package/dist/connections/types.d.ts.map +1 -0
- package/dist/connections/url-policy.d.ts +30 -0
- package/dist/connections/url-policy.d.ts.map +1 -0
- package/dist/connections/wiring.d.ts +5 -0
- package/dist/connections/wiring.d.ts.map +1 -0
- package/dist/discovery.d.ts +11 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/dpop.d.ts +18 -0
- package/dist/dpop.d.ts.map +1 -0
- package/dist/failure.d.ts +14 -0
- package/dist/failure.d.ts.map +1 -0
- package/dist/github-identity.d.ts +11 -0
- package/dist/github-identity.d.ts.map +1 -0
- package/dist/github.d.ts +11 -0
- package/dist/github.d.ts.map +1 -0
- package/dist/google.d.ts +11 -0
- package/dist/google.d.ts.map +1 -0
- package/dist/guard-error.d.ts +14 -0
- package/dist/guard-error.d.ts.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1825 -0
- package/dist/index.js.map +51 -0
- package/dist/microsoft-tenant.d.ts +32 -0
- package/dist/microsoft-tenant.d.ts.map +1 -0
- package/dist/microsoft.d.ts +16 -0
- package/dist/microsoft.d.ts.map +1 -0
- package/dist/oauth2.d.ts +13 -0
- package/dist/oauth2.d.ts.map +1 -0
- package/dist/oidc-engine.d.ts +62 -0
- package/dist/oidc-engine.d.ts.map +1 -0
- package/dist/oidc-step-up.d.ts +15 -0
- package/dist/oidc-step-up.d.ts.map +1 -0
- package/dist/oidc.d.ts +11 -0
- package/dist/oidc.d.ts.map +1 -0
- package/dist/options.d.ts +108 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/pushed-authorization.d.ts +23 -0
- package/dist/pushed-authorization.d.ts.map +1 -0
- package/dist/step-up.d.ts +50 -0
- package/dist/step-up.d.ts.map +1 -0
- package/dist/transport.d.ts +18 -0
- package/dist/transport.d.ts.map +1 -0
- package/docs/README.md +35 -0
- package/docs/guide/custom-providers.md +182 -0
- package/docs/guide/github.md +109 -0
- package/docs/guide/google.md +103 -0
- package/docs/guide/microsoft.md +158 -0
- package/docs/guide/oidc-connections.md +265 -0
- package/docs/guide/oidc-step-up.md +122 -0
- package/docs/guide/par-dpop.md +63 -0
- package/docs/roadmap.md +33 -0
- package/docs/troubleshooting.md +632 -0
- package/package.json +67 -5
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `checkConnection`: the one gate a connection record passes, on the
|
|
3
|
+
* application's admin write path and again when the memory source is built.
|
|
4
|
+
*/
|
|
5
|
+
import { type OidcConnection } from './types';
|
|
6
|
+
export declare const PROVIDER_NAME: RegExp;
|
|
7
|
+
/** The scopes of a connection that lists none. */
|
|
8
|
+
export declare const DEFAULT_SCOPES: string[];
|
|
9
|
+
export declare const isObject: (value: unknown) => value is Record<string, unknown>;
|
|
10
|
+
/**
|
|
11
|
+
* Validates a connection record and answers it frozen, with the defaults
|
|
12
|
+
* written in (`scopes`, `emailTrust`) and the domains normalised. Throws one
|
|
13
|
+
* `TypeError` listing every problem by field name, never a value (the
|
|
14
|
+
* secret is in there). An unknown key, at the top or in `client`, is refused.
|
|
15
|
+
* Call it before storing a record.
|
|
16
|
+
*
|
|
17
|
+
* The answer is built from the validated fields in fresh objects: the
|
|
18
|
+
* caller's record is never frozen or kept. The issuer is stored and compared
|
|
19
|
+
* exactly as given (the discovery check compares it byte for byte), so it
|
|
20
|
+
* must be written with a lowercase `https` scheme and host and no empty, `.`
|
|
21
|
+
* or `..` path segment. Its host (loopback, private ranges) is not policed
|
|
22
|
+
* here but by the guarded fetch that reads its discovery document.
|
|
23
|
+
*/
|
|
24
|
+
export declare function checkConnection(record: unknown): OidcConnection;
|
|
25
|
+
//# sourceMappingURL=check.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/connections/check.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,EAIN,KAAK,cAAc,EACnB,MAAM,SAAS,CAAC;AAGjB,eAAO,MAAM,aAAa,QAA2B,CAAC;AAetD,kDAAkD;AAClD,eAAO,MAAM,cAAc,UAAiC,CAAC;AAuB7D,eAAO,MAAM,QAAQ,UAAW,OAAO,KAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CACJ,CAAC;AAyHtE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,GAAG,cAAc,CA4B/D"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** A connection's validated ID token claims, read into the core's `SocialIdentity` under its e-mail trust policy. */
|
|
2
|
+
import type { SocialIdentity } from '@softistx/janus';
|
|
3
|
+
import type { IDToken } from 'oauth4webapi';
|
|
4
|
+
import type { OidcConnection } from './types';
|
|
5
|
+
/** What the mapping reads of a connection record. */
|
|
6
|
+
export type ClaimPolicy = Pick<OidcConnection, 'domains' | 'emailTrust' | 'claims'>;
|
|
7
|
+
/**
|
|
8
|
+
* The identity the connection's identity provider vouches for. `sub` is the
|
|
9
|
+
* account, always. `emailVerified` is true only when the connection's
|
|
10
|
+
* `emailTrust` holds (`'claimAndDomain'` by default): a verified claim from a
|
|
11
|
+
* domain the connection does not own never reaches the core as verified, so
|
|
12
|
+
* the core refuses to link a local account by it. A malformed address is
|
|
13
|
+
* `email: null`, never verified. A claim that is not a string is ignored.
|
|
14
|
+
*/
|
|
15
|
+
export declare function connectionIdentity(connection: ClaimPolicy, claims: IDToken, step: string): SocialIdentity;
|
|
16
|
+
//# sourceMappingURL=claims.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claims.d.ts","sourceRoot":"","sources":["../../src/connections/claims.ts"],"names":[],"mappings":"AAAA,qHAAqH;AAErH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAI5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,qDAAqD;AACrD,MAAM,MAAM,WAAW,GAAG,IAAI,CAC7B,cAAc,EACd,SAAS,GAAG,YAAY,GAAG,QAAQ,CACnC,CAAC;AAkBF;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CACjC,UAAU,EAAE,WAAW,EACvB,MAAM,EAAE,OAAO,EACf,IAAI,EAAE,MAAM,GACV,cAAc,CA6BhB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Discovery of a connection's issuer through the guarded transport. */
|
|
2
|
+
import * as oauth from 'oauth4webapi';
|
|
3
|
+
import type { transport } from '../transport';
|
|
4
|
+
import { type AllowUrl } from './url-policy';
|
|
5
|
+
/**
|
|
6
|
+
* Reads the issuer's discovery document and refuses it, as a
|
|
7
|
+
* `PROVIDER_ERROR` with reason `refused`, unless:
|
|
8
|
+
* - its `issuer` equals the configured one **byte for byte** (oauth4webapi
|
|
9
|
+
* compares the parsed URLs, which would let `https://a.test` pass for
|
|
10
|
+
* `https://a.test/`);
|
|
11
|
+
* - the endpoints a sign-in needs (authorization, token, `jwks_uri`) are
|
|
12
|
+
* there, and every endpoint it names (those, PAR and userinfo) passes the
|
|
13
|
+
* URL policy, so a hostile document cannot aim the server at `http:`, a
|
|
14
|
+
* private address or the metadata service;
|
|
15
|
+
* - `none` is not among the ID token signature algorithms.
|
|
16
|
+
*
|
|
17
|
+
* The failure carries no URL and no part of the document.
|
|
18
|
+
*/
|
|
19
|
+
export declare function discoverIssuer(issuer: string, http: ReturnType<typeof transport>, allowUrl: AllowUrl | undefined): Promise<oauth.AuthorizationServer>;
|
|
20
|
+
//# sourceMappingURL=discovery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../../src/connections/discovery.ts"],"names":[],"mappings":"AAAA,wEAAwE;AAExE,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,KAAK,QAAQ,EAAc,MAAM,cAAc,CAAC;AASzD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAC7B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,UAAU,CAAC,OAAO,SAAS,CAAC,EAClC,QAAQ,EAAE,QAAQ,GAAG,SAAS,GAC5B,OAAO,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAsBpC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** E-mail domains as connections store and look them up: lowercase, punycode. */
|
|
2
|
+
/**
|
|
3
|
+
* The lowercase ASCII form of a domain, or `null` when it is not a plain
|
|
4
|
+
* domain name (empty, an address, a URL, a wildcard, a single label, an empty
|
|
5
|
+
* or over-long label, a label outside `a-z`, `0-9` and `-` or with an edge `-`, a `%`, an IP literal). One
|
|
6
|
+
* trailing dot is dropped; two are refused.
|
|
7
|
+
*/
|
|
8
|
+
export declare function normalizeDomain(value: unknown): string | null;
|
|
9
|
+
/**
|
|
10
|
+
* The normalised domain of an e-mail address, or `null`: it must hold no
|
|
11
|
+
* whitespace, one `@`, a non-empty local part and a domain `normalizeDomain`
|
|
12
|
+
* accepts. The one parser of `forEmail` and of the claim mapping.
|
|
13
|
+
*/
|
|
14
|
+
export declare function domainOfEmail(address: string): string | null;
|
|
15
|
+
//# sourceMappingURL=domain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain.d.ts","sourceRoot":"","sources":["../../src/connections/domain.ts"],"names":[],"mappings":"AAAA,iFAAiF;AAmBjF;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAM7D;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAK5D"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `fetch` every request to a tenant-configured identity provider goes
|
|
3
|
+
* through. Hand it to oauth4webapi as `[oauth.customFetch]`.
|
|
4
|
+
*
|
|
5
|
+
* Before each request the URL is checked (`urlRefusal`), its host resolved
|
|
6
|
+
* and every address checked (`addressesRefusal`). The request goes out with
|
|
7
|
+
* `redirect: 'manual'` and any 3xx (or opaque redirect) is refused, so a redirect never leads to
|
|
8
|
+
* a host the policy did not see. The answer must be JSON and within the cap.
|
|
9
|
+
* Every refusal is a `GuardError`, which the failure mapping reports as
|
|
10
|
+
* `PROVIDER_ERROR` with reason `refused`, except a DNS failure (`dns`) and a
|
|
11
|
+
* 5xx answer that is not JSON (`server-error`), which are `unreachable` like a
|
|
12
|
+
* network error or a timeout.
|
|
13
|
+
*
|
|
14
|
+
* **Known limit, DNS rebinding.** We check what the host resolves to, then
|
|
15
|
+
* `fetch` resolves it again to connect. A DNS server that answers a public
|
|
16
|
+
* address to the check and a private one to the connection (TOCTOU) is not
|
|
17
|
+
* stopped by this layer. Pinning the connection to the checked address needs
|
|
18
|
+
* a runtime hook `fetch` does not offer; an egress firewall or proxy that
|
|
19
|
+
* denies private ranges is the complete answer, and the application's own.
|
|
20
|
+
*/
|
|
21
|
+
import type { SocialFetch } from '../options';
|
|
22
|
+
import { type AllowUrl } from './url-policy';
|
|
23
|
+
/** Resolves a host to every address it has. Injected in specs; `node:dns` `lookup` by default. */
|
|
24
|
+
export type ResolveHost = (host: string) => Promise<readonly string[]>;
|
|
25
|
+
/** Milliseconds a request may take, answer body included, when `timeout` is absent. */
|
|
26
|
+
export declare const GUARD_TIMEOUT = 10000;
|
|
27
|
+
export interface GuardedFetchOptions {
|
|
28
|
+
/** The `fetch` to call once a request passes; the global one when absent. */
|
|
29
|
+
readonly fetch?: SocialFetch;
|
|
30
|
+
/** Milliseconds per request, body included. Default 10 000. */
|
|
31
|
+
readonly timeout?: number;
|
|
32
|
+
/** Narrows the built-in URL policy; it can never widen it. */
|
|
33
|
+
readonly allowUrl?: AllowUrl;
|
|
34
|
+
/** Resolves a host to all its addresses. Default: `node:dns/promises` `lookup(host, { all: true })`. */
|
|
35
|
+
readonly resolveHost?: ResolveHost;
|
|
36
|
+
/**
|
|
37
|
+
* The answer cap in bytes, or a function of the request URL so a caller
|
|
38
|
+
* can give the key set and userinfo `LARGE_MAX_BYTES`. Default 64 KiB.
|
|
39
|
+
*/
|
|
40
|
+
readonly maxBytes?: number | ((url: URL) => number);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A `fetch` that refuses what the policy refuses (see the module comment).
|
|
44
|
+
* The `fetch` it wraps must honour `init.redirect` (the guard sends `'manual'`
|
|
45
|
+
* and refuses any 3xx; a `fetch` that follows redirects anyway defeats the
|
|
46
|
+
* check) and `init.signal` (the guard's timeout and the caller's abort).
|
|
47
|
+
*/
|
|
48
|
+
export declare function guardedFetch(options?: GuardedFetchOptions): SocialFetch;
|
|
49
|
+
//# sourceMappingURL=guarded-fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guarded-fetch.d.ts","sourceRoot":"","sources":["../../src/connections/guarded-fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAG9C,OAAO,EACN,KAAK,QAAQ,EAIb,MAAM,cAAc,CAAC;AAEtB,kGAAkG;AAClG,MAAM,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAAC;AAEvE,uFAAuF;AACvF,eAAO,MAAM,aAAa,QAAS,CAAC;AAEpC,MAAM,WAAW,mBAAmB;IACnC,6EAA6E;IAC7E,QAAQ,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC;IAC7B,+DAA+D;IAC/D,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,8DAA8D;IAC9D,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAC7B,wGAAwG;IACxG,QAAQ,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC;IACnC;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,CAAC,CAAC;CACpD;AAKD;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,WAAW,CAwC3E"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** The steps a connection hands to the code exchange, built from its {@link IdTokenPolicy}. */
|
|
2
|
+
import type { IdTokenSteps } from '../code-exchange';
|
|
3
|
+
import { type IdTokenPolicy } from './id-token';
|
|
4
|
+
/**
|
|
5
|
+
* The exchange's extra steps for a connection. `verifyKeys` is the connection
|
|
6
|
+
* server's `verifySignature`. Throws a `TypeError` at wiring when the
|
|
7
|
+
* pinned algorithm is not an accepted one.
|
|
8
|
+
*
|
|
9
|
+
* Order, in the exchange: oauth4webapi's checks (which read the claims, but
|
|
10
|
+
* answer nothing), the `alg` against the accepted list, the signature, then
|
|
11
|
+
* our claim checks: no claim is trusted, or handed on, before the signature
|
|
12
|
+
* holds.
|
|
13
|
+
*/
|
|
14
|
+
export declare function idTokenSteps(policy: IdTokenPolicy, verifyKeys: (answer: Response) => Promise<void>): IdTokenSteps;
|
|
15
|
+
//# sourceMappingURL=id-token-steps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id-token-steps.d.ts","sourceRoot":"","sources":["../../src/connections/id-token-steps.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAE/F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAON,KAAK,aAAa,EAElB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAC3B,MAAM,EAAE,aAAa,EACrB,UAAU,EAAE,CAAC,MAAM,EAAE,QAAQ,KAAK,OAAO,CAAC,IAAI,CAAC,GAC7C,YAAY,CA2Bd"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a connection's ID token must prove, on top of oauth4webapi.
|
|
3
|
+
*
|
|
4
|
+
* **oauth4webapi 3.8.8 checks** (in `processAuthorizationCodeResponse`):
|
|
5
|
+
* `iss` equals the discovered issuer; `aud` holds the client id; `azp` equals
|
|
6
|
+
* the client id when `aud` has several members (and is then required);
|
|
7
|
+
* `exp` is not past `now - tolerance`; `nbf` is not after `now + tolerance`;
|
|
8
|
+
* `iat`, `sub`, `exp`, `aud`, `iss` and `nonce` are present; the nonce
|
|
9
|
+
* matches; the `alg` is the client's `id_token_signed_response_alg`, else one
|
|
10
|
+
* of the metadata's list, else `RS256`. Its signature step
|
|
11
|
+
* (`validateApplicationLevelSignature`) refuses `HS*` and an unknown `alg`,
|
|
12
|
+
* reads only keys of the issuer's JWKS, takes only an Ed25519 key for `EdDSA`,
|
|
13
|
+
* and refuses an RSA key under 2048 bits.
|
|
14
|
+
*
|
|
15
|
+
* **This module adds**: the `alg` is one of the connection's accepted list
|
|
16
|
+
* *before* any key is fetched, so the metadata cannot widen it: the pinned
|
|
17
|
+
* algorithm, else the intersection of `RS256`, `PS256`, `ES256` and `EdDSA`
|
|
18
|
+
* with what the metadata lists (`RS256` when it lists none); `iss` equals the
|
|
19
|
+
* connection's issuer byte for byte; `azp`, when present, equals the client id
|
|
20
|
+
* even with one audience; `iat` is at most 30 s in the future (the one clock
|
|
21
|
+
* tolerance, shared with `exp` and `nbf`); `sub` is a non-empty string of 255
|
|
22
|
+
* characters or fewer; `at_hash`, when present, matches the access token; and
|
|
23
|
+
* a connection's fixed step-up is held by the token's `acr` and `auth_time`.
|
|
24
|
+
* No claim is trusted before the signature holds: the checks run in that order.
|
|
25
|
+
*
|
|
26
|
+
* Every refusal is `PROVIDER_ERROR` with reason `refused`, its `cause`
|
|
27
|
+
* naming the check (`{ check: 'iat' }`) and never a token, a claim or a key.
|
|
28
|
+
* Two exceptions: an unmet step-up is `SOCIAL_STEP_UP_UNMET`, and a failure to
|
|
29
|
+
* fetch the keys is `PROVIDER_ERROR` with reason `unreachable`.
|
|
30
|
+
*/
|
|
31
|
+
import { SocialError } from '@softistx/janus';
|
|
32
|
+
import type * as oauth from 'oauth4webapi';
|
|
33
|
+
import { type FixedStepUp } from '../step-up';
|
|
34
|
+
import { type ConnectionAlgorithm } from './types';
|
|
35
|
+
/** Seconds of clock skew allowed on `exp`, `nbf` and `iat`: fixed, not a setting. */
|
|
36
|
+
export declare const CLOCK_TOLERANCE = 30;
|
|
37
|
+
/** The algorithms a connection that pins none accepts. */
|
|
38
|
+
export declare const DEFAULT_ALGORITHMS: readonly ConnectionAlgorithm[];
|
|
39
|
+
/** What the checks need to know about the connection. */
|
|
40
|
+
export interface IdTokenPolicy {
|
|
41
|
+
readonly issuer: string;
|
|
42
|
+
readonly clientId: string;
|
|
43
|
+
/** `client.idTokenSignedResponseAlg`: the one algorithm, when pinned. */
|
|
44
|
+
readonly algorithm?: ConnectionAlgorithm | undefined;
|
|
45
|
+
readonly stepUp?: FixedStepUp | undefined;
|
|
46
|
+
/** Epoch milliseconds; `Date.now()` when absent (oauth4webapi reads it too). */
|
|
47
|
+
readonly now?: (() => number) | undefined;
|
|
48
|
+
}
|
|
49
|
+
/** The refusal of one check: `PROVIDER_ERROR`, `refused`, naming the check only. */
|
|
50
|
+
export declare function refused(check: string): SocialError;
|
|
51
|
+
/** The algorithms the connection accepts: its pinned one, else {@link DEFAULT_ALGORITHMS}. */
|
|
52
|
+
export declare function algorithmsOf(pinned: ConnectionAlgorithm | undefined): readonly ConnectionAlgorithm[];
|
|
53
|
+
/** The `alg` of an ID token's header, read without trusting anything else in it. */
|
|
54
|
+
export declare function headerAlgorithm(idToken: unknown): string;
|
|
55
|
+
/** Refuses an `alg` outside the list, before the signature step fetches a key. */
|
|
56
|
+
export declare function checkAlgorithm(idToken: unknown, algorithms: readonly ConnectionAlgorithm[]): string;
|
|
57
|
+
/** `iss`, `sub`, `azp` and `iat`: what oauth4webapi leaves open. */
|
|
58
|
+
export declare function checkClaims(claims: oauth.IDToken, policy: IdTokenPolicy, nowSeconds: number): void;
|
|
59
|
+
/** `at_hash`, when the token carries one; absent is accepted (the code flow makes it optional). */
|
|
60
|
+
export declare function checkAtHash(claims: oauth.IDToken, alg: string, accessToken: string): Promise<void>;
|
|
61
|
+
/** The connection's fixed step-up, held by the token's own claims. */
|
|
62
|
+
export declare function requireStepUp(claims: oauth.IDToken, stepUp: FixedStepUp | undefined, nowMs: number): void;
|
|
63
|
+
//# sourceMappingURL=id-token.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id-token.d.ts","sourceRoot":"","sources":["../../src/connections/id-token.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,KAAK,WAAW,EAAe,MAAM,YAAY,CAAC;AAE3D,OAAO,EAAyB,KAAK,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE1E,qFAAqF;AACrF,eAAO,MAAM,eAAe,KAAK,CAAC;AAClC,0DAA0D;AAC1D,eAAO,MAAM,kBAAkB,EAAE,SAAS,mBAAmB,EAK5D,CAAC;AAIF,yDAAyD;AACzD,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,yEAAyE;IACzE,QAAQ,CAAC,SAAS,CAAC,EAAE,mBAAmB,GAAG,SAAS,CAAC;IACrD,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;IAC1C,gFAAgF;IAChF,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,MAAM,CAAC,GAAG,SAAS,CAAC;CAC1C;AAED,oFAAoF;AACpF,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAElD;AAED,8FAA8F;AAC9F,wBAAgB,YAAY,CAC3B,MAAM,EAAE,mBAAmB,GAAG,SAAS,GACrC,SAAS,mBAAmB,EAAE,CAQhC;AAED,oFAAoF;AACpF,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAYxD;AAED,kFAAkF;AAClF,wBAAgB,cAAc,CAC7B,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,SAAS,mBAAmB,EAAE,GACxC,MAAM,CAIR;AAED,oEAAoE;AACpE,wBAAgB,WAAW,CAC1B,MAAM,EAAE,KAAK,CAAC,OAAO,EACrB,MAAM,EAAE,aAAa,EACrB,UAAU,EAAE,MAAM,GAChB,IAAI,CAYN;AAED,mGAAmG;AACnG,wBAAsB,WAAW,CAChC,MAAM,EAAE,KAAK,CAAC,OAAO,EACrB,GAAG,EAAE,MAAM,EACX,WAAW,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CAIf;AAED,sEAAsE;AACtE,wBAAgB,aAAa,CAC5B,MAAM,EAAE,KAAK,CAAC,OAAO,EACrB,MAAM,EAAE,WAAW,GAAG,SAAS,EAC/B,KAAK,EAAE,MAAM,GACX,IAAI,CAQN"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** The building blocks of `oidcConnections`: the record, its check and the read-only source. */
|
|
2
|
+
export { checkConnection } from './check';
|
|
3
|
+
export type { ResolveHost } from './guarded-fetch';
|
|
4
|
+
export type { IssuerCacheSetting } from './issuer-cache';
|
|
5
|
+
export { createMemoryConnections } from './memory';
|
|
6
|
+
export type { OidcConnections, OidcConnectionsOptions, } from './oidc-connections';
|
|
7
|
+
export { oidcConnections } from './oidc-connections';
|
|
8
|
+
export type { ClaimNames, ConnectionAlgorithm, ConnectionClient, ConnectionSource, EmailTrust, OidcConnection, } from './types';
|
|
9
|
+
export { CONNECTION_ALGORITHMS } from './types';
|
|
10
|
+
export type { AllowUrl } from './url-policy';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connections/index.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAEhG,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC1C,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,YAAY,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AACnD,YAAY,EACX,eAAe,EACf,sBAAsB,GACtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,YAAY,EACX,UAAU,EACV,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACV,cAAc,GACd,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAChD,YAAY,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Parsing and ranges of IP literals, no I/O. */
|
|
2
|
+
type V4 = readonly [number, number, number, number];
|
|
3
|
+
/** A canonical dotted-decimal IPv4 address, or `undefined`. */
|
|
4
|
+
export declare function parseV4(text: string): V4 | undefined;
|
|
5
|
+
/** An IPv6 address (brackets and a dotted IPv4 tail allowed) as eight 16-bit groups, or `undefined`. */
|
|
6
|
+
export declare function parseV6(text: string): readonly number[] | undefined;
|
|
7
|
+
/** Whether a public host may own this IPv4 address. */
|
|
8
|
+
export declare function publicV4([a, b, c]: V4): boolean;
|
|
9
|
+
/** Whether a public host may own this IPv6 address (eight groups). */
|
|
10
|
+
export declare function publicV6(g: readonly number[]): boolean;
|
|
11
|
+
/** Whether an address given as text (either family) may belong to a public host. An unreadable one may not. */
|
|
12
|
+
export declare function publicAddress(text: string): boolean;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=ip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ip.d.ts","sourceRoot":"","sources":["../../src/connections/ip.ts"],"names":[],"mappings":"AAAA,iDAAiD;AAEjD,KAAK,EAAE,GAAG,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAEpD,+DAA+D;AAC/D,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,EAAE,GAAG,SAAS,CAWpD;AAED,wGAAwG;AACxG,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,GAAG,SAAS,CA6BnE;AAED,uDAAuD;AACvD,wBAAgB,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,CAY/C;AASD,sEAAsE;AACtE,wBAAgB,QAAQ,CAAC,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CA8CtD;AAED,+GAA+G;AAC/G,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAKnD"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A per-issuer cache of what a lookup found: kept for a time, shared by
|
|
3
|
+
* concurrent callers, and never poisoned by a failure.
|
|
4
|
+
*/
|
|
5
|
+
import type { Clock } from '@softistx/janus';
|
|
6
|
+
/** How long a found value is kept: 1 hour. */
|
|
7
|
+
export declare const ISSUER_TTL_MS = 3600000;
|
|
8
|
+
/** After a failure, how long a lookup fails fast without a network call: 30 seconds. */
|
|
9
|
+
export declare const FAILURE_COOLDOWN_MS = 30000;
|
|
10
|
+
/** Issuers kept by default. */
|
|
11
|
+
export declare const DEFAULT_MAX_ISSUERS = 500;
|
|
12
|
+
/** Unused for this long, an issuer is dropped: 1 hour. */
|
|
13
|
+
export declare const DEFAULT_IDLE_MS = 3600000;
|
|
14
|
+
/** The `cache` option of the connections. */
|
|
15
|
+
export interface IssuerCacheOptions {
|
|
16
|
+
/** Issuers kept; the least recently used goes first. Default 500. */
|
|
17
|
+
readonly max?: number;
|
|
18
|
+
/** Milliseconds an issuer may go unused before it is dropped. Default 1 hour. */
|
|
19
|
+
readonly idleMs?: number;
|
|
20
|
+
/** A lookup still pending after this many milliseconds is not shared any more. */
|
|
21
|
+
readonly pendingMs?: number;
|
|
22
|
+
}
|
|
23
|
+
/** The `cache` option the application sets: `max` and `idleMs` only. */
|
|
24
|
+
export type IssuerCacheSetting = Pick<IssuerCacheOptions, 'max' | 'idleMs'>;
|
|
25
|
+
export interface IssuerCache<V> {
|
|
26
|
+
/**
|
|
27
|
+
* The value for `issuer`: the kept one, the lookup already in flight, or a
|
|
28
|
+
* new `load()`. During the cooldown after a failure it throws that same
|
|
29
|
+
* failure and calls nothing.
|
|
30
|
+
*/
|
|
31
|
+
get(issuer: string, load: () => Promise<V>): Promise<V>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* An LRU map with an idle limit and no timer: the order of a `Map` is the
|
|
35
|
+
* recency, and an entry unused for `idleMs` is dropped on the next call.
|
|
36
|
+
* The failure is kept 30 s (not the value, which a failure never is), so a
|
|
37
|
+
* down provider is asked once per 30 s rather than once per sign-in.
|
|
38
|
+
*/
|
|
39
|
+
export declare function createIssuerCache<V>(clock: Clock, options?: IssuerCacheOptions): IssuerCache<V>;
|
|
40
|
+
//# sourceMappingURL=issuer-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"issuer-cache.d.ts","sourceRoot":"","sources":["../../src/connections/issuer-cache.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAE7C,8CAA8C;AAC9C,eAAO,MAAM,aAAa,UAAY,CAAC;AACvC,wFAAwF;AACxF,eAAO,MAAM,mBAAmB,QAAS,CAAC;AAC1C,+BAA+B;AAC/B,eAAO,MAAM,mBAAmB,MAAM,CAAC;AACvC,0DAA0D;AAC1D,eAAO,MAAM,eAAe,UAAY,CAAC;AAEzC,6CAA6C;AAC7C,MAAM,WAAW,kBAAkB;IAClC,qEAAqE;IACrE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,iFAAiF;IACjF,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,kFAAkF;IAClF,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC5B;AAYD,wEAAwE;AACxE,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,kBAAkB,EAAE,KAAK,GAAG,QAAQ,CAAC,CAAC;AAE5E,MAAM,WAAW,WAAW,CAAC,CAAC;IAC7B;;;;OAIG;IACH,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACxD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAClC,KAAK,EAAE,KAAK,EACZ,OAAO,GAAE,kBAAuB,GAC9B,WAAW,CAAC,CAAC,CAAC,CA2DhB"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** The issuer of a connection: an https URL held exactly as written. */
|
|
2
|
+
/** Pushes a problem unless `issuer` is an https URL with no query, fragment, credentials, empty, `.` or `..` segment, and a lowercase scheme and host. */
|
|
3
|
+
export declare function checkIssuer(problems: string[], issuer: unknown): void;
|
|
4
|
+
//# sourceMappingURL=issuer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"issuer.d.ts","sourceRoot":"","sources":["../../src/connections/issuer.ts"],"names":[],"mappings":"AAAA,wEAAwE;AAMxE,0JAA0J;AAC1J,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI,CAkCrE"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single flight and a short cooldown for the key set requests, which
|
|
3
|
+
* oauth4webapi does not share between concurrent verifications.
|
|
4
|
+
*/
|
|
5
|
+
import type { Clock } from '@softistx/janus';
|
|
6
|
+
import type { SocialFetch } from '../options';
|
|
7
|
+
/**
|
|
8
|
+
* Wraps a `fetch` so that concurrent requests for one URL make one request
|
|
9
|
+
* (each caller gets a clone of the answer: the first caller's method, headers
|
|
10
|
+
* and signal decide it, so use it for GETs only), and a request that failed
|
|
11
|
+
* makes the next ones within 30 s fail the same way without a call. State is
|
|
12
|
+
* per URL and shared by every wrapped `fetch`; a failed entry is dropped when
|
|
13
|
+
* the next call finds it 30 s old.
|
|
14
|
+
*/
|
|
15
|
+
export declare function keyFlights(clock: Clock): (base: SocialFetch) => SocialFetch;
|
|
16
|
+
//# sourceMappingURL=key-flights.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key-flights.d.ts","sourceRoot":"","sources":["../../src/connections/key-flights.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAQ9C;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,IAAI,EAAE,WAAW,KAAK,WAAW,CAsC3E"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** `createMemoryConnections`: a reference `ConnectionSource` over a list of records. */
|
|
2
|
+
import type { ConnectionSource } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* A {@link ConnectionSource} over records held in memory, for specs and
|
|
5
|
+
* examples; the application implements the port over its own table. Each
|
|
6
|
+
* record goes through `checkConnection`, and a duplicate id or a domain two
|
|
7
|
+
* records claim is refused at creation.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createMemoryConnections(records: readonly unknown[]): ConnectionSource;
|
|
10
|
+
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/connections/memory.ts"],"names":[],"mappings":"AAAA,wFAAwF;AAIxF,OAAO,KAAK,EAAE,gBAAgB,EAAkB,MAAM,SAAS,CAAC;AAEhE;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACtC,OAAO,EAAE,SAAS,OAAO,EAAE,GACzB,gBAAgB,CA2BlB"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `oidcConnections`: the facade that turns the application's stored
|
|
3
|
+
* connections into providers for the core's `social.resolveProvider`.
|
|
4
|
+
*/
|
|
5
|
+
import type { Clock, SocialProvider } from '@softistx/janus';
|
|
6
|
+
import type { SocialFetch } from '../options';
|
|
7
|
+
import type { ResolveHost } from './guarded-fetch';
|
|
8
|
+
import type { IssuerCacheSetting } from './issuer-cache';
|
|
9
|
+
import type { ConnectionSource } from './types';
|
|
10
|
+
import type { AllowUrl } from './url-policy';
|
|
11
|
+
export interface OidcConnectionsOptions {
|
|
12
|
+
/** Where the connections live: the application's own table. */
|
|
13
|
+
readonly source: ConnectionSource;
|
|
14
|
+
/**
|
|
15
|
+
* The callback URL registered with every identity provider; the same for
|
|
16
|
+
* all connections. `https`, or `http` on a loopback host.
|
|
17
|
+
*/
|
|
18
|
+
readonly redirectUri: string;
|
|
19
|
+
/**
|
|
20
|
+
* The `fetch` to call once a request passes the URL guard; the global one
|
|
21
|
+
* when absent. It must honour `init.redirect` (the guard sends `'manual'`
|
|
22
|
+
* and refuses any 3xx) and `init.signal` (the guard's timeout).
|
|
23
|
+
*/
|
|
24
|
+
readonly fetch?: SocialFetch;
|
|
25
|
+
/** Milliseconds per request, body included. Default 10 000. */
|
|
26
|
+
readonly timeout?: number;
|
|
27
|
+
/** Narrows the URL policy (a host allow-list, say); it can never widen it. */
|
|
28
|
+
readonly allowUrl?: AllowUrl;
|
|
29
|
+
/** The discovery cache: issuers kept (default 500) and idle milliseconds (default 1 hour). */
|
|
30
|
+
readonly cache?: IssuerCacheSetting;
|
|
31
|
+
/**
|
|
32
|
+
* The time of the discovery cache, and nothing else. The ID token's `exp`
|
|
33
|
+
* and `nbf` are checked by oauth4webapi on the system clock, so a fixed
|
|
34
|
+
* clock here never moves them.
|
|
35
|
+
*/
|
|
36
|
+
readonly clock?: Clock;
|
|
37
|
+
/**
|
|
38
|
+
* Resolves a host to all its addresses, for the URL guard that checks
|
|
39
|
+
* every address before a request. Default: `node:dns/promises`
|
|
40
|
+
* `lookup(host, { all: true })`. Give a fake in specs so discovery
|
|
41
|
+
* needs no real DNS and no global mock of `node:dns/promises`; the
|
|
42
|
+
* addresses it answers are still checked by the policy.
|
|
43
|
+
*/
|
|
44
|
+
readonly resolveHost?: ResolveHost;
|
|
45
|
+
}
|
|
46
|
+
export interface OidcConnections {
|
|
47
|
+
/**
|
|
48
|
+
* Answers the provider of connection `name`, for `social.resolveProvider`.
|
|
49
|
+
* `null` when `name` is not a provider name (it never reaches the source) or
|
|
50
|
+
* the source has no such connection. A failure of the source
|
|
51
|
+
* propagates untouched; a stored record that fails `checkConnection` (or
|
|
52
|
+
* whose `id` is not `name`) is `PROVIDER_ERROR` with the reason `'refused'`
|
|
53
|
+
* and one process warning naming the id, never a value.
|
|
54
|
+
*/
|
|
55
|
+
resolve(name: string): Promise<SocialProvider | null>;
|
|
56
|
+
/**
|
|
57
|
+
* Home-realm discovery: the id of the connection that owns the domain of
|
|
58
|
+
* `email`, or `null` (unknown domain, or not an address).
|
|
59
|
+
*/
|
|
60
|
+
forEmail(email: string): Promise<string | null>;
|
|
61
|
+
}
|
|
62
|
+
/** The facade. `resolveHost` as a second argument is kept for older specs; the option wins. */
|
|
63
|
+
export declare function createConnections(options: OidcConnectionsOptions, resolveHostArgument?: ResolveHost): OidcConnections;
|
|
64
|
+
/**
|
|
65
|
+
* The connections of an application as providers: wire `resolve` into the
|
|
66
|
+
* core's `social.resolveProvider`, and use `forEmail` to send a visitor to
|
|
67
|
+
* their company's sign-in. Throws a `TypeError` at construction for a bad
|
|
68
|
+
* option, never later.
|
|
69
|
+
*/
|
|
70
|
+
export declare function oidcConnections(options: OidcConnectionsOptions): OidcConnections;
|
|
71
|
+
//# sourceMappingURL=oidc-connections.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oidc-connections.d.ts","sourceRoot":"","sources":["../../src/connections/oidc-connections.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAE7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAG9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAGzD,OAAO,KAAK,EAAE,gBAAgB,EAAkB,MAAM,SAAS,CAAC;AAChE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG7C,MAAM,WAAW,sBAAsB;IACtC,+DAA+D;IAC/D,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC;IAClC;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC;IAC7B,+DAA+D;IAC/D,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,8EAA8E;IAC9E,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAC7B,8FAA8F;IAC9F,QAAQ,CAAC,KAAK,CAAC,EAAE,kBAAkB,CAAC;IACpC;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IACvB;;;;;;OAMG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC;CACnC;AAED,MAAM,WAAW,eAAe;IAC/B;;;;;;;OAOG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IACtD;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CAChD;AAED,+FAA+F;AAC/F,wBAAgB,iBAAiB,CAChC,OAAO,EAAE,sBAAsB,EAC/B,mBAAmB,CAAC,EAAE,WAAW,GAC/B,eAAe,CA0DjB;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC9B,OAAO,EAAE,sBAAsB,GAC7B,eAAe,CAEjB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** The `SocialProvider` of one connection record, on the same engine as the presets. */
|
|
2
|
+
import type { SocialProvider } from '@softistx/janus';
|
|
3
|
+
import type { ConnectionServers } from './server';
|
|
4
|
+
import type { OidcConnection } from './types';
|
|
5
|
+
/** What every provider of one facade shares. */
|
|
6
|
+
export interface ProviderWiring {
|
|
7
|
+
readonly servers: ConnectionServers;
|
|
8
|
+
readonly redirectUri: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Builds the provider of a record that passed `checkConnection` (call it
|
|
12
|
+
* first: this trusts the record). Throws a `TypeError` when the ID token
|
|
13
|
+
* steps cannot be wired from it, so the caller can refuse the record up
|
|
14
|
+
* front rather than at request time.
|
|
15
|
+
*
|
|
16
|
+
* There is one way to build the exchange: the server, its transport and the
|
|
17
|
+
* signature check all come from one `servers(connection)` lookup, since
|
|
18
|
+
* oauth4webapi keys its key cache on that server object, and `idToken` is
|
|
19
|
+
* always set, so the signature is always verified. The provider holds no
|
|
20
|
+
* `fetch` of its own: every request goes through the guarded transport of
|
|
21
|
+
* the server lookup. Claims go through
|
|
22
|
+
* `connectionIdentity`, never a preset's mapping.
|
|
23
|
+
*/
|
|
24
|
+
export declare function connectionProvider(connection: OidcConnection, wiring: ProviderWiring): SocialProvider;
|
|
25
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/connections/provider.ts"],"names":[],"mappings":"AAAA,wFAAwF;AAExF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAMtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,gDAAgD;AAChD,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC;IACpC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC7B;AAiBD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CACjC,UAAU,EAAE,cAAc,EAC1B,MAAM,EAAE,cAAc,GACpB,cAAc,CA8BhB"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The authorization server of a connection: its discovered metadata and the
|
|
3
|
+
* way to check a signature against its keys, for the ID token checks.
|
|
4
|
+
*/
|
|
5
|
+
import { type Clock } from '@softistx/janus';
|
|
6
|
+
import * as oauth from 'oauth4webapi';
|
|
7
|
+
import type { SocialFetch } from '../options';
|
|
8
|
+
import { transport } from '../transport';
|
|
9
|
+
import { type GuardedFetchOptions } from './guarded-fetch';
|
|
10
|
+
import { type IssuerCacheSetting } from './issuer-cache';
|
|
11
|
+
import type { OidcConnection } from './types';
|
|
12
|
+
import type { AllowUrl } from './url-policy';
|
|
13
|
+
export interface ServerOptions {
|
|
14
|
+
/**
|
|
15
|
+
* The `fetch` to call once a request passes the guard; the global one when
|
|
16
|
+
* absent. It must honour `init.redirect` (the guard sends `'manual'`) and
|
|
17
|
+
* `init.signal` (the guard's timeout), like the platform's.
|
|
18
|
+
*/
|
|
19
|
+
readonly fetch?: SocialFetch;
|
|
20
|
+
/** Milliseconds per request, body included. Default 10 000. */
|
|
21
|
+
readonly timeout?: number;
|
|
22
|
+
/** Narrows the URL policy; it can never widen it. */
|
|
23
|
+
readonly allowUrl?: AllowUrl;
|
|
24
|
+
/** Resolves a host to all its addresses; `node:dns` by default. */
|
|
25
|
+
readonly resolveHost?: GuardedFetchOptions['resolveHost'];
|
|
26
|
+
readonly cache?: IssuerCacheSetting;
|
|
27
|
+
/** The time of the cache; the system clock when absent. */
|
|
28
|
+
readonly clock?: Clock;
|
|
29
|
+
}
|
|
30
|
+
/** What a connection's issuer gave, valid until the metadata cache drops it. */
|
|
31
|
+
export interface ConnectionServer {
|
|
32
|
+
/**
|
|
33
|
+
* The discovered metadata, every endpoint already through the URL policy.
|
|
34
|
+
* **The same object** until the metadata is refetched (1 h): oauth4webapi
|
|
35
|
+
* keys its key cache on this object's identity, so always pass this one.
|
|
36
|
+
*/
|
|
37
|
+
readonly as: oauth.AuthorizationServer;
|
|
38
|
+
/**
|
|
39
|
+
* Request options for oauth4webapi calls to this server's endpoints: the
|
|
40
|
+
* guarded fetch (64 KiB cap) and the timeout.
|
|
41
|
+
*/
|
|
42
|
+
readonly http: ReturnType<typeof transport>;
|
|
43
|
+
/**
|
|
44
|
+
* Checks the signature of the ID token in `ref` (the token response that
|
|
45
|
+
* `processAuthorizationCodeResponse` returned) against the issuer's keys,
|
|
46
|
+
* fetched through the guard (256 KiB cap). oauth4webapi keeps the key set
|
|
47
|
+
* per `as`: an unknown `kid` refetches it only when the kept set is 60 s
|
|
48
|
+
* old or more, and a set 300 s old or more is never used.
|
|
49
|
+
*/
|
|
50
|
+
verifySignature(ref: Response): Promise<void>;
|
|
51
|
+
}
|
|
52
|
+
/** Looks up a connection's server: cached per issuer, one lookup in flight at a time. */
|
|
53
|
+
export type ConnectionServers = (connection: Pick<OidcConnection, 'issuer'>) => Promise<ConnectionServer>;
|
|
54
|
+
export declare function connectionServers(options?: ServerOptions): ConnectionServers;
|
|
55
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/connections/server.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,KAAK,EAAe,MAAM,iBAAiB,CAAC;AAC1D,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,OAAO,EAEN,KAAK,mBAAmB,EAExB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAqB,KAAK,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAE5E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE7C,MAAM,WAAW,aAAa;IAC7B;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC;IAC7B,+DAA+D;IAC/D,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,qDAAqD;IACrD,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAC7B,mEAAmE;IACnE,QAAQ,CAAC,WAAW,CAAC,EAAE,mBAAmB,CAAC,aAAa,CAAC,CAAC;IAC1D,QAAQ,CAAC,KAAK,CAAC,EAAE,kBAAkB,CAAC;IACpC,2DAA2D;IAC3D,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;CACvB;AAED,gFAAgF;AAChF,MAAM,WAAW,gBAAgB;IAChC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC,mBAAmB,CAAC;IACvC;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC;IAC5C;;;;;;OAMG;IACH,eAAe,CAAC,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9C;AAED,yFAAyF;AACzF,MAAM,MAAM,iBAAiB,GAAG,CAC/B,UAAU,EAAE,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAC,KACtC,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAe/B,wBAAgB,iBAAiB,CAChC,OAAO,GAAE,aAAkB,GACzB,iBAAiB,CAwDnB"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/** The record of an upstream OpenID Connect connection and the port that reads it. */
|
|
2
|
+
import type { OidcSecurityOptions } from '../options';
|
|
3
|
+
import type { FixedStepUp } from '../step-up';
|
|
4
|
+
/**
|
|
5
|
+
* The signature algorithms an ID token may be signed with: asymmetric only.
|
|
6
|
+
* `none` and the `HS*` family are not here, so they cannot be written; the
|
|
7
|
+
* check refuses them at runtime too, for a record read from a database.
|
|
8
|
+
*/
|
|
9
|
+
export declare const CONNECTION_ALGORITHMS: readonly ['RS256', 'RS384', 'RS512', 'PS256', 'PS384', 'PS512', 'ES256', 'ES384', 'ES512', 'EdDSA'];
|
|
10
|
+
/** One of {@link CONNECTION_ALGORITHMS}. */
|
|
11
|
+
export type ConnectionAlgorithm = (typeof CONNECTION_ALGORITHMS)[number];
|
|
12
|
+
/**
|
|
13
|
+
* Which e-mails of the identity provider count as proven:
|
|
14
|
+
* - `'claimAndDomain'` (default): the `email_verified` claim is true and the
|
|
15
|
+
* address is in one of the connection's `domains`;
|
|
16
|
+
* - `'domain'`: the address is in one of `domains` (for providers that do not
|
|
17
|
+
* send `email_verified`, such as Entra ID);
|
|
18
|
+
* - `'claim'`: the claim alone. Opt-in; a tenant can then assert any address.
|
|
19
|
+
*/
|
|
20
|
+
export type EmailTrust = 'claimAndDomain' | 'domain' | 'claim';
|
|
21
|
+
/** The names of the ID token claims that fill the identity. Absent keys keep the standard names. */
|
|
22
|
+
export interface ClaimNames {
|
|
23
|
+
readonly email?: string;
|
|
24
|
+
readonly emailVerified?: string;
|
|
25
|
+
readonly name?: string;
|
|
26
|
+
readonly picture?: string;
|
|
27
|
+
}
|
|
28
|
+
/** The client this application is registered as at the identity provider. */
|
|
29
|
+
export interface ConnectionClient {
|
|
30
|
+
/** The client id. */
|
|
31
|
+
readonly id: string;
|
|
32
|
+
/** The client secret. Never logged, never put in an error. */
|
|
33
|
+
readonly secret: string;
|
|
34
|
+
/** How the secret reaches the token endpoint. Absent: the method the server lists (`'post'` when it does, else `'basic'`), as for the presets. */
|
|
35
|
+
readonly authentication?: 'post' | 'basic';
|
|
36
|
+
/**
|
|
37
|
+
* The one algorithm the ID token must be signed with
|
|
38
|
+
* (`id_token_signed_response_alg`). Absent: any of `RS256`, `PS256`,
|
|
39
|
+
* `ES256` and `EdDSA`.
|
|
40
|
+
*/
|
|
41
|
+
readonly idTokenSignedResponseAlg?: ConnectionAlgorithm;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* An upstream OpenID Connect connection: one tenant's identity provider,
|
|
45
|
+
* stored by the application and read through a {@link ConnectionSource}.
|
|
46
|
+
*/
|
|
47
|
+
export interface OidcConnection extends OidcSecurityOptions {
|
|
48
|
+
/**
|
|
49
|
+
* The provider name: what the sign-in URL, the link records and the events
|
|
50
|
+
* carry (`/^[a-z][a-z0-9-]{0,31}$/`). **Never changed while accounts are
|
|
51
|
+
* linked**: a new issuer is a new id.
|
|
52
|
+
*/
|
|
53
|
+
readonly id: string;
|
|
54
|
+
/** The issuer URL (`https`), whose discovery document is read. **Never changed while accounts are linked.** */
|
|
55
|
+
readonly issuer: string;
|
|
56
|
+
readonly client: ConnectionClient;
|
|
57
|
+
/** Scopes to ask for; `openid` is always added. `['openid', 'email', 'profile']` when absent. */
|
|
58
|
+
readonly scopes?: readonly string[];
|
|
59
|
+
/**
|
|
60
|
+
* The e-mail domains this connection is the sign-in of, verified by the
|
|
61
|
+
* application (not by the identity provider). Lowercased and converted to
|
|
62
|
+
* punycode by the check. Unique across connections.
|
|
63
|
+
*/
|
|
64
|
+
readonly domains: readonly string[];
|
|
65
|
+
/** `'claimAndDomain'` when absent. */
|
|
66
|
+
readonly emailTrust?: EmailTrust;
|
|
67
|
+
readonly claims?: ClaimNames;
|
|
68
|
+
/** Held on every sign-in through this connection. */
|
|
69
|
+
readonly stepUp?: FixedStepUp;
|
|
70
|
+
/**
|
|
71
|
+
* For your own bookkeeping (a version of the stored row, say);
|
|
72
|
+
* `janus-social` does not read it, since a record is read again on every
|
|
73
|
+
* resolve. A non-empty string or a non-negative integer when given.
|
|
74
|
+
*/
|
|
75
|
+
readonly revision?: string | number;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Where the connections live: the application's own table, read-only here.
|
|
79
|
+
* `null` is "no such connection"; a throw is a failure (the store is down) and
|
|
80
|
+
* is never read as an absence.
|
|
81
|
+
*/
|
|
82
|
+
export interface ConnectionSource {
|
|
83
|
+
findConnection(id: string): Promise<OidcConnection | null>;
|
|
84
|
+
/** The one connection that owns this e-mail domain, or `null`. */
|
|
85
|
+
findConnectionByDomain(domain: string): Promise<OidcConnection | null>;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=types.d.ts.map
|