Commit c44c99c2 authored by Matija Obreza's avatar Matija Obreza
Browse files

/proxy uses access_token from cookies if Authorization header is missing

- This allows us to proxy file download requests
parent 7949b4cc
......@@ -66,6 +66,18 @@ module.exports = {
} else if (p.indexOf('/google/verify-token') === 0) {
p = `${p}&clientId=${CLIENT_ID}`;
}
// If authorization header is not provided, use access_token from cookie
// console.log('Cookies', req.headers.cookie, req);
if (! req.headers.authorization && req.headers.cookie) {
const authorization = req.headers.cookie.match(/access_token=([^;]+)/);
// console.log('Cookies', req.headers.cookie, authorization);
if (authorization.length === 2) {
console.log('Injecting Authorization header from cookies');
req.headers.authorization = 'Bearer ' + authorization[1];
}
}
return p;
},
onError(err, req, res) {
......
......@@ -6,11 +6,26 @@ const httpProxy = proxy(config.apiUrl, {
timeout: config.apiTimeout,
filter: (req, res) => {
if (req.url.startsWith('/oauth/')) {
// console.log('Will proxy /oauth');
return true;
}
if (req.url.startsWith('/api')) {
console.log(req.headers.authorization);
// If authorization header is not provided, use access_token from cookie
if (!req.headers.authorization && req.headers.cookie) {
const authorization = req.headers.cookie.match(/access_token=([^;]+)/);
// console.log('Cookies', req.headers.cookie, authorization);
if (authorization.length === 2) {
console.log('Injecting Authorization header from cookies');
req.headers.authorization = 'Bearer ' + authorization[1];
}
}
// console.log(`Will HTTP Proxy filter? ${typeof req.headers.authorization !== 'undefined'}`);
return typeof req.headers.authorization !== 'undefined';
}
return true;
// Not proxying the request
return false;
},
proxyReqPathResolver: (req) => {
......@@ -23,6 +38,7 @@ const httpProxy = proxy(config.apiUrl, {
} else if (path.startsWith('/google/verify-token')) {
path = `${path}&clientId=${config.clientId}`;
}
console.log(`HTTP proxy to ${config.apiUrl}${path}`);
return path;
},
......
......@@ -276,9 +276,9 @@ class DetailInfo extends React.Component<IDetailInfoProps, any> {
</Typography>
</Hidden>
<Hidden mdDown>
<Button raised component="span" className={ `${classes.buttonGreen} ${classes.button}` }>
<a href={ `/proxy/api/v0/repository/download/${e.uuid}` }><Button raised component="span" className={ `${classes.buttonGreen} ${classes.button}` }>
Download XLS
</Button>
</Button></a>
</Hidden>
<Hidden lgUp>
<Button raised component="span" className={ `${classes.buttonGreen} ${classes.button}` }>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment