@oslokommune/auth-bff 2.0.1 → 2.1.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
CHANGED
|
@@ -81,7 +81,7 @@ WORKDIR /application
|
|
|
81
81
|
EXPOSE 8080
|
|
82
82
|
COPY --from=build /home/app/dist /application/dist
|
|
83
83
|
ENV NODE_ENV=production
|
|
84
|
-
RUN npm install -g @oslokommune/auth-bff@2.0
|
|
84
|
+
RUN npm install -g @oslokommune/auth-bff@2.1.0
|
|
85
85
|
COPY bff.config.json /application/
|
|
86
86
|
CMD ["auth-bff"]
|
|
87
87
|
```
|
|
@@ -140,6 +140,8 @@ Standalone:
|
|
|
140
140
|
auth-bff --configFile /path/to/bff.config.json
|
|
141
141
|
```
|
|
142
142
|
|
|
143
|
+
### Loading values from environment or AWS Parameter Store
|
|
144
|
+
|
|
143
145
|
The config file supports two special forms for loading values from other sources. Primarily meant for loading secrets:
|
|
144
146
|
|
|
145
147
|
Environment values:
|
|
@@ -164,6 +166,29 @@ variable must be set, and you must be signed in to that profile
|
|
|
164
166
|
> [!NOTE]
|
|
165
167
|
>️ See [`config.ts`](src/config.ts) for a description of all config parameters
|
|
166
168
|
|
|
169
|
+
### Mixing public and protected routes
|
|
170
|
+
|
|
171
|
+
If the application has some routes that should be reachable without an authenticated session (e.g. a
|
|
172
|
+
public catalog or a download endpoint polled by CI), list them under `publicProxyTargets`:
|
|
173
|
+
|
|
174
|
+
```json
|
|
175
|
+
{
|
|
176
|
+
"proxyTargets": {
|
|
177
|
+
"/api": "http://localhost:8080/api"
|
|
178
|
+
},
|
|
179
|
+
"publicProxyTargets": {
|
|
180
|
+
"/api/public": "http://localhost:8080/api/public",
|
|
181
|
+
"/export.zip": "http://localhost:8080/export.zip"
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Public targets are proxied through anonymously — no session lookup, no Authorization header. The
|
|
187
|
+
session cookie is stripped on the way through.
|
|
188
|
+
|
|
189
|
+
Public targets are registered before protected ones, so overlapping paths resolve to the public
|
|
190
|
+
mapping (e.g. `publicProxyTargets["/api/public"]` wins over `proxyTargets["/api"]`).
|
|
191
|
+
|
|
167
192
|
## Using with ID-porten (via `okdata`):
|
|
168
193
|
|
|
169
194
|
`auth-bff` Has special support for keys generated by [`okdata`](https://github.com/oslokommune/okdata-cli).
|
package/dist/package.json
CHANGED
package/dist/src/config.d.ts
CHANGED
|
@@ -101,6 +101,16 @@ export type BffConfig = {
|
|
|
101
101
|
proxyTargets: {
|
|
102
102
|
[path: string]: string;
|
|
103
103
|
};
|
|
104
|
+
/**
|
|
105
|
+
* Like `proxyTargets`, but requests pass through anonymously — no session lookup, no Authorization
|
|
106
|
+
* header. Registered before `proxyTargets`, so a public path takes precedence over an overlapping
|
|
107
|
+
* protected one.
|
|
108
|
+
*
|
|
109
|
+
* Example: `{'/api/public': 'http://example.com/api/public'}`
|
|
110
|
+
*/
|
|
111
|
+
publicProxyTargets?: {
|
|
112
|
+
[path: string]: string;
|
|
113
|
+
};
|
|
104
114
|
/**
|
|
105
115
|
* List of claims in the id_token that are returned by the /user-endpoint. By default all are returned
|
|
106
116
|
*
|
package/dist/src/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,aAAa,EAAC,MAAM,QAAQ,CAAC;AACrC,OAAO,OAAO,MAAM,iBAAiB,CAAC;AAEtC,MAAM,MAAM,SAAS,GAAG;IACtB;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB;;;;OAIG;IACH,MAAM,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IACh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AM,GAAG,MAAM,CAAA;KAAE,CAAA;IACxC;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAA;IAC/C;;;;OAIG;IACH,UAAU,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IAC1B;;;;;;;;;;;;;;;;OAgBG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,uBAAuB,CAAC,EAAE,OAAO,CAAC,CAAA;CACjF,CAAA;AAWD,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,UAQzF;AAID,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,cAAc,GAAE,OAAc,mBAMjF;AAID,wBAAsB,UAAU,CAAC,UAAU,GAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAqB,sBAyBtF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy-routes.d.ts","sourceRoot":"","sources":["../../../src/middleware/proxy-routes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AACvC,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAC;AAEnD,wBAAgB,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,cAAc,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"proxy-routes.d.ts","sourceRoot":"","sources":["../../../src/middleware/proxy-routes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AACvC,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAC;AAEnD,wBAAgB,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,cAAc,EAAE,cAAc,8CAoD5E"}
|
|
@@ -2,6 +2,23 @@ import express from "express";
|
|
|
2
2
|
import { createProxyMiddleware } from "http-proxy-middleware";
|
|
3
3
|
export function proxyRoutes(config, oidcMiddleware) {
|
|
4
4
|
const router = express.Router();
|
|
5
|
+
// Public targets first so they win over overlapping protected paths.
|
|
6
|
+
for (const [path, target] of Object.entries(config.publicProxyTargets ?? {})) {
|
|
7
|
+
console.log(`Setting up public proxy: ${path} -> ${target}`);
|
|
8
|
+
router.use(path, createProxyMiddleware({
|
|
9
|
+
target: target,
|
|
10
|
+
changeOrigin: true,
|
|
11
|
+
on: {
|
|
12
|
+
proxyReq: (proxyReq) => {
|
|
13
|
+
proxyReq.removeHeader("Cookie");
|
|
14
|
+
},
|
|
15
|
+
proxyRes: (proxyRes, req) => {
|
|
16
|
+
// @ts-ignore //TODO: proxyRes har en mystisk type som mangler req, men den er der
|
|
17
|
+
console.log(`Proxied (public): ${req.method} ${req.originalUrl} -> ${proxyRes.req.protocol}//${proxyRes.req.host}${proxyRes.req.path}, status=${proxyRes.statusCode}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
5
22
|
for (const [path, target] of Object.entries(config.proxyTargets)) {
|
|
6
23
|
console.log(`Setting up auth proxy: ${path} -> ${target}`);
|
|
7
24
|
router.use(path, oidcMiddleware.ensureFreshToken, createProxyMiddleware({
|