@bernierllc/nevar-auth 0.3.1 → 0.4.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/README.md +5 -3
- package/dist/index.d.ts +5 -1
- package/dist/index.js +18 -1
- package/dist/testing/index.d.ts +8 -0
- package/dist/testing/index.js +11 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ Verifies nevar.io credentials (JWTs and typed `api_`/`mcp_` keys) and performs a
|
|
|
6
6
|
npm install @bernierllc/nevar-auth
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
**Contract:** `ifc:platform/authentication` (`#ActorContext`
|
|
9
|
+
**Contract:** `ifc:platform/authentication` (`#ActorContext@r3`, sha `dfb29f99150b`, since 0.4.0), with the package-conformance decisions Q6, Q10, Q11, Q12, Q15 and Q16 implemented. Production issuer `https://auth.nevar.io`, staging issuer `https://auth.notnevar.us`.
|
|
10
10
|
|
|
11
11
|
## Rules this package enforces
|
|
12
12
|
|
|
@@ -16,6 +16,7 @@ npm install @bernierllc/nevar-auth
|
|
|
16
16
|
- **Introspection uses the endpoint discovery names.** The verifier posts to discovery's `introspection_endpoint`, and falls back to `<issuer>/oauth/introspect` only when discovery omits it. An endpoint that is present but not an absolute URL fails discovery; it never falls back. Like the token endpoint, it must be on the issuer's own origin, over https outside `mode: 'test'`, because it carries the client secret.
|
|
17
17
|
- **Typed keys are opaque, and only work on configured audiences.** `api_` and `mcp_` keys are checked only through RFC 7662 introspection. The surface of an audience comes from `resourceAudiences`, a set of exact audience URLs per surface, never from the host name: an `api_` key works only on an audience in `resourceAudiences.api`, an `mcp_` key only on one in `resourceAudiences.mcp`, and any other audience refuses both with `wrong_surface`. Omitting `resourceAudiences` is deprecated since 0.3.0 (removed in 1.0.0): the verifier falls back to the 0.2 first-DNS-label rule and prints a one-time warning.
|
|
18
18
|
- **JWTs are introspected too, after local verification.** A revoked grant is therefore denied on the very next call. `scope` and `nevar_grant_id` in the returned `ActorContext` come from the introspection response, not from the JWT; a response with no `scope` is refused. The response must also say `role: "authenticated"`: any other role (such as `service_role`), or none, is refused with `invalid_token`.
|
|
19
|
+
- **Execution-grant claims (since 0.4.0).** `nevar_project_id` and `nevar_callback_op` come back on the `ActorContext`, both `null` on every credential that is not an execution grant. A token that carries either claim (JSON `null` counts as carrying it) must carry a `nevar_callback_op` that is a string matching the OperationCatalog id pattern, and a `nevar_project_id` that is a non-empty string or JSON `null`; anything else is refused with `invalid_token` (JWTs, `api_` and `mcp_` keys alike). That includes an operation with no project claim, a project claim with a missing or `null` operation, a wrong type, and an operation that fails the pattern. The package only copies the two claims: the callee enforces the operation binding. For a JWT they come from the verified JWT, never from the introspection response (which supplies only `scope`, `nevar_grant_id` and `role`); for an `api_`/`mcp_` key they come from the introspection response.
|
|
19
20
|
- **Identity comes only from the verified credential.** `verifyCredential` takes no actor header. A service acting for a user obtains a delegated token through RFC 8693 token exchange (`delegateActor`), and that token carries an `act` claim.
|
|
20
21
|
- **Delegation only talks to the issuer and returns only a verified token.** `delegateActor` requires a `token_endpoint` in discovery on the issuer's own origin, over https (plain http only in `mode: 'test'`). It authenticates with HTTP Basic using `introspectionClient`, and the actor (service) token's `aud` must be the issuer. The returned token is verified for the requested audience, including introspection, before `delegateActor` returns it; if that check cannot complete, the call fails.
|
|
21
22
|
- **When the issuer cannot be reached, the call fails.** You get `dependency_unavailable` with `retryable: true`. The verifier never falls back to cached or local keys.
|
|
@@ -44,7 +45,8 @@ try {
|
|
|
44
45
|
correlationId: req.id,
|
|
45
46
|
});
|
|
46
47
|
// actor.sub, actor.nevar_actor_type, actor.nevar_owner_sub, actor.nevar_org_id,
|
|
47
|
-
// actor.scope, actor.nevar_grant_id, actor.act, actor.role ("authenticated"), actor.aud
|
|
48
|
+
// actor.scope, actor.nevar_grant_id, actor.act, actor.role ("authenticated"), actor.aud,
|
|
49
|
+
// actor.nevar_project_id, actor.nevar_callback_op (execution-grant claims, string | null; since 0.4.0)
|
|
48
50
|
} catch (error) {
|
|
49
51
|
if (error instanceof NevarAuthError && error.retryable) return res.status(503).end();
|
|
50
52
|
return res.status(401).end();
|
|
@@ -105,7 +107,7 @@ await issuer.close();
|
|
|
105
107
|
- `startTestIssuer({ introspectionPath, advertiseIntrospection })` moves the introspection route (default `/oauth/introspect`) or leaves `introspection_endpoint` out of discovery.
|
|
106
108
|
|
|
107
109
|
**Sample credentials:**
|
|
108
|
-
- `issuer.tokens`: `valid`, `expired`, `wrongAudience`, `wrongIssuer`, `revoked`, `agent
|
|
110
|
+
- `issuer.tokens`: `valid`, `expired`, `wrongAudience`, `wrongIssuer`, `revoked`, `agent`, `service` (whose `aud` is the issuer) and `executionGrant` (since 0.4.0: a service token carrying `TEST_EXECUTION_GRANT`, project `proj_test_1` and operation `projects.tasks.run_due`).
|
|
109
111
|
- `TEST_RESOURCE_AUDIENCES`: the `resourceAudiences` set matching `TEST_AUDIENCES`.
|
|
110
112
|
- `TEST_KEYS`: one `api_` key and one `mcp_` key.
|
|
111
113
|
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { NevarAuthError, type NevarAuthErrorCode } from './errors.js';
|
|
|
2
2
|
/** The two real issuers. Pass one as `issuer`. */
|
|
3
3
|
export declare const NEVAR_ISSUERS: {
|
|
4
4
|
readonly production: "https://auth.nevar.io";
|
|
5
|
-
readonly staging: "https://auth.
|
|
5
|
+
readonly staging: "https://auth.notnevar.us";
|
|
6
6
|
};
|
|
7
7
|
export declare const TEST_KID = "test-only-not-production";
|
|
8
8
|
declare const ACTOR_TYPES: readonly ["user", "agent", "service"];
|
|
@@ -28,6 +28,10 @@ export interface ActorContext {
|
|
|
28
28
|
role: 'authenticated';
|
|
29
29
|
/** The audience this credential was verified for. */
|
|
30
30
|
aud: string;
|
|
31
|
+
/** ActorContext rev 3: the project an execution-grant token is bound to; `null` on every other token and on a grant with no project. */
|
|
32
|
+
nevar_project_id: string | null;
|
|
33
|
+
/** ActorContext rev 3: the OperationCatalog id an execution-grant token is bound to; `null` on every other token. The callee enforces the binding. */
|
|
34
|
+
nevar_callback_op: string | null;
|
|
31
35
|
}
|
|
32
36
|
/** Anything with `warn(message, context)`, e.g. a `@bernierllc/logger` instance. */
|
|
33
37
|
export interface NevarAuthLogger {
|
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ export { NevarAuthError } from './errors.js';
|
|
|
11
11
|
/** The two real issuers. Pass one as `issuer`. */
|
|
12
12
|
export const NEVAR_ISSUERS = {
|
|
13
13
|
production: 'https://auth.nevar.io',
|
|
14
|
-
staging: 'https://auth.
|
|
14
|
+
staging: 'https://auth.notnevar.us',
|
|
15
15
|
};
|
|
16
16
|
/** `kid` of the fixture signing key in `@bernierllc/nevar-auth/testing`. Refused in production mode. */
|
|
17
17
|
/** Q14: how long discovery metadata and its JWKS are reused before refetching. */
|
|
@@ -373,6 +373,8 @@ function jwtError(cause, grantId) {
|
|
|
373
373
|
code = 'wrong_audience';
|
|
374
374
|
return new NevarAuthError(code, cause instanceof Error ? cause.message : 'Token verification failed', { cause, grantId });
|
|
375
375
|
}
|
|
376
|
+
/** OperationCatalog id pattern, from actor-context.schema.json (`nevar_callback_op`) at ActorContext rev 3. */
|
|
377
|
+
const OPERATION_ID = /^[a-z][a-z0-9-]*(\.[a-z][a-z0-9-]*)?(\.[a-z][a-z0-9_]*){2}$/;
|
|
376
378
|
function toActorContext(claims, audience) {
|
|
377
379
|
const grantId = typeof claims.nevar_grant_id === 'string' && claims.nevar_grant_id ? claims.nevar_grant_id : null;
|
|
378
380
|
const invalid = (claim) => new NevarAuthError('invalid_token', `Claim ${claim} is missing or invalid`, { grantId });
|
|
@@ -398,6 +400,19 @@ function toActorContext(claims, audience) {
|
|
|
398
400
|
if (act !== undefined && !isActClaim(act)) {
|
|
399
401
|
throw new NevarAuthError('invalid_delegation', 'Claim act is malformed', { grantId });
|
|
400
402
|
}
|
|
403
|
+
// Execution-grant claims (ifc:platform/authentication#ActorContext@r3, sha dfb29f99150b). Neither claim present
|
|
404
|
+
// (JSON null counts as present) means no grant: both null. Otherwise the operation must be an OperationCatalog id
|
|
405
|
+
// and the project claim must be present, a non-empty string or JSON null. We only copy; the callee binds the operation.
|
|
406
|
+
const hasGrantClaims = 'nevar_project_id' in claims || 'nevar_callback_op' in claims;
|
|
407
|
+
const project = claims.nevar_project_id;
|
|
408
|
+
const operation = claims.nevar_callback_op;
|
|
409
|
+
if (hasGrantClaims) {
|
|
410
|
+
if (typeof operation !== 'string' || !OPERATION_ID.test(operation))
|
|
411
|
+
throw invalid('nevar_callback_op');
|
|
412
|
+
if (!('nevar_project_id' in claims) || (project !== null && (typeof project !== 'string' || !project))) {
|
|
413
|
+
throw invalid('nevar_project_id');
|
|
414
|
+
}
|
|
415
|
+
}
|
|
401
416
|
return {
|
|
402
417
|
sub: claims.sub,
|
|
403
418
|
nevar_actor_type: actorType,
|
|
@@ -408,6 +423,8 @@ function toActorContext(claims, audience) {
|
|
|
408
423
|
act: act ?? null,
|
|
409
424
|
role: 'authenticated',
|
|
410
425
|
aud: audience,
|
|
426
|
+
nevar_project_id: hasGrantClaims ? project : null,
|
|
427
|
+
nevar_callback_op: hasGrantClaims ? operation : null,
|
|
411
428
|
};
|
|
412
429
|
}
|
|
413
430
|
function isActClaim(value) {
|
package/dist/testing/index.d.ts
CHANGED
|
@@ -60,6 +60,12 @@ export declare const TEST_GRANTS: {
|
|
|
60
60
|
readonly revoked: "grant_test_revoked";
|
|
61
61
|
readonly apiKey: "grant_test_api_key";
|
|
62
62
|
readonly mcpKey: "grant_test_mcp_key";
|
|
63
|
+
readonly executionGrant: "grant_test_execution_grant";
|
|
64
|
+
};
|
|
65
|
+
/** The execution-grant claims (ActorContext rev 3) on `issuer.tokens.executionGrant`; the operation matches the OperationCatalog id pattern. */
|
|
66
|
+
export declare const TEST_EXECUTION_GRANT: {
|
|
67
|
+
readonly nevar_project_id: "proj_test_1";
|
|
68
|
+
readonly nevar_callback_op: "projects.tasks.run_due";
|
|
63
69
|
};
|
|
64
70
|
/** Claims of the default user token. `sign()` merges overrides onto these. */
|
|
65
71
|
export declare const TEST_USER_CLAIMS: {
|
|
@@ -103,6 +109,8 @@ export interface TestIssuer {
|
|
|
103
109
|
agent: string;
|
|
104
110
|
/** A service token with `aud` = this issuer (Q6): the `serviceToken` for `delegateActor`. */
|
|
105
111
|
service: string;
|
|
112
|
+
/** An execution-grant callback token (ActorContext rev 3): a service actor carrying `TEST_EXECUTION_GRANT`, acting through `act`. */
|
|
113
|
+
executionGrant: string;
|
|
106
114
|
};
|
|
107
115
|
keys: typeof TEST_KEYS;
|
|
108
116
|
introspectionClient: typeof TEST_INTROSPECTION_CLIENT;
|
package/dist/testing/index.js
CHANGED
|
@@ -62,7 +62,10 @@ export const TEST_GRANTS = {
|
|
|
62
62
|
revoked: 'grant_test_revoked',
|
|
63
63
|
apiKey: 'grant_test_api_key',
|
|
64
64
|
mcpKey: 'grant_test_mcp_key',
|
|
65
|
+
executionGrant: 'grant_test_execution_grant',
|
|
65
66
|
};
|
|
67
|
+
/** The execution-grant claims (ActorContext rev 3) on `issuer.tokens.executionGrant`; the operation matches the OperationCatalog id pattern. */
|
|
68
|
+
export const TEST_EXECUTION_GRANT = { nevar_project_id: 'proj_test_1', nevar_callback_op: 'projects.tasks.run_due' };
|
|
66
69
|
/** Claims of the default user token. `sign()` merges overrides onto these. */
|
|
67
70
|
export const TEST_USER_CLAIMS = {
|
|
68
71
|
sub: TEST_SUBJECTS.user,
|
|
@@ -242,6 +245,14 @@ export async function startTestIssuer(options = {}) {
|
|
|
242
245
|
nevar_grant_id: TEST_GRANTS.agent,
|
|
243
246
|
}),
|
|
244
247
|
service: await sign(service),
|
|
248
|
+
executionGrant: await sign({
|
|
249
|
+
sub: TEST_SUBJECTS.service,
|
|
250
|
+
nevar_actor_type: 'service',
|
|
251
|
+
nevar_owner_sub: TEST_SUBJECTS.user,
|
|
252
|
+
nevar_grant_id: TEST_GRANTS.executionGrant,
|
|
253
|
+
act: { sub: TEST_SUBJECTS.service },
|
|
254
|
+
...TEST_EXECUTION_GRANT,
|
|
255
|
+
}),
|
|
245
256
|
};
|
|
246
257
|
return {
|
|
247
258
|
url,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bernierllc/nevar-auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Verifier for Nevar central auth (auth.nevar.io): JWT via OIDC discovery + JWKS, api_/mcp_ keys via RFC 7662 introspection, RFC 8693 delegation, plus a real-HTTP test issuer.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|