@softistx/janus-oidc 0.0.0-stage → 0.4.5

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.
Files changed (40) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +175 -2
  3. package/dist/claims/scopes.d.ts +15 -0
  4. package/dist/claims/scopes.d.ts.map +1 -0
  5. package/dist/claims/types.d.ts +36 -0
  6. package/dist/claims/types.d.ts.map +1 -0
  7. package/dist/create.d.ts +19 -0
  8. package/dist/create.d.ts.map +1 -0
  9. package/dist/http/discovery.d.ts +13 -0
  10. package/dist/http/discovery.d.ts.map +1 -0
  11. package/dist/http/handlers.d.ts +16 -0
  12. package/dist/http/handlers.d.ts.map +1 -0
  13. package/dist/http/respond.d.ts +8 -0
  14. package/dist/http/respond.d.ts.map +1 -0
  15. package/dist/http/source.d.ts +13 -0
  16. package/dist/http/source.d.ts.map +1 -0
  17. package/dist/http/urls.d.ts +7 -0
  18. package/dist/http/urls.d.ts.map +1 -0
  19. package/dist/http/userinfo.d.ts +15 -0
  20. package/dist/http/userinfo.d.ts.map +1 -0
  21. package/dist/id-token/at-hash.d.ts +4 -0
  22. package/dist/id-token/at-hash.d.ts.map +1 -0
  23. package/dist/id-token/hook.d.ts +15 -0
  24. package/dist/id-token/hook.d.ts.map +1 -0
  25. package/dist/id-token/sign.d.ts +16 -0
  26. package/dist/id-token/sign.d.ts.map +1 -0
  27. package/dist/index.d.ts +15 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +423 -0
  30. package/dist/index.js.map +20 -0
  31. package/dist/types.d.ts +99 -0
  32. package/dist/types.d.ts.map +1 -0
  33. package/docs/README.md +18 -0
  34. package/docs/guide/claims.md +92 -0
  35. package/docs/guide/discovery.md +51 -0
  36. package/docs/guide/getting-started.md +79 -0
  37. package/docs/guide/issuers.md +54 -0
  38. package/docs/roadmap.md +32 -0
  39. package/docs/troubleshooting.md +112 -0
  40. package/package.json +67 -5
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Steve Tsala
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,176 @@
1
- # Temporary Holding Version
1
+ # @softistx/janus-oidc
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ An OpenID Connect provider on top of
4
+ [`@softistx/janus-oauth`](https://github.com/softistx/nxgt-janus/tree/develop/packages/janus-oauth):
5
+ the **ID Token** your authorization server adds to the token endpoint's answer, the
6
+ **userinfo** endpoint and the **discovery** document, for one issuer or for
7
+ several. Your OAuth server stays the one that signs in users, asks consent and
8
+ issues tokens; this package only adds what OpenID Connect asks on top.
9
+
10
+ The ID Token is signed with the same signing keys as the JWT access tokens, so
11
+ the JWKS `janus-oauth` already serves verifies both. Specs validate the token
12
+ with [`oauth4webapi`](https://github.com/panva/oauth4webapi) over a full
13
+ authorization-code flow with PKCE and a nonce.
14
+
15
+ ## Install
16
+
17
+ Public on npmjs:
18
+
19
+ ```sh
20
+ bun add @softistx/janus-oidc @softistx/janus-oauth @softistx/janus
21
+ bun add -d typescript # 6 or 7
22
+ ```
23
+
24
+ Both peers are required: `@softistx/janus-oauth`, whose server, endpoints and
25
+ signing keys it extends, and `@softistx/janus` (durations). `jose` is a
26
+ dependency, not a peer: no type of it crosses the surface.
27
+
28
+ ## Usage
29
+
30
+ The hook has to exist when the OAuth server is built, so the provider is made
31
+ first and attached afterwards:
32
+
33
+ ```ts
34
+ import { createOAuthEndpoints, createOAuthServer } from '@softistx/janus-oauth';
35
+ import { createOidcProvider } from '@softistx/janus-oidc';
36
+
37
+ const issuer = 'https://id.example.com';
38
+ const resource = 'https://id.example.com/userinfo';
39
+
40
+ const oidc = createOidcProvider({
41
+ // every claim you know; the scopes decide which are released
42
+ claims: async ({ id }) => {
43
+ const user = await directory.find(id);
44
+ return { name: user.name, email: user.email, email_verified: user.verified };
45
+ },
46
+ });
47
+
48
+ const oauth = createOAuthServer({
49
+ auth, // your janus() instance
50
+ store,
51
+ issuer,
52
+ resources: { [resource]: { scopes: ['openid', 'profile', 'email'] } },
53
+ defaultResource: resource,
54
+ accessTokens: { format: 'jwt', keys }, // the signing keys, rotated with rotateSigningKeys
55
+ tokenResponse: oidc.tokenResponse({ issuer, keys }), // adds id_token
56
+ });
57
+
58
+ const endpoints = createOAuthEndpoints(oauth, { consentUrl: '/consent' });
59
+ const openid = oidc.endpoints(oauth, endpoints, { resource });
60
+
61
+ for (const { method, path, handler } of [...endpoints.routes, ...openid.routes]) {
62
+ app.on(method, path, (c) => handler(c.req.raw));
63
+ }
64
+ ```
65
+
66
+ A client that asks for the `openid` scope now gets an `id_token` beside its
67
+ access token, reads `/userinfo` with that access token, and discovers
68
+ everything at `/.well-known/openid-configuration`.
69
+
70
+ ## API
71
+
72
+ | Export | What it is |
73
+ | --- | --- |
74
+ | `createOidcProvider(options)` | Makes the provider. Synchronous, no I/O; wrong options are a `TypeError`. |
75
+ | `provider.tokenResponse({ issuer, keys })` | The `tokenResponse` hook for `createOAuthServer`: adds `id_token` when the granted scopes include `openid`, **except on the token-exchange grant** (RFC 8693, `@softistx/janus-oauth`'s `tokenExchange`), which gets none even with `openid`: the exchanging client never saw the user authenticate (to confirm, the exchange answer's `scope` can include `openid` and the answer still has no `id_token`). One per issuer. |
76
+ | `provider.endpoints(oauth, endpoints, { resource })` | `{ discovery, userinfo, urls, routes }` for one server. |
77
+ | `provider.issuers(issuers, { resource })` | `{ handle(request) }` for `createOAuthIssuers`: the response of the discovery or userinfo route, or `null` for any other request. |
78
+
79
+ Options of `createOidcProvider`:
80
+
81
+ | Option | Default | |
82
+ | --- | --- | --- |
83
+ | `claims(user, scopes, { issuer })` | required | `user` is `{ id }`; `issuer` is the issuer the request went through (with `issuers()`, the one `resolve` answered), to look the user up in that issuer's partition. A callback may take fewer arguments. Sync or async; returns the standard claims (typed) and any claim of your own. |
84
+ | `scopeClaims` | none | Claims your own scopes release: `{ roles: ['roles'] }`. |
85
+ | `acrValuesSupported` | none | The ACR values your application can reach, published as `acr_values_supported` in discovery. |
86
+ | `idToken.lifetime` | the access token's | A duration: `'10m'`. |
87
+ | `idToken.includeClaims` | `false` | Put the released claims in the ID Token too (Core §5.4); by default they are at userinfo. |
88
+ | `paths.userinfo` | `<issuer>/userinfo` | A path from the origin or an absolute URL. |
89
+
90
+ Types: `OidcClaims`, `OidcStandardClaims`, `OidcAddress`, `OidcSubject`, `OidcClaimsContext`,
91
+ `OidcProviderOptions`, `OidcProvider`, `OidcEndpoints`, `OidcIssuers`,
92
+ `OidcTokenSource`, `OidcEndpointOptions`, `OidcIssuersOptions`.
93
+
94
+ ## What is in the ID Token
95
+
96
+ `iss`, `sub` (the user id), `aud` (the `client_id`), `exp`, `iat`; `auth_time`
97
+ (from the authentication you pass to `approve`), `nonce` (when the request had
98
+ one), `at_hash` (left half of the access token's hash: SHA-256 for ES256,
99
+ SHA-512 for EdDSA), and `amr` / `acr` when `approve` was given them. The header
100
+ carries the key's `alg` and `kid`. A refresh answers a new ID Token with the
101
+ original `auth_time` and no `nonce`.
102
+
103
+ ## Traps
104
+
105
+ - **The hook goes into `createOAuthServer`, the handlers come after it.**
106
+ `createOidcProvider` cannot take the server, because the server needs its
107
+ hook; `provider.endpoints(oauth, …)` attaches afterwards.
108
+ - **`issuer` and `keys` of the hook are the server's own.** Another issuer
109
+ signs an `iss` the discovery document does not state. `endpoints()` refuses a
110
+ server whose issuer has no hook made here; with several issuers, make the hook
111
+ inside `build`, per issuer.
112
+ - **The hook checks the issuer at issuing time.** The server hands the hook its
113
+ own `issuer`; when it differs from the one given to `tokenResponse({ issuer })`
114
+ the exchange rejects with a `TypeError` (a wiring mistake: the `id_token`
115
+ would carry the wrong `iss`) and no token is stored.
116
+ - **`tokenResponse({ keys })` and `accessTokens.keys` are the same store.** The ID Token is signed with the first and verified with the JWKS of the second; two stores give a token no published key verifies.
117
+ - **JWT access tokens are required**: the ID Token is verified with the JWKS
118
+ `janus-oauth` serves only when `accessTokens: { format: 'jwt', keys }` is on.
119
+ - **The `openid` scope must be offered by a resource**, and so must `profile`,
120
+ `email`, … when you want them: `authorize` refuses a scope no resource offers.
121
+ - **`claims` may return everything; the scopes release.** A claim no granted
122
+ scope names is dropped, and `sub`, `iss`, `aud`, `exp`, `iat`, `nonce`,
123
+ `at_hash`, `auth_time`, `amr`, `acr` can never be set from it.
124
+ - **`acr_values`, `max_age`, `prompt` and `login_hint` are kept, not enforced.** `janus-oauth` stores them on the pending request and shows them on `AuthorizationView` (`acrValues`, `maxAge`, `prompt`, `loginHint`). The package neither forces a
125
+ re-authentication nor answers `login_required` / `consent_required`: the
126
+ consent screen you write must handle them (ask again when the session is
127
+ older than `max_age`) and pass the result to `approve`. `auth_time` is in the
128
+ ID Token only when `approve` receives it (the `Authenticated` from `consent()`
129
+ carries it, or pass `authTime`).
130
+ - **Discovery before the first key** announces `ES256` in
131
+ `id_token_signing_alg_values_supported`, the algorithm `rotateSigningKeys`
132
+ generates by default; once keys are published it lists theirs.
133
+ - **Userinfo accepts tokens of one resource.** Make the userinfo URL a resource
134
+ of the server (or the API's own) and pass it as `resource`: a token for another
135
+ resource is a 401.
136
+ - **Userinfo accepts DPoP-bound tokens** (RFC 9449) when the OAuth server has
137
+ the `dpop` option: `Authorization: DPoP <token>` with the request's `DPoP`
138
+ proof, whose `htu` is the URL the request carries (behind a proxy, rebuild
139
+ the `Request` with the public URL). A bound token sent as `Bearer` is a 401.
140
+ The refusal answers `WWW-Authenticate: DPoP realm="userinfo",
141
+ error="invalid_dpop_proof", error_description="…", algs="ES256 EdDSA"`
142
+ (the failed check in a few words, also in the JSON body), and `DPoP-Nonce` for
143
+ `use_dpop_nonce` ([DPoP guide](https://github.com/softistx/nxgt-janus/blob/develop/packages/janus-oauth/docs/guide/dpop.md)).
144
+ - **No `current` signing key is a 503.** The ID Token hook throws
145
+ `NoSigningKeyError` (from `@softistx/janus-oauth`, code
146
+ `temporarily_unavailable`), which the token endpoint answers `503`.
147
+ - **A failure rejects.** A `claims` or store failure is thrown for your
148
+ framework's error handling (answer 503), never turned into a 401.
149
+
150
+ ## Documentation
151
+
152
+ - [Getting started](docs/guide/getting-started.md) — the wiring, step by step
153
+ - [Claims and scopes](docs/guide/claims.md) — what each scope releases
154
+ - [Discovery](docs/guide/discovery.md) — the document and what `oauth4webapi` reads from it
155
+ - [Several issuers](docs/guide/issuers.md) — one provider, an isolated issuer per tenant
156
+ - [Troubleshooting](docs/troubleshooting.md) — every error message and its fix
157
+ - [Roadmap](docs/roadmap.md) — what is next, and what is not planned
158
+
159
+ ## Type safety, counted
160
+
161
+ **Twenty-two plausible mistakes, twenty-two refused at compile time.**
162
+ `test/types/refusals.ts` holds one `@ts-expect-error` per mistake, beside the
163
+ wiring that must keep compiling (claims sync or async with custom claims, the
164
+ hook in `createOAuthServer`, `endpoints()` and `issuers()`): no `claims`,
165
+ `claims` as an object, a standard claim of the wrong type (`email_verified`,
166
+ `updated_at`, `address`), a `sub` in the claims, a `claims` that expects a user
167
+ record, `scopeClaims` as a string, a non-boolean `includeClaims`, a bad
168
+ `lifetime`, a numeric `paths.userinfo`, the hook without its issuer or keys or
169
+ with a JWKS for keys, `endpoints()` without a resource or with the endpoints'
170
+ options, `issuers()` with a single server, without `endpoints` or a resource,
171
+ or with a per-issuer resource that is not a function of the issuer string,
172
+ reassigning the URLs, and treating `handle` as always answering.
173
+
174
+ ## Licence
175
+
176
+ MIT
@@ -0,0 +1,15 @@
1
+ /** Which claims a scope releases (OpenID Connect Core §5.4), and the filter that applies it. */
2
+ export declare const STANDARD_SCOPE_CLAIMS: Readonly<Record<string, readonly string[]>>;
3
+ /** Claims the provider writes itself: a `claims` function can never set them. */
4
+ export declare const RESERVED_CLAIMS: readonly string[];
5
+ /** The standard table with the application's own scopes added (theirs win for a scope both name). */
6
+ export declare function mergedScopeClaims(own: Readonly<Record<string, readonly string[]>> | undefined): Readonly<Record<string, readonly string[]>>;
7
+ /** Every claim name any scope releases, sorted. */
8
+ export declare function releasableClaims(table: Readonly<Record<string, readonly string[]>>): string[];
9
+ /**
10
+ * The claims the granted scopes release: a claim no scope names, a reserved
11
+ * one and an `undefined` are dropped, so `claims` can return everything it
12
+ * knows.
13
+ */
14
+ export declare function releasedClaims(claims: Readonly<Record<string, unknown>>, scopes: readonly string[], table: Readonly<Record<string, readonly string[]>>): Record<string, unknown>;
15
+ //# sourceMappingURL=scopes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scopes.d.ts","sourceRoot":"","sources":["../../src/claims/scopes.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAEhG,eAAO,MAAM,qBAAqB,EAAE,QAAQ,CAC3C,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAqBjC,CAAC;AAEF,iFAAiF;AACjF,eAAO,MAAM,eAAe,EAAE,SAAS,MAAM,EAe5C,CAAC;AAEF,qGAAqG;AACrG,wBAAgB,iBAAiB,CAChC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,GAAG,SAAS,GAC1D,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,CAE7C;AAED,mDAAmD;AACnD,wBAAgB,gBAAgB,CAC/B,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,GAChD,MAAM,EAAE,CAIV;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC7B,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACzC,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,GAChD,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAazB"}
@@ -0,0 +1,36 @@
1
+ /** The wire types of the standard claims: `snake_case`, as OpenID Connect Core spells them. */
2
+ /** The postal address claim (OpenID Connect Core §5.1.1). */
3
+ export interface OidcAddress {
4
+ readonly formatted?: string;
5
+ readonly street_address?: string;
6
+ readonly locality?: string;
7
+ readonly region?: string;
8
+ readonly postal_code?: string;
9
+ readonly country?: string;
10
+ }
11
+ /** The standard claims of OpenID Connect Core §5.1, as the specification spells them. */
12
+ export interface OidcStandardClaims {
13
+ /** `sub` is the user's id; the provider writes it, so it cannot be given. */
14
+ readonly sub?: never;
15
+ readonly name?: string;
16
+ readonly given_name?: string;
17
+ readonly family_name?: string;
18
+ readonly middle_name?: string;
19
+ readonly nickname?: string;
20
+ readonly preferred_username?: string;
21
+ readonly profile?: string;
22
+ readonly picture?: string;
23
+ readonly website?: string;
24
+ readonly email?: string;
25
+ readonly email_verified?: boolean;
26
+ readonly gender?: string;
27
+ readonly birthdate?: string;
28
+ readonly zoneinfo?: string;
29
+ readonly locale?: string;
30
+ readonly phone_number?: string;
31
+ readonly phone_number_verified?: boolean;
32
+ readonly address?: OidcAddress;
33
+ /** Seconds since the epoch. */
34
+ readonly updated_at?: number;
35
+ }
36
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/claims/types.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAE/F,6DAA6D;AAC7D,MAAM,WAAW,WAAW;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,yFAAyF;AACzF,MAAM,WAAW,kBAAkB;IAClC,6EAA6E;IAC7E,QAAQ,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC;IACrB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IACrC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC;IAClC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,qBAAqB,CAAC,EAAE,OAAO,CAAC;IACzC,QAAQ,CAAC,OAAO,CAAC,EAAE,WAAW,CAAC;IAC/B,+BAA+B;IAC/B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC7B"}
@@ -0,0 +1,19 @@
1
+ import type { OidcProvider, OidcProviderOptions } from './types';
2
+ /**
3
+ * An OpenID Connect provider on top of `@softistx/janus-oauth`: the
4
+ * `tokenResponse` hook that adds `id_token`, and the userinfo and discovery
5
+ * handlers. It holds no state of its own beyond the issuers it made a hook
6
+ * for. Wrong options are a `TypeError`, at wiring time.
7
+ *
8
+ * ```ts
9
+ * const oidc = createOidcProvider({ claims: async ({ id }) => profileOf(id) });
10
+ * const oauth = createOAuthServer({
11
+ * …,
12
+ * accessTokens: { format: 'jwt', keys },
13
+ * tokenResponse: oidc.tokenResponse({ issuer, keys }),
14
+ * });
15
+ * const { routes } = oidc.endpoints(oauth, endpoints, { resource });
16
+ * ```
17
+ */
18
+ export declare function createOidcProvider(options: OidcProviderOptions): OidcProvider;
19
+ //# sourceMappingURL=create.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAGX,YAAY,EACZ,mBAAmB,EACnB,MAAM,SAAS,CAAC;AAqFjB;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,YAAY,CAiC7E"}
@@ -0,0 +1,13 @@
1
+ /** The discovery document (OpenID Connect Discovery §3): the OAuth metadata plus what OpenID Connect adds. */
2
+ import { type OAuthServer } from '@softistx/janus-oauth';
3
+ export interface DiscoveryContext {
4
+ readonly scopeClaims: Readonly<Record<string, readonly string[]>>;
5
+ readonly acrValuesSupported: readonly string[];
6
+ }
7
+ /**
8
+ * `metadata` is the OAuth document of the same issuer, merged under the
9
+ * OpenID Connect members. Throws when the server cannot do OpenID Connect:
10
+ * no JWKS (access tokens are opaque) or no `openid` scope on any resource.
11
+ */
12
+ export declare function discoveryDocument(ctx: DiscoveryContext, oauth: OAuthServer, metadata: Readonly<Record<string, unknown>>, userinfoEndpoint: string): Promise<Response>;
13
+ //# sourceMappingURL=discovery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../../src/http/discovery.ts"],"names":[],"mappings":"AAAA,8GAA8G;AAE9G,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAI9E,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,CAAC;IAClE,QAAQ,CAAC,kBAAkB,EAAE,SAAS,MAAM,EAAE,CAAC;CAC/C;AAeD;;;;GAIG;AACH,wBAAsB,iBAAiB,CACtC,GAAG,EAAE,gBAAgB,EACrB,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAC3C,gBAAgB,EAAE,MAAM,GACtB,OAAO,CAAC,QAAQ,CAAC,CAmCnB"}
@@ -0,0 +1,16 @@
1
+ /** The two handlers over a `ServerSource`; each is one function. */
2
+ import type { OAuthHandler } from '@softistx/janus-oauth';
3
+ import type { OidcClaims, OidcClaimsContext, OidcSubject } from '../types';
4
+ import type { ServerSource } from './source';
5
+ export interface HandlerContext {
6
+ readonly scopeClaims: Readonly<Record<string, readonly string[]>>;
7
+ readonly claims: (user: OidcSubject, scopes: readonly string[], context: OidcClaimsContext) => OidcClaims | Promise<OidcClaims>;
8
+ readonly userinfoPath: string | undefined;
9
+ /** The `acr_values_supported` discovery publishes; empty publishes none. */
10
+ readonly acrValuesSupported: readonly string[];
11
+ /** The issuers a `tokenResponse` hook was made for: a server of another one signs no ID Token. */
12
+ readonly hooked: ReadonlySet<string>;
13
+ }
14
+ export declare function discoveryHandler(ctx: HandlerContext, source: ServerSource): OAuthHandler;
15
+ export declare function userinfoHandler(ctx: HandlerContext, source: ServerSource): OAuthHandler;
16
+ //# sourceMappingURL=handlers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../src/http/handlers.ts"],"names":[],"mappings":"AAAA,oEAAoE;AAEpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAG3E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAI7C,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,CAAC;IAClE,QAAQ,CAAC,MAAM,EAAE,CAChB,IAAI,EAAE,WAAW,EACjB,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,OAAO,EAAE,iBAAiB,KACtB,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IACtC,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C,4EAA4E;IAC5E,QAAQ,CAAC,kBAAkB,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/C,kGAAkG;IAClG,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CACrC;AAgBD,wBAAgB,gBAAgB,CAC/B,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE,YAAY,GAClB,YAAY,CAiBd;AAED,wBAAgB,eAAe,CAC9B,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE,YAAY,GAClB,YAAY,CAMd"}
@@ -0,0 +1,8 @@
1
+ /** The JSON answers of the discovery and userinfo endpoints. */
2
+ /** A userinfo answer: it names a user, so it is never cached. */
3
+ export declare function privateJson(body: unknown, status?: number, headers?: Readonly<Record<string, string>>): Response;
4
+ /** The discovery document: public, cacheable, readable from any origin. */
5
+ export declare function publicJson(body: unknown): Response;
6
+ export declare const notFound: () => Response;
7
+ export declare const methodNotAllowed: (allow: string) => Response;
8
+ //# sourceMappingURL=respond.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"respond.d.ts","sourceRoot":"","sources":["../../src/http/respond.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAIhE,iEAAiE;AACjE,wBAAgB,WAAW,CAC1B,IAAI,EAAE,OAAO,EACb,MAAM,SAAM,EACZ,OAAO,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM,GAC5C,QAAQ,CAKV;AAED,2EAA2E;AAC3E,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,GAAG,QAAQ,CASlD;AAED,eAAO,MAAM,QAAQ,QAAO,QACa,CAAC;AAE1C,eAAO,MAAM,gBAAgB,UAAW,MAAM,KAAG,QAQ/C,CAAC"}
@@ -0,0 +1,13 @@
1
+ /** Where a request's server and its OAuth metadata come from: one server, or several issuers. */
2
+ import type { OAuthEndpoints, OAuthIssuers, OAuthServer } from '@softistx/janus-oauth';
3
+ export interface ServerSource {
4
+ /** The request's server, or `null` for a request no issuer claims. */
5
+ serverFor(request: Request): Promise<OAuthServer | null>;
6
+ /** The server's RFC 8414 document. */
7
+ metadata(request: Request, oauth: OAuthServer): Promise<Record<string, unknown>>;
8
+ /** The resource userinfo accepts tokens for. */
9
+ resource(oauth: OAuthServer): string;
10
+ }
11
+ export declare function singleSource(oauth: OAuthServer, endpoints: OAuthEndpoints, resource: string): ServerSource;
12
+ export declare function issuersSource(issuers: OAuthIssuers, resource: string | ((issuer: string) => string)): ServerSource;
13
+ //# sourceMappingURL=source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../src/http/source.ts"],"names":[],"mappings":"AAAA,iGAAiG;AAEjG,OAAO,KAAK,EACX,cAAc,EACd,YAAY,EACZ,WAAW,EACX,MAAM,uBAAuB,CAAC;AAE/B,MAAM,WAAW,YAAY;IAC5B,sEAAsE;IACtE,SAAS,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IACzD,sCAAsC;IACtC,QAAQ,CACP,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,WAAW,GAChB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACpC,gDAAgD;IAChD,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAAC;CACrC;AAWD,wBAAgB,YAAY,CAC3B,KAAK,EAAE,WAAW,EAClB,SAAS,EAAE,cAAc,EACzB,QAAQ,EAAE,MAAM,GACd,YAAY,CAOd;AAED,wBAAgB,aAAa,CAC5B,OAAO,EAAE,YAAY,EACrB,QAAQ,EAAE,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC,GAC7C,YAAY,CAiBd"}
@@ -0,0 +1,7 @@
1
+ /** Where the OpenID Connect endpoints live, derived from the issuer like the OAuth ones. */
2
+ /** `/.well-known/openid-configuration` with the issuer's path appended (Discovery §4.1). */
3
+ export declare function discoveryPath(issuer: string): string;
4
+ export declare function discoveryUrl(issuer: string): string;
5
+ /** Userinfo: a path from the origin, an absolute URL, or `<issuer>/userinfo`. */
6
+ export declare function userinfoUrl(issuer: string, configured?: string): URL;
7
+ //# sourceMappingURL=urls.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"urls.d.ts","sourceRoot":"","sources":["../../src/http/urls.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAQ5F,4FAA4F;AAC5F,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,iFAAiF;AACjF,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,GAAG,CA6BpE"}
@@ -0,0 +1,15 @@
1
+ /** The userinfo endpoint (OpenID Connect Core §5.3): a bearer or DPoP token in, the released claims out. */
2
+ import type { OAuthServer } from '@softistx/janus-oauth';
3
+ import type { OidcClaims, OidcClaimsContext, OidcSubject } from '../types';
4
+ export interface UserinfoContext {
5
+ readonly scopeClaims: Readonly<Record<string, readonly string[]>>;
6
+ readonly claims: (user: OidcSubject, scopes: readonly string[], context: OidcClaimsContext) => OidcClaims | Promise<OidcClaims>;
7
+ }
8
+ /**
9
+ * `sub` and the claims the token's scopes release. A token for another
10
+ * resource, a lapsed or revoked one, or a deactivated user is a 401; a token
11
+ * without `openid` is a 403 `insufficient_scope`. A store or `claims` failure
12
+ * rejects: answer 503, never 401.
13
+ */
14
+ export declare function userinfo(ctx: UserinfoContext, oauth: OAuthServer, resource: string, request: Request): Promise<Response>;
15
+ //# sourceMappingURL=userinfo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"userinfo.d.ts","sourceRoot":"","sources":["../../src/http/userinfo.ts"],"names":[],"mappings":"AAAA,4GAA4G;AAE5G,OAAO,KAAK,EAAgB,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEvE,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAG3E,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,CAAC;IAClE,QAAQ,CAAC,MAAM,EAAE,CAChB,IAAI,EAAE,WAAW,EACjB,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,OAAO,EAAE,iBAAiB,KACtB,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACtC;AA6CD;;;;;GAKG;AACH,wBAAsB,QAAQ,CAC7B,GAAG,EAAE,eAAe,EACpB,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,QAAQ,CAAC,CA0BnB"}
@@ -0,0 +1,4 @@
1
+ /** `at_hash` (OpenID Connect Core §3.1.3.6): the left half of the access token's hash, base64url. */
2
+ import type { SigningAlg } from '@softistx/janus-oauth';
3
+ export declare function atHash(alg: SigningAlg, accessToken: string): Promise<string>;
4
+ //# sourceMappingURL=at-hash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"at-hash.d.ts","sourceRoot":"","sources":["../../src/id-token/at-hash.ts"],"names":[],"mappings":"AAAA,qGAAqG;AAErG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAOxD,wBAAsB,MAAM,CAC3B,GAAG,EAAE,UAAU,EACf,WAAW,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,CAAC,CAQjB"}
@@ -0,0 +1,15 @@
1
+ /** The `tokenResponse` hook: one function, `id_token` for a grant that includes `openid`, except the token-exchange grant, which gets none even with `openid`. */
2
+ import { type OAuthTokenResponseHook, type SigningKeyStore } from '@softistx/janus-oauth';
3
+ import type { OidcClaims, OidcClaimsContext, OidcSubject } from '../types';
4
+ /** Data only: what the hook reads, validated once at wiring. */
5
+ export interface IdTokenContext {
6
+ readonly issuer: string;
7
+ readonly keys: SigningKeyStore;
8
+ /** `null`: the access token's `expires_in`. */
9
+ readonly lifetimeMs: number | null;
10
+ readonly includeClaims: boolean;
11
+ readonly scopeClaims: Readonly<Record<string, readonly string[]>>;
12
+ readonly claims: (user: OidcSubject, scopes: readonly string[], context: OidcClaimsContext) => OidcClaims | Promise<OidcClaims>;
13
+ }
14
+ export declare function idTokenHook(ctx: IdTokenContext): OAuthTokenResponseHook;
15
+ //# sourceMappingURL=hook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hook.d.ts","sourceRoot":"","sources":["../../src/id-token/hook.ts"],"names":[],"mappings":"AAAA,kKAAkK;AAElK,OAAO,EAEN,KAAK,sBAAsB,EAC3B,KAAK,eAAe,EAEpB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAI3E,gEAAgE;AAChE,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAC/B,+CAA+C;IAC/C,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;IAChC,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,CAAC;IAClE,QAAQ,CAAC,MAAM,EAAE,CAChB,IAAI,EAAE,WAAW,EACjB,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,OAAO,EAAE,iBAAiB,KACtB,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACtC;AAkBD,wBAAgB,WAAW,CAAC,GAAG,EAAE,cAAc,GAAG,sBAAsB,CAoCvE"}
@@ -0,0 +1,16 @@
1
+ /** Signing an ID Token with the server's current signing key. */
2
+ import { type SigningKeyRecord, type SigningKeyStore } from '@softistx/janus-oauth';
3
+ /** The `current` key at `now`. A `NoSigningKeyError` (an `OAuthError` `temporarily_unavailable`, answered 503) when there is none: a failure to fix, never a client's mistake. */
4
+ export declare function currentKey(keys: SigningKeyStore, now: Date): Promise<SigningKeyRecord>;
5
+ export interface IdTokenClaims {
6
+ readonly iss: string;
7
+ readonly sub: string;
8
+ readonly aud: string;
9
+ readonly iat: Date;
10
+ readonly exp: Date;
11
+ /** The rest: `auth_time`, `nonce`, `at_hash`, `amr`, `acr`, scope claims. */
12
+ readonly extra: Readonly<Record<string, unknown>>;
13
+ }
14
+ /** The compact JWT, with the key's `alg` and `kid` in the header. Only the private JWK is read. */
15
+ export declare function signIdToken(key: SigningKeyRecord, claims: IdTokenClaims): Promise<string>;
16
+ //# sourceMappingURL=sign.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sign.d.ts","sourceRoot":"","sources":["../../src/id-token/sign.ts"],"names":[],"mappings":"AAAA,iEAAiE;AAEjE,OAAO,EAEN,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,MAAM,uBAAuB,CAAC;AAG/B,kLAAkL;AAClL,wBAAsB,UAAU,CAC/B,IAAI,EAAE,eAAe,EACrB,GAAG,EAAE,IAAI,GACP,OAAO,CAAC,gBAAgB,CAAC,CAQ3B;AAED,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC;IACnB,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC;IACnB,6EAA6E;IAC7E,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAClD;AAED,mGAAmG;AACnG,wBAAsB,WAAW,CAChC,GAAG,EAAE,gBAAgB,EACrB,MAAM,EAAE,aAAa,GACnB,OAAO,CAAC,MAAM,CAAC,CAUjB"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * `@softistx/janus-oidc` — an OpenID Connect provider on top of
3
+ * `@softistx/janus-oauth`.
4
+ *
5
+ * - `createOidcProvider()` — `tokenResponse()`, the hook that adds a signed
6
+ * `id_token` to the token endpoint's answer; `endpoints()`, the userinfo
7
+ * and discovery handlers of one server; `issuers()`, the same for
8
+ * `createOAuthIssuers`.
9
+ *
10
+ * Guides: `docs/guide/getting-started.md`.
11
+ */
12
+ export type { OidcAddress, OidcStandardClaims } from './claims/types';
13
+ export { createOidcProvider } from './create';
14
+ export type { OidcClaims, OidcClaimsContext, OidcEndpointOptions, OidcEndpoints, OidcIssuers, OidcIssuersOptions, OidcProvider, OidcProviderOptions, OidcSubject, OidcTokenSource, } from './types';
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC9C,YAAY,EACX,UAAU,EACV,iBAAiB,EACjB,mBAAmB,EACnB,aAAa,EACb,WAAW,EACX,kBAAkB,EAClB,YAAY,EACZ,mBAAmB,EACnB,WAAW,EACX,eAAe,GACf,MAAM,SAAS,CAAC"}