Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

possible to use header to set username ? #195

Open
4 tasks
cornernote opened this issue Jan 14, 2023 · 2 comments
Open
4 tasks

possible to use header to set username ? #195

cornernote opened this issue Jan 14, 2023 · 2 comments

Comments

@cornernote
Copy link

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
@cornernote
Copy link
Author

cornernote commented Jan 14, 2023

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];
            }

@cornernote
Copy link
Author

cornernote commented Jan 15, 2023

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
      ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant