Skip to content

Add authentication in the proxy #7461

Answered by chriswk
liamskydamien asked this question in Q&A
Discussion options

You must be logged in to vote

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(

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@liamskydamien
Comment options

Answer selected by ivarconr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants