Add authentication in the proxy #7461
Answered
by
chriswk
liamskydamien
asked this question in
Q&A
-
Hello, Is something like this possible? |
Beta Was this translation helpful? Give feedback.
Answered by
chriswk
Jun 27, 2024
Replies: 1 comment 1 reply
-
Hi, the proxy app allows you to add a preHook to your config when you start it up. So something like const jwt = require('jsonwebtoken');
const proxy = require('unleash-proxy');
const getCustomData = require('./myContextBuilder'); // This you have to write yourself.
const config = proxy.createProxyConfig({
preHook: (app) => {
app.use('/', (req, res, next) => {
// extract token from req
// validate
// populate req query with extra parameters to use in context enricher
req.query.jwtValidated = true
});
},
expContextEnricher: [(context) => {
if (context.parameters.jwtValidated === true) {
context.myCustomContext = getCustomData()
}}]
});
const myApp = proxy.createApp(config);
myApp.start(); Should work. Though the above example probably won't build it should give you pointers to what you'll need to add. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
ivarconr
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, the proxy app allows you to add a preHook to your config when you start it up. So something like