@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 +6 -5
- package/dist/models/OIDCAuthorization.d.ts +2 -2
- package/dist/models/OIDCAuthorization.d.ts.map +1 -1
- package/dist/models/OIDCAuthorization.js.map +1 -1
- package/dist/oidc-authorize.d.ts.map +1 -1
- package/dist/oidc-authorize.js +15 -6
- package/dist/oidc-authorize.js.map +1 -1
- package/package.json +4 -5
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
|
-
| `
|
|
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` `
|
|
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
|
|
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`
|
|
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
|
-
|
|
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
|
|
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 =
|
|
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,
|
|
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,
|
|
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,
|
|
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"}
|
package/dist/oidc-authorize.js
CHANGED
|
@@ -5,9 +5,12 @@ function getAccessToken(token) {
|
|
|
5
5
|
return accessToken;
|
|
6
6
|
}
|
|
7
7
|
export default async function oidc(context) {
|
|
8
|
-
const
|
|
8
|
+
const discoveryResponse = await fetch(context.discoveryUrl, {
|
|
9
9
|
method: 'GET',
|
|
10
|
-
})
|
|
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
|
|
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
|
-
})
|
|
30
|
-
|
|
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
|
-
})
|
|
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,MAA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CAAA;IAEtD,MAAM,aAAa,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC,cAAc,EAAE;QAC1D,IAAI,EAAE,IAAI,eAAe,CAAC,IAAI,CAAC;QAC/B,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,cAAc,EAAE,mCAAmC;SACpD;KACF,CAAC,CAAA;IAEF,IAAI,CAAC,aAAa,CAAC,EAAE;QACnB,MAAM,IAAI,KAAK,CACb,yBAAyB,aAAa,CAAC,MAAM,IAAI,aAAa,CAAC,UAAU,EAAE,CAC5E,CAAA;IAEH,MAAM,EAAE,YAAY,EAAE,GAAG,CAAC,MAAM,aAAa,CAAC,IAAI,EAAE,CAEnD,CAAA;IAED,MAAM,qBAAqB,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC,sBAAsB,EAAE;QAC1E,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;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.
|
|
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.
|
|
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.
|
|
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
|
}
|