@platf/bridge 0.0.19 → 0.0.21
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/dist/lib/discoveryRoutes.d.ts +0 -2
- package/dist/lib/discoveryRoutes.js +3 -9
- package/dist/lib/discoveryRoutes.js.map +1 -1
- package/dist/lib/express.js +1 -3
- package/dist/lib/express.js.map +1 -1
- package/dist/lib/headers.d.ts +1 -1
- package/dist/lib/onSignals.d.ts +1 -1
- package/dist/lib/sessionAccessCounter.d.ts +1 -1
- package/package.json +1 -1
- package/src/lib/discoveryRoutes.ts +3 -9
- package/src/lib/express.ts +1 -3
- package/src/lib/headers.ts +1 -1
- package/src/lib/onSignals.ts +1 -1
- package/src/lib/sessionAccessCounter.ts +1 -1
- package/dist/lib/oauthProxy.d.ts +0 -14
- package/dist/lib/oauthProxy.js +0 -80
- package/dist/lib/oauthProxy.js.map +0 -1
- package/src/lib/oauthProxy.ts +0 -86
|
@@ -6,8 +6,6 @@
|
|
|
6
6
|
* - GET /.well-known/oauth-authorization-server[/*] (RFC 8414 — proxied from issuer)
|
|
7
7
|
* - POST /register (Pseudo-DCR — RFC 7591)
|
|
8
8
|
*
|
|
9
|
-
* OAuth proxy routes (/authorize, /token, /jwks) are in oauthProxy.ts.
|
|
10
|
-
*
|
|
11
9
|
* These endpoints are unauthenticated — they must be accessible to
|
|
12
10
|
* any client performing OAuth discovery before obtaining a token.
|
|
13
11
|
*/
|
|
@@ -6,8 +6,6 @@
|
|
|
6
6
|
* - GET /.well-known/oauth-authorization-server[/*] (RFC 8414 — proxied from issuer)
|
|
7
7
|
* - POST /register (Pseudo-DCR — RFC 7591)
|
|
8
8
|
*
|
|
9
|
-
* OAuth proxy routes (/authorize, /token, /jwks) are in oauthProxy.ts.
|
|
10
|
-
*
|
|
11
9
|
* These endpoints are unauthenticated — they must be accessible to
|
|
12
10
|
* any client performing OAuth discovery before obtaining a token.
|
|
13
11
|
*/
|
|
@@ -80,15 +78,11 @@ export function createDiscoveryRouter(auth, logger) {
|
|
|
80
78
|
return res.status(502).json({ error: 'upstream_error' });
|
|
81
79
|
}
|
|
82
80
|
const metadata = (await upstream.json());
|
|
83
|
-
//
|
|
81
|
+
// Only patch registration_endpoint to point to our pseudo-DCR
|
|
82
|
+
// Keep original issuer/authorization_endpoint/token_endpoint so tokens validate correctly
|
|
84
83
|
const scheme = req.protocol;
|
|
85
84
|
const host = req.get('host');
|
|
86
|
-
|
|
87
|
-
metadata.issuer = bridgeOrigin;
|
|
88
|
-
metadata.authorization_endpoint = `${bridgeOrigin}/authorize`;
|
|
89
|
-
metadata.token_endpoint = `${bridgeOrigin}/token`;
|
|
90
|
-
metadata.registration_endpoint = `${bridgeOrigin}/register`;
|
|
91
|
-
metadata.jwks_uri = `${bridgeOrigin}/jwks`;
|
|
85
|
+
metadata.registration_endpoint = `${scheme}://${host}/register`;
|
|
92
86
|
res.json(metadata);
|
|
93
87
|
}
|
|
94
88
|
catch (err) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discoveryRoutes.js","sourceRoot":"","sources":["../../src/lib/discoveryRoutes.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"discoveryRoutes.js","sourceRoot":"","sources":["../../src/lib/discoveryRoutes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,MAAM,EAA+B,MAAM,SAAS,CAAA;AAG7D,MAAM,UAAU,qBAAqB,CAAC,IAAgB,EAAE,MAAc;IACpE,MAAM,MAAM,GAAG,MAAM,EAAE,CAAA;IAEvB;;;;;;;;;;;;;;;;;;OAkBG;IACH,MAAM,CAAC,GAAG,CAAC,uCAAuC,EAAE,CAAC,GAAY,EAAE,GAAa,EAAE,EAAE;QAClF,wDAAwD;QACxD,+CAA+C;QAC/C,MAAM,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAA;QAC3B,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,MA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,8CAA8C;YAC9C,0BAA0B,EAAE,MAAM;YAClC,WAAW,EAAE,CAAC,oBAAoB,CAAC;YACnC,cAAc,EAAE,CAAC,MAAM,CAAC;YACxB,aAAa,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE;SAC3E,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/dist/lib/express.js
CHANGED
|
@@ -8,7 +8,6 @@ import express from 'express';
|
|
|
8
8
|
import cors from 'cors';
|
|
9
9
|
import { serializeCorsOrigin } from './cors.js';
|
|
10
10
|
import { createDiscoveryRouter } from './discoveryRoutes.js';
|
|
11
|
-
import { createOAuthProxyRouter } from './oauthProxy.js';
|
|
12
11
|
import { createAuthMiddleware } from './authMiddleware.js';
|
|
13
12
|
/** Set custom response headers */
|
|
14
13
|
export const setResponseHeaders = (res, headers) => Object.entries(headers).forEach(([key, value]) => res.setHeader(key, value));
|
|
@@ -29,6 +28,7 @@ export function createApp(options) {
|
|
|
29
28
|
const app = express();
|
|
30
29
|
app.set('trust proxy', true);
|
|
31
30
|
app.use(express.json());
|
|
31
|
+
app.use(express.urlencoded({ extended: true }));
|
|
32
32
|
// CORS
|
|
33
33
|
if (corsOrigin) {
|
|
34
34
|
app.use(cors({ origin: corsOrigin, exposedHeaders: ['Mcp-Session-Id'] }));
|
|
@@ -51,8 +51,6 @@ export function createApp(options) {
|
|
|
51
51
|
if (auth) {
|
|
52
52
|
// Discovery routes (PRM, AS metadata, pseudo-DCR)
|
|
53
53
|
app.use(createDiscoveryRouter(auth, logger));
|
|
54
|
-
// OAuth proxy routes (authorize redirect, token proxy, JWKS proxy)
|
|
55
|
-
app.use(createOAuthProxyRouter(auth, logger));
|
|
56
54
|
// Auth middleware on MCP path
|
|
57
55
|
app.use(mcpPath, createAuthMiddleware(auth, logger));
|
|
58
56
|
logger.info(` - Auth: enabled (issuer=${auth.issuer})`);
|
package/dist/lib/express.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"express.js","sourceRoot":"","sources":["../../src/lib/express.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,OAAwC,MAAM,SAAS,CAAA;AAC9D,OAAO,IAA0B,MAAM,MAAM,CAAA;AAE7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAC5D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"express.js","sourceRoot":"","sources":["../../src/lib/express.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,OAAwC,MAAM,SAAS,CAAA;AAC9D,OAAO,IAA0B,MAAM,MAAM,CAAA;AAE7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAY1D,kCAAkC;AAClC,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAa,EAAE,OAA+B,EAAE,EAAE,CACnF,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAA;AAE9E;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,SAAS,CAAC,OAAyB;IACjD,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAA;IAE/E,MAAM,GAAG,GAAG,OAAO,EAAE,CAAA;IACrB,GAAG,CAAC,GAAG,CAAC,aAAa,EAAE,IAAI,CAA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AAC,MAAM,GAAG,CAAC,CAAA;IAC1D,CAAC;SAAM,CAAC;QACN,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAA;IACnC,CAAC;IAED,OAAO,GAAG,CAAA;AACZ,CAAC"}
|
package/dist/lib/headers.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Logger } from '
|
|
1
|
+
import type { Logger } from '@/types.js';
|
|
2
2
|
export declare function parseHeaders(rawHeaders: (string | number)[], logger: Logger): Record<string, string>;
|
package/dist/lib/onSignals.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -6,8 +6,6 @@
|
|
|
6
6
|
* - GET /.well-known/oauth-authorization-server[/*] (RFC 8414 — proxied from issuer)
|
|
7
7
|
* - POST /register (Pseudo-DCR — RFC 7591)
|
|
8
8
|
*
|
|
9
|
-
* OAuth proxy routes (/authorize, /token, /jwks) are in oauthProxy.ts.
|
|
10
|
-
*
|
|
11
9
|
* These endpoints are unauthenticated — they must be accessible to
|
|
12
10
|
* any client performing OAuth discovery before obtaining a token.
|
|
13
11
|
*/
|
|
@@ -89,15 +87,11 @@ export function createDiscoveryRouter(auth: AuthConfig, logger: Logger): Router
|
|
|
89
87
|
|
|
90
88
|
const metadata = (await upstream.json()) as Record<string, unknown>
|
|
91
89
|
|
|
92
|
-
//
|
|
90
|
+
// Only patch registration_endpoint to point to our pseudo-DCR
|
|
91
|
+
// Keep original issuer/authorization_endpoint/token_endpoint so tokens validate correctly
|
|
93
92
|
const scheme = req.protocol
|
|
94
93
|
const host = req.get('host')
|
|
95
|
-
|
|
96
|
-
metadata.issuer = bridgeOrigin
|
|
97
|
-
metadata.authorization_endpoint = `${bridgeOrigin}/authorize`
|
|
98
|
-
metadata.token_endpoint = `${bridgeOrigin}/token`
|
|
99
|
-
metadata.registration_endpoint = `${bridgeOrigin}/register`
|
|
100
|
-
metadata.jwks_uri = `${bridgeOrigin}/jwks`
|
|
94
|
+
metadata.registration_endpoint = `${scheme}://${host}/register`
|
|
101
95
|
|
|
102
96
|
res.json(metadata)
|
|
103
97
|
} catch (err: any) {
|
package/src/lib/express.ts
CHANGED
|
@@ -10,7 +10,6 @@ import cors, { type CorsOptions } from 'cors'
|
|
|
10
10
|
import type { AuthConfig, Logger } from '../types.js'
|
|
11
11
|
import { serializeCorsOrigin } from './cors.js'
|
|
12
12
|
import { createDiscoveryRouter } from './discoveryRoutes.js'
|
|
13
|
-
import { createOAuthProxyRouter } from './oauthProxy.js'
|
|
14
13
|
import { createAuthMiddleware } from './authMiddleware.js'
|
|
15
14
|
|
|
16
15
|
export interface CreateAppOptions {
|
|
@@ -45,6 +44,7 @@ export function createApp(options: CreateAppOptions): Express {
|
|
|
45
44
|
const app = express()
|
|
46
45
|
app.set('trust proxy', true)
|
|
47
46
|
app.use(express.json())
|
|
47
|
+
app.use(express.urlencoded({ extended: true }))
|
|
48
48
|
|
|
49
49
|
// CORS
|
|
50
50
|
if (corsOrigin) {
|
|
@@ -69,8 +69,6 @@ export function createApp(options: CreateAppOptions): Express {
|
|
|
69
69
|
if (auth) {
|
|
70
70
|
// Discovery routes (PRM, AS metadata, pseudo-DCR)
|
|
71
71
|
app.use(createDiscoveryRouter(auth, logger))
|
|
72
|
-
// OAuth proxy routes (authorize redirect, token proxy, JWKS proxy)
|
|
73
|
-
app.use(createOAuthProxyRouter(auth, logger))
|
|
74
72
|
// Auth middleware on MCP path
|
|
75
73
|
app.use(mcpPath, createAuthMiddleware(auth, logger))
|
|
76
74
|
logger.info(` - Auth: enabled (issuer=${auth.issuer})`)
|
package/src/lib/headers.ts
CHANGED
package/src/lib/onSignals.ts
CHANGED
package/dist/lib/oauthProxy.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OAuth 2.0 proxy routes for the bridge.
|
|
3
|
-
*
|
|
4
|
-
* These routes proxy OAuth endpoints to the upstream authorization server:
|
|
5
|
-
* - GET /authorize → Redirect to upstream (preserves query params)
|
|
6
|
-
* - POST /token → Proxy to upstream
|
|
7
|
-
* - GET /jwks → Proxy JWKS for token verification
|
|
8
|
-
*
|
|
9
|
-
* This separation allows the bridge to advertise itself as the authorization
|
|
10
|
-
* server while delegating actual auth operations to the upstream issuer.
|
|
11
|
-
*/
|
|
12
|
-
import { Router } from 'express';
|
|
13
|
-
import type { AuthConfig, Logger } from '../types.js';
|
|
14
|
-
export declare function createOAuthProxyRouter(auth: AuthConfig, logger: Logger): Router;
|
package/dist/lib/oauthProxy.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OAuth 2.0 proxy routes for the bridge.
|
|
3
|
-
*
|
|
4
|
-
* These routes proxy OAuth endpoints to the upstream authorization server:
|
|
5
|
-
* - GET /authorize → Redirect to upstream (preserves query params)
|
|
6
|
-
* - POST /token → Proxy to upstream
|
|
7
|
-
* - GET /jwks → Proxy JWKS for token verification
|
|
8
|
-
*
|
|
9
|
-
* This separation allows the bridge to advertise itself as the authorization
|
|
10
|
-
* server while delegating actual auth operations to the upstream issuer.
|
|
11
|
-
*/
|
|
12
|
-
import { Router } from 'express';
|
|
13
|
-
export function createOAuthProxyRouter(auth, logger) {
|
|
14
|
-
const router = Router();
|
|
15
|
-
/**
|
|
16
|
-
* OAuth Authorization Endpoint — Redirect to upstream
|
|
17
|
-
*
|
|
18
|
-
* Since the bridge advertises itself as the authorization_server,
|
|
19
|
-
* clients will attempt to call /authorize here. We redirect
|
|
20
|
-
* to the upstream auth server, preserving all query parameters.
|
|
21
|
-
*/
|
|
22
|
-
router.get('/authorize', (req, res) => {
|
|
23
|
-
const upstreamUrl = new URL(`${auth.issuer}/authorize`);
|
|
24
|
-
// Copy all query params to upstream
|
|
25
|
-
for (const [key, value] of Object.entries(req.query)) {
|
|
26
|
-
if (typeof value === 'string') {
|
|
27
|
-
upstreamUrl.searchParams.set(key, value);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
logger.info(`[oauth-proxy] Redirecting /authorize to upstream`);
|
|
31
|
-
res.redirect(upstreamUrl.toString());
|
|
32
|
-
});
|
|
33
|
-
/**
|
|
34
|
-
* OAuth Token Endpoint — Proxy to upstream
|
|
35
|
-
*
|
|
36
|
-
* Proxies token exchange requests to the upstream auth server.
|
|
37
|
-
*/
|
|
38
|
-
router.post('/token', async (req, res) => {
|
|
39
|
-
try {
|
|
40
|
-
const upstreamUrl = `${auth.issuer}/token`;
|
|
41
|
-
logger.info('[oauth-proxy] Proxying /token to upstream');
|
|
42
|
-
const upstreamRes = await fetch(upstreamUrl, {
|
|
43
|
-
method: 'POST',
|
|
44
|
-
headers: {
|
|
45
|
-
'Content-Type': req.get('Content-Type') || 'application/x-www-form-urlencoded',
|
|
46
|
-
},
|
|
47
|
-
body: req.get('Content-Type')?.includes('application/json')
|
|
48
|
-
? JSON.stringify(req.body)
|
|
49
|
-
: new URLSearchParams(req.body).toString(),
|
|
50
|
-
});
|
|
51
|
-
const data = await upstreamRes.text();
|
|
52
|
-
res.status(upstreamRes.status);
|
|
53
|
-
res.set('Content-Type', upstreamRes.headers.get('Content-Type') || 'application/json');
|
|
54
|
-
res.send(data);
|
|
55
|
-
}
|
|
56
|
-
catch (err) {
|
|
57
|
-
logger.error('[oauth-proxy] Error proxying /token:', err.message ?? err);
|
|
58
|
-
res.status(502).json({ error: 'upstream_error' });
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
/**
|
|
62
|
-
* JWKS Endpoint — Proxy to upstream
|
|
63
|
-
*
|
|
64
|
-
* Proxies JSON Web Key Set requests for token verification.
|
|
65
|
-
*/
|
|
66
|
-
router.get('/jwks', async (_req, res) => {
|
|
67
|
-
try {
|
|
68
|
-
const upstreamUrl = `${auth.issuer}/jwks`;
|
|
69
|
-
const upstreamRes = await fetch(upstreamUrl);
|
|
70
|
-
const data = await upstreamRes.json();
|
|
71
|
-
res.json(data);
|
|
72
|
-
}
|
|
73
|
-
catch (err) {
|
|
74
|
-
logger.error('[oauth-proxy] Error proxying /jwks:', err.message ?? err);
|
|
75
|
-
res.status(502).json({ error: 'upstream_error' });
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
return router;
|
|
79
|
-
}
|
|
80
|
-
//# sourceMappingURL=oauthProxy.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"oauthProxy.js","sourceRoot":"","sources":["../../src/lib/oauthProxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,MAAM,EAA+B,MAAM,SAAS,CAAA;AAG7D,MAAM,UAAU,sBAAsB,CAAC,IAAgB,EAAE,MAAc;IACrE,MAAM,MAAM,GAAG,MAAM,EAAE,CAAA;IAEvB;;;;;;OAMG;IACH,MAAM,CAAC,GAAG,CAAC,YAAY,EAAE,CAAC,GAAY,EAAE,GAAa,EAAE,EAAE;QACvD,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,YAAY,CAAC,CAAA;QACvD,oCAAoC;QACpC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YACrD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBAC9B,WAAW,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;YAC1C,CAAC;QACH,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,kDAAkD,CAAC,CAAA;QAC/D,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,CAAA;IACtC,CAAC,CAAC,CAAA;IAEF;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,EAAE;QAC1D,IAAI,CAAC;YACH,MAAM,WAAW,GAAG,GAAG,IAAI,CAAC,MAAM,QAAQ,CAAA;YAC1C,MAAM,CAAC,IAAI,CAAC,2CA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C,CAAA;YAC5C,MAAM,IAAI,GAAG,MAAM,WAAW,CAAC,IAAI,EAAE,CAAA;YACrC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAChB,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,MAAM,CAAC,KAAK,CAAC,qCAAqC,EAAE,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,CAAA;YACvE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,gBAAgB,EAAE,CAAC,CAAA;QACnD,CAAC;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/src/lib/oauthProxy.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OAuth 2.0 proxy routes for the bridge.
|
|
3
|
-
*
|
|
4
|
-
* These routes proxy OAuth endpoints to the upstream authorization server:
|
|
5
|
-
* - GET /authorize → Redirect to upstream (preserves query params)
|
|
6
|
-
* - POST /token → Proxy to upstream
|
|
7
|
-
* - GET /jwks → Proxy JWKS for token verification
|
|
8
|
-
*
|
|
9
|
-
* This separation allows the bridge to advertise itself as the authorization
|
|
10
|
-
* server while delegating actual auth operations to the upstream issuer.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { Router, type Request, type Response } from 'express'
|
|
14
|
-
import type { AuthConfig, Logger } from '../types.js'
|
|
15
|
-
|
|
16
|
-
export function createOAuthProxyRouter(auth: AuthConfig, logger: Logger): Router {
|
|
17
|
-
const router = Router()
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* OAuth Authorization Endpoint — Redirect to upstream
|
|
21
|
-
*
|
|
22
|
-
* Since the bridge advertises itself as the authorization_server,
|
|
23
|
-
* clients will attempt to call /authorize here. We redirect
|
|
24
|
-
* to the upstream auth server, preserving all query parameters.
|
|
25
|
-
*/
|
|
26
|
-
router.get('/authorize', (req: Request, res: Response) => {
|
|
27
|
-
const upstreamUrl = new URL(`${auth.issuer}/authorize`)
|
|
28
|
-
// Copy all query params to upstream
|
|
29
|
-
for (const [key, value] of Object.entries(req.query)) {
|
|
30
|
-
if (typeof value === 'string') {
|
|
31
|
-
upstreamUrl.searchParams.set(key, value)
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
logger.info(`[oauth-proxy] Redirecting /authorize to upstream`)
|
|
35
|
-
res.redirect(upstreamUrl.toString())
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* OAuth Token Endpoint — Proxy to upstream
|
|
40
|
-
*
|
|
41
|
-
* Proxies token exchange requests to the upstream auth server.
|
|
42
|
-
*/
|
|
43
|
-
router.post('/token', async (req: Request, res: Response) => {
|
|
44
|
-
try {
|
|
45
|
-
const upstreamUrl = `${auth.issuer}/token`
|
|
46
|
-
logger.info('[oauth-proxy] Proxying /token to upstream')
|
|
47
|
-
|
|
48
|
-
const upstreamRes = await fetch(upstreamUrl, {
|
|
49
|
-
method: 'POST',
|
|
50
|
-
headers: {
|
|
51
|
-
'Content-Type': req.get('Content-Type') || 'application/x-www-form-urlencoded',
|
|
52
|
-
},
|
|
53
|
-
body: req.get('Content-Type')?.includes('application/json')
|
|
54
|
-
? JSON.stringify(req.body)
|
|
55
|
-
: new URLSearchParams(req.body as Record<string, string>).toString(),
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
const data = await upstreamRes.text()
|
|
59
|
-
res.status(upstreamRes.status)
|
|
60
|
-
res.set('Content-Type', upstreamRes.headers.get('Content-Type') || 'application/json')
|
|
61
|
-
res.send(data)
|
|
62
|
-
} catch (err: any) {
|
|
63
|
-
logger.error('[oauth-proxy] Error proxying /token:', err.message ?? err)
|
|
64
|
-
res.status(502).json({ error: 'upstream_error' })
|
|
65
|
-
}
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* JWKS Endpoint — Proxy to upstream
|
|
70
|
-
*
|
|
71
|
-
* Proxies JSON Web Key Set requests for token verification.
|
|
72
|
-
*/
|
|
73
|
-
router.get('/jwks', async (_req: Request, res: Response) => {
|
|
74
|
-
try {
|
|
75
|
-
const upstreamUrl = `${auth.issuer}/jwks`
|
|
76
|
-
const upstreamRes = await fetch(upstreamUrl)
|
|
77
|
-
const data = await upstreamRes.json()
|
|
78
|
-
res.json(data)
|
|
79
|
-
} catch (err: any) {
|
|
80
|
-
logger.error('[oauth-proxy] Error proxying /jwks:', err.message ?? err)
|
|
81
|
-
res.status(502).json({ error: 'upstream_error' })
|
|
82
|
-
}
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
return router
|
|
86
|
-
}
|