@t4h.framework/oidc 0.0.0-experimental-4621dcf-2ba30d83b350fbc392d4 → 0.0.1

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 CHANGED
@@ -23,7 +23,7 @@ You construct it with a context object; your app or hosting layer is responsible
23
23
 
24
24
  | Field | Required | Description |
25
25
  |-------|----------|-------------|
26
- | `wellKnownUrl` | Yes | OpenID Provider configuration document URL (must return JSON with at least `token_endpoint` and `introspection_endpoint`). |
26
+ | `discoveryUrl` | Yes | OpenID Provider configuration document URL (must return JSON with at least `token_endpoint` and `introspection_endpoint`). |
27
27
  | `clientId` | Yes | OAuth 2.0 client identifier used for the client credentials grant. |
28
28
  | `clientSecret` | Yes | OAuth 2.0 client secret used for the client credentials grant. |
29
29
  | `token` | Yes | Credential to verify. Must use a `Bearer ` prefix (see below). |
@@ -40,15 +40,16 @@ The default export is an async function:
40
40
 
41
41
  Behavior:
42
42
 
43
- 1. **Discovery** — `GET` `wellKnownUrl` and read JSON with `token_endpoint` and `introspection_endpoint`.
43
+ 1. **Discovery** — `GET` `discoveryUrl` and read JSON with `token_endpoint` and `introspection_endpoint`.
44
44
  2. **Client credentials** — `POST` the token endpoint with `grant_type=client_credentials`, `client_id`, `client_secret`, and optional `scope` / `resource` (`application/x-www-form-urlencoded`).
45
- 3. **Introspection** — `POST` the introspection endpoint with JSON body `{ "token": "<access token>" }`, where the value is taken from `token` after stripping a leading `Authorization: Bearer ` style prefix (the implementation expects `token` to start with `Bearer `).
45
+ 3. **Introspection** — `POST` the introspection endpoint with JSON body `{ "token": "<access token>" }`, where the value is taken from `token` after stripping the leading `Bearer ` prefix.
46
46
  4. **Authorization header** — The introspection call uses `Authorization: Bearer <access_token>` with the access token from step 2.
47
47
 
48
48
  Result:
49
49
 
50
50
  - Returns `true` if the introspection response includes `"active": true`.
51
- - Returns `false` if the token is inactive or introspection indicates failure (including when the Bearer prefix is missing or the token cannot be extracted).
51
+ - Returns `false` when the introspection response includes `"active": false`.
52
+ - If the incoming credential does not start with `Bearer `, the handler sends `token: null` to introspection (final result then depends on the provider response, and is typically `false`).
52
53
 
53
54
  There is no built-in mapping from environment variables; all configuration comes from the manifest context.
54
55
 
@@ -58,7 +59,7 @@ There is no built-in mapping from environment variables; all configuration comes
58
59
  import { OIDCAuthorization } from '@t4h.framework/oidc'
59
60
 
60
61
  const authorization = new OIDCAuthorization({
61
- wellKnownUrl: 'https://auth.example.com/.well-known/openid-configuration',
62
+ discoveryUrl: 'https://auth.example.com/.well-known/openid-configuration',
62
63
  clientId: 'my-service',
63
64
  clientSecret: process.env.OIDC_CLIENT_SECRET!,
64
65
  token: 'Bearer <incoming-access-token-from-runtime>',
@@ -1,4 +1,4 @@
1
- import { Authorization, type AuthenticationManifest } from '@t4h.framework/core';
1
+ import { Authorization, type AuthorizationManifest } from '@t4h.framework/core';
2
2
  export type OIDCAuthorizationContext = {
3
3
  discoveryUrl: string;
4
4
  clientId: string;
@@ -7,7 +7,7 @@ export type OIDCAuthorizationContext = {
7
7
  scope?: string[];
8
8
  resource?: string;
9
9
  };
10
- export type OIDCAuthorizationManifest = AuthenticationManifest<OIDCAuthorizationContext>;
10
+ export type OIDCAuthorizationManifest = AuthorizationManifest<OIDCAuthorizationContext>;
11
11
  export declare class OIDCAuthorization extends Authorization<OIDCAuthorizationContext> {
12
12
  private readonly context;
13
13
  constructor(context: OIDCAuthorizationContext);
@@ -1 +1 @@
1
- {"version":3,"file":"OIDCAuthorization.d.ts","sourceRoot":"","sources":["../../src/models/OIDCAuthorization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,sBAAsB,EAAE,MAAM,qBAAqB,CAAA;AAEhF,MAAM,MAAM,wBAAwB,GAAG;IACrC,YAAY,EAAE,MAAM,CAAA;IACpB,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,MAAM,CAAA;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,yBAAyB,GACnC,sBAAsB,CAAC,wBAAwB,CAAC,CAAA;AAElD,qBAAa,iBAAkB,SAAQ,aAAa,CAAC,wBAAwB,CAAC;IAChE,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,wBAAwB;IAIvD,UAAU,IAAI,yBAAyB;CAa/C"}
1
+ {"version":3,"file":"OIDCAuthorization.d.ts","sourceRoot":"","sources":["../../src/models/OIDCAuthorization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAE/E,MAAM,MAAM,wBAAwB,GAAG;IACrC,YAAY,EAAE,MAAM,CAAA;IACpB,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,MAAM,CAAA;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,yBAAyB,GACnC,qBAAqB,CAAC,wBAAwB,CAAC,CAAA;AAEjD,qBAAa,iBAAkB,SAAQ,aAAa,CAAC,wBAAwB,CAAC;IAChE,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,wBAAwB;IAIvD,UAAU,IAAI,yBAAyB;CAa/C"}
@@ -1 +1 @@
1
- {"version":3,"file":"OIDCAuthorization.js","sourceRoot":"","sources":["../../src/models/OIDCAuthorization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA+B,MAAM,qBAAqB,CAAA;AAchF,MAAM,OAAO,iBAAkB,SAAQ,aAAuC;IAC/C;IAA7B,YAA6B,OAAiC;QAC5D,KAAK,EAAE,CAAA;QADoB,YAAO,GAAP,OAAO,CAA0B;IAE9D,CAAC;IAEM,UAAU;QACf,OAAO;YACL,OAAO,EAAE;gBACP,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY;gBACvC,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ;gBAC/B,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY;gBACvC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK;gBACzB,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ;gBAC/B,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK;aAC1B;YACD,YAAY,EAAE,+BAA+B;SAC9C,CAAA;IACH,CAAC;CACF"}
1
+ {"version":3,"file":"OIDCAuthorization.js","sourceRoot":"","sources":["../../src/models/OIDCAuthorization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA8B,MAAM,qBAAqB,CAAA;AAc/E,MAAM,OAAO,iBAAkB,SAAQ,aAAuC;IAC/C;IAA7B,YAA6B,OAAiC;QAC5D,KAAK,EAAE,CAAA;QADoB,YAAO,GAAP,OAAO,CAA0B;IAE9D,CAAC;IAEM,UAAU;QACf,OAAO;YACL,OAAO,EAAE;gBACP,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY;gBACvC,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ;gBAC/B,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY;gBACvC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK;gBACzB,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ;gBAC/B,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK;aAC1B;YACD,YAAY,EAAE,+BAA+B;SAC9C,CAAA;IACH,CAAC;CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"oidc-authorize.d.ts","sourceRoot":"","sources":["../src/oidc-authorize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAA;AAezD,wBAA8B,IAAI,CAChC,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,OAAO,CAAC,CAwClB"}
1
+ {"version":3,"file":"oidc-authorize.d.ts","sourceRoot":"","sources":["../src/oidc-authorize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAA;AAezD,wBAA8B,IAAI,CAChC,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,OAAO,CAAC,CAiElB"}
@@ -5,9 +5,12 @@ function getAccessToken(token) {
5
5
  return accessToken;
6
6
  }
7
7
  export default async function oidc(context) {
8
- const discovery = await fetch(context.discoveryUrl, {
8
+ const discoveryResponse = await fetch(context.discoveryUrl, {
9
9
  method: 'GET',
10
- }).then(response => response.json());
10
+ });
11
+ if (!discoveryResponse.ok)
12
+ throw new Error(`Discovery request failed: ${discoveryResponse.status} ${discoveryResponse.statusText}`);
13
+ const discovery = (await discoveryResponse.json());
11
14
  const scope = Array.isArray(context.scope)
12
15
  ? context.scope.join(' ')
13
16
  : context.scope;
@@ -20,14 +23,17 @@ export default async function oidc(context) {
20
23
  body.scope = scope;
21
24
  if (context.resource)
22
25
  body.resource = context.resource;
23
- const { access_token } = await fetch(discovery.token_endpoint, {
26
+ const tokenResponse = await fetch(discovery.token_endpoint, {
24
27
  body: new URLSearchParams(body),
25
28
  method: 'POST',
26
29
  headers: {
27
30
  'Content-Type': 'application/x-www-form-urlencoded',
28
31
  },
29
- }).then(response => response.json());
30
- const introspection = await fetch(discovery.introspection_endpoint, {
32
+ });
33
+ if (!tokenResponse.ok)
34
+ throw new Error(`Token request failed: ${tokenResponse.status} ${tokenResponse.statusText}`);
35
+ const { access_token } = (await tokenResponse.json());
36
+ const introspectionResponse = await fetch(discovery.introspection_endpoint, {
31
37
  body: JSON.stringify({
32
38
  token: getAccessToken(context.token),
33
39
  }),
@@ -36,7 +42,10 @@ export default async function oidc(context) {
36
42
  'Content-Type': 'application/json',
37
43
  Authorization: `Bearer ${access_token}`,
38
44
  },
39
- }).then(response => response.json());
45
+ });
46
+ if (!introspectionResponse.ok)
47
+ throw new Error(`Introspection request failed: ${introspectionResponse.status} ${introspectionResponse.statusText}`);
48
+ const introspection = (await introspectionResponse.json());
40
49
  if (!introspection.active)
41
50
  return false;
42
51
  return true;
@@ -1 +1 @@
1
- {"version":3,"file":"oidc-authorize.js","sourceRoot":"","sources":["../src/oidc-authorize.ts"],"names":[],"mappings":"AAOA,SAAS,cAAc,CAAC,KAAa;IACnC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC;QAAE,OAAO,IAAI,CAAA;IAE7C,MAAM,CAAC,EAAE,WAAW,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;IAE9C,OAAO,WAAW,CAAA;AACpB,CAAC;AAED,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,IAAI,CAChC,OAAiC;IAEjC,MAAM,SAAS,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,YAAY,EAAE;QAClD,MAAM,EAAE,KAAK;KACd,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAkC,CAAC,CAAA;IAEpE,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;QACxC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC;QACzB,CAAC,CAAC,OAAO,CAAC,KAAK,CAAA;IAEjB,MAAM,IAAI,GAA2B;QACnC,UAAU,EAAE,oBAAoB;QAChC,SAAS,EAAE,OAAO,CAAC,QAAQ;QAC3B,aAAa,EAAE,OAAO,CAAC,YAAY;KACpC,CAAA;IAED,IAAI,KAAK;QAAE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IAC7B,IAAI,OAAO,CAAC,QAAQ;QAAE,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAA;IAEtD,MAAM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;YACnB,KAAK,EAAE,cAAc,CAAC,OAAO,CAAC,KAAK,CAAC;SACrC,CAAC;QACF,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;YAClC,aAAa,EAAE,UAAU,YAAY,EAAE;SACxC;KACF,CAAC,CAAA;IAEF,IAAI,CAAC,qBAAqB,CAAC,EAAE;QAC3B,MAAM,IAAI,KAAK,CACb,iCAAiC,qBAAqB,CAAC,MAAM,IAAI,qBAAqB,CAAC,UAAU,EAAE,CACpG,CAAA;IAEH,MAAM,aAAa,GAAG,CAAC,MAAM,qBAAqB,CAAC,IAAI,EAAE,CAExD,CAAA;IAED,IAAI,CAAC,aAAa,CAAC,MAAM;QAAE,OAAO,KAAK,CAAA;IAEvC,OAAO,IAAI,CAAA;AACb,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t4h.framework/oidc",
3
- "version": "0.0.0-experimental-4621dcf-2ba30d83b350fbc392d4",
3
+ "version": "0.0.1",
4
4
  "description": "OIDC module for the T4H Framework authorization",
5
5
  "homepage": "https://github.com/tech4humans-brasil/framework/tree/main/packages/oidc",
6
6
  "bugs": "https://github.com/tech4humans-brasil/framework/issues",
@@ -36,16 +36,15 @@
36
36
  "test:watch": "vitest"
37
37
  },
38
38
  "devDependencies": {
39
- "@t4h.framework/core": "^0.0.0-experimental-4621dcf-2ba30d83b350fbc392d4",
39
+ "@t4h.framework/core": "^0.0.1",
40
40
  "typescript": "^5.9.3",
41
41
  "vitest": "^4.0.18"
42
42
  },
43
43
  "peerDependencies": {
44
- "@t4h.framework/core": "^0.0.0-experimental-4621dcf-2ba30d83b350fbc392d4"
44
+ "@t4h.framework/core": "^0.0.1"
45
45
  },
46
46
  "packageManager": "yarn@4.12.0",
47
47
  "engines": {
48
48
  "node": ">=22"
49
- },
50
- "stableVersion": "0.0.0"
49
+ }
51
50
  }