@zelavis/app-auth-oidc 2.0.0-alpha.3

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ivan Jeremic
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 ADDED
@@ -0,0 +1,36 @@
1
+ # @zelavis/app-auth-oidc
2
+
3
+ An ordinary Zelavis auth plugin for validating OIDC access tokens through the
4
+ native `Request` authentication contract. It verifies issuer, audience,
5
+ algorithm allow-lists, signatures, and remote JWKS keys before mapping claims
6
+ to a Zelavis principal.
7
+
8
+ The optional `authorizationCode` configuration enables endpoint-backed login
9
+ and explicit account linking. Zelavis creates short-lived one-time flow state,
10
+ binds callbacks to state and nonce, uses S256 PKCE, verifies the returned ID
11
+ token against issuer/audience/algorithm/JWKS constraints, and never links an
12
+ existing account merely because an email address matches.
13
+
14
+ ```ts
15
+ import { oidcBearerService } from "@zelavis/app-auth-oidc";
16
+
17
+ export const service = oidcBearerService({
18
+ issuer: "https://identity.example.com",
19
+ audience: "zelavis-project",
20
+ jwksUrl: "https://identity.example.com/.well-known/jwks.json",
21
+ authorizationCode: {
22
+ clientId: "zelavis-project",
23
+ authorizationEndpoint: "https://identity.example.com/oauth2/authorize",
24
+ tokenEndpoint: "https://identity.example.com/oauth2/token",
25
+ redirectUri: "https://app.example.com/zelavis/api/v1/auth/oauth/oidc/callback",
26
+ },
27
+ });
28
+ ```
29
+
30
+ The plugin requires explicit issuer, audience, JWKS URL, and an algorithm
31
+ allow-list (or its conservative asymmetric default). It never accepts an
32
+ unsigned token or derives trust from unverified token claims.
33
+
34
+ Login starts at `POST /auth/oauth/oidc/start`. Authenticated accounts can start
35
+ an explicit link at `POST /auth/oauth/oidc/link/start`; both complete through
36
+ `GET /auth/oauth/oidc/callback`.
@@ -0,0 +1,32 @@
1
+ import { type ZelavisPrincipal } from "zelavis/core";
2
+ /**
3
+ * Accepts JWT bearer tokens issued by an external OpenID Connect provider.
4
+ *
5
+ * This is machine-to-machine access: a caller already holding a token from the
6
+ * issuer presents it, and the token is verified against the issuer's key set.
7
+ * No sign-in happens here and no account is created.
8
+ *
9
+ * Browser sign-in is a different thing and lives in `@zelavis/auth`, which
10
+ * runs the Authorization Code flow through core auth and creates real
11
+ * accounts. This package used to carry a second implementation of that flow;
12
+ * two implementations of one exchange drift, and only one of them can be the
13
+ * one an operator has configured.
14
+ */
15
+ export interface OidcBearerPluginOptions {
16
+ providerName?: string;
17
+ issuer: string;
18
+ audience: string | readonly string[];
19
+ jwksUrl: string | URL;
20
+ algorithms?: readonly string[];
21
+ mapPrincipal?: (claims: Readonly<Record<string, unknown>>) => ZelavisPrincipal | undefined | Promise<ZelavisPrincipal | undefined>;
22
+ }
23
+ export declare function oidcBearerService(options: OidcBearerPluginOptions): Readonly<{
24
+ name: "@zelavis/auth-oidc";
25
+ kind: "plugin";
26
+ capabilities: readonly string[];
27
+ authenticators: import("zelavis/core").ZelavisRequestAuthenticator<unknown>[];
28
+ service: {
29
+ name: string;
30
+ register(): void;
31
+ };
32
+ }>;
package/dist/index.js ADDED
@@ -0,0 +1,30 @@
1
+ import { createJwksAuthenticator, } from "zelavis/core";
2
+ export function oidcBearerService(options) {
3
+ const issuer = options.issuer.replace(/\/$/u, "");
4
+ return Object.freeze({
5
+ name: "@zelavis/auth-oidc",
6
+ kind: "plugin",
7
+ capabilities: Object.freeze(["zelavis/identity:credentials"]),
8
+ authenticators: [
9
+ createJwksAuthenticator({
10
+ name: options.providerName ?? "oidc",
11
+ issuer,
12
+ audience: options.audience,
13
+ algorithms: options.algorithms ?? ["RS256", "ES256", "EdDSA"],
14
+ jwksUrl: options.jwksUrl,
15
+ async mapPrincipal(payload) {
16
+ if (options.mapPrincipal)
17
+ return options.mapPrincipal(payload);
18
+ if (typeof payload.sub !== "string" || !payload.sub)
19
+ return undefined;
20
+ return {
21
+ id: payload.sub,
22
+ type: "user",
23
+ metadata: { issuer: payload.iss, authentication: "oidc" },
24
+ };
25
+ },
26
+ }),
27
+ ],
28
+ service: { name: options.providerName ?? "oidc", register() { } },
29
+ });
30
+ }
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "@zelavis/app-auth-oidc",
3
+ "version": "2.0.0-alpha.3",
4
+ "private": false,
5
+ "description": "OIDC/JWKS bearer authentication plugin for Zelavis.",
6
+ "license": "MIT",
7
+ "author": "Ivan Jeremic",
8
+ "type": "module",
9
+ "types": "./dist/index.d.ts",
10
+ "zelavis": {
11
+ "kind": "plugin",
12
+ "capabilities": [
13
+ "zelavis/identity:credentials"
14
+ ],
15
+ "namespace": "oidc",
16
+ "marketplace": {
17
+ "title": "OpenID Connect Sign-in",
18
+ "summary": "Let people sign in with any OpenID Connect provider, or verify bearer tokens from one.",
19
+ "categories": [
20
+ "auth",
21
+ "identity",
22
+ "official"
23
+ ],
24
+ "tags": [
25
+ "oidc",
26
+ "jwks",
27
+ "sso"
28
+ ]
29
+ }
30
+ },
31
+ "exports": {
32
+ ".": {
33
+ "types": "./dist/index.d.ts",
34
+ "import": "./dist/index.js"
35
+ }
36
+ },
37
+ "files": [
38
+ "dist"
39
+ ],
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "https://github.com/zelavis/zelavis.git",
46
+ "directory": "zelavis-services/auth-oidc"
47
+ },
48
+ "homepage": "https://github.com/zelavis/zelavis/tree/main/zelavis-services/auth-oidc#readme",
49
+ "bugs": {
50
+ "url": "https://github.com/zelavis/zelavis/issues"
51
+ },
52
+ "peerDependencies": {
53
+ "zelavis": ">=2.0.0-alpha.4"
54
+ },
55
+ "dependencies": {
56
+ "jose": "^6.2.12"
57
+ },
58
+ "devDependencies": {
59
+ "typescript": "^7.0.2",
60
+ "zelavis": "2.0.0-alpha.4"
61
+ },
62
+ "keywords": [
63
+ "auth",
64
+ "oauth",
65
+ "oidc",
66
+ "jwt",
67
+ "jwks"
68
+ ],
69
+ "scripts": {
70
+ "build": "tsc -p tsconfig.json",
71
+ "typecheck": "tsc -p tsconfig.json --noEmit",
72
+ "test": "pnpm run typecheck"
73
+ }
74
+ }