possible to use header to set username ?
Opened this issue · 2 comments
I would like to use a header from nginx proxy to set the $:/status/UserName
.
I have nginx setup like this:
upstream websocket {
server tiddlywiki:8080;
}
server {
listen 80;
listen [::]:80;
server_name localhost;
location / {
auth_basic "Login";
auth_basic_user_file /etc/nginx/.htpasswd;
proxy_pass http://websocket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
proxy_set_header X-BasicAuth-RemoteUser $remote_user;
}
}
Importantly these lines:
auth_basic "Login";
auth_basic_user_file /etc/nginx/.htpasswd;
proxy_set_header X-BasicAuth-RemoteUser $remote_user;
I tried like to run node tiddlywiki with the authenticated-user-header
option, as described here:
https://tiddlywiki.com/static/WebServer%2520Parameter%253A%2520authenticated-user-header.html
Something like this:
node tiddlywiki --wsserver authenticated-user-header=X-RemoteUser
But that doesn't seem to do anything.
I'm looking for advise on if this is possible, if so then I would also be grateful for a gentle push in the right direction.
I am running:
- Windows
- [ x] OSX
- Linux
- Other
and using
- [ x] The nodejs version
- The single file executable
Before posting I read issue guidelines and:
- [ x] I am using the newest version
- [ x] The answer to my question isn't listed in the documentation or this isn't
a question - [ x] This is not a duplicate issue
- [ x] I have not done anything that required me to set acceptance to
I Will Not Get Tech Support For This
I added something like this in ws-server.js
, and I can get the header value. How can I write it to a tiddler?
if(request.headers['X-BasicAuth-RemoteUser']) {
console.log("set state.authenticatedUsername to "+request.headers[request.headers['X-BasicAuth-RemoteUser']]);
// what can i do here to write to the tiddler ? - this doesn't work...
self.wiki.addTiddler({
title: "$:/status/UserName",
text: request.headers[header]});
//state.authenticatedUsername = request.headers[header];
}
I got it working with a change to get-status.js
:
...
exports.handler = function(request,response,state) {
...
const header = 'X-BasicAuth-RemoteUser'.toLowerCase();
const username = header && request.headers[header] ? request.headers[header] : '';
const status = {
...
username: username,
...
}
...
}
}());
and to BrowserWSAdaptor.js
...
$tw.wiki.addTiddler(new $tw.Tiddler({title:'$:/status/IsLoggedIn', text:data.logged_in}));
$tw.wiki.addTiddler(new $tw.Tiddler({title:'$:/status/UserName', text:data.username})); // add this
...