Arlen22 / TiddlyServer

v2 - A static file server that can also save files and mount TiddlyWiki folders
https://arlen22.github.io/tiddlyserver/
MIT License
256 stars 36 forks source link

Login/Password issues TiddlyServer v2.2.0-beta-2 #107

Open primetimber opened 3 years ago

primetimber commented 3 years ago

I am having trouble getting into the tiddlywiki. I followed "Getting Started". Everything looks good, but I am having trouble finding out, where to set login and password. settings.json looks like this:

{
    "tree": "./wikidata",
    "bindInfo": {
    "bindWildcard": true
    },

    "authAccounts": {},

    "putsaver": {
    "backupFolder": "./backups"
    },

    "$schema": "./tiddlyserver-2-2.schema.json"
}
Arlen22 commented 3 years ago

Go to /admin/authenticate/login.html and type in your desired username and password. This will print a message to the server console containing the public key and username.

    login attempted with unknown public key
    <base64 encoded string>
    username: test
    timestamp: 2020-12-30T19:59:16.580Z

Run the command node -e "console.log(Date.now())" to get the current timestamp for the cookie suffix. This just makes sure you don't accidentally re-use the same suffix for the same user. The suffix is used to force a user to be logged out of all sessions.

Now add a new key to the authAccounts object.

  "authAccounts": {
    "group name": { // << this is the "group" name such as "admin" or whatever you want
      "clientKeys": {
        "test": { // << this is the username you typed into the login form
          "cookieSalt": "timestamp from command",
          "publicKey": "<base64 encoded string>"
        }
      },
      "permissions": {
        "loginlink": true,
        "mkdir": true,
        "putsaver": true,
        "registerNotice": true,
        "upload": true,
        "websockets": true,
        "writeErrors": true,
        "transfer": true,
        "datafolder": true
      }
    }
  },

After this, modify your tree option to look like this

"tree": {
  "$element": "group",
  "$options": [
    // the auth list array specifies which authAccounts groups are allowed to access this resource. 
    { "$element": "auth", "authList": ["group name"]}, 
  ],
  "$children": // << your original tree value goes here
}

And then login again.

Sorry it looks so messy. The tree is so much nicer in XML.

<!-- the authList property is a JSON array -->
<tree>
  <!-- this protects the entire tree -->
  <auth authList='["group name"]' />  
  <folder path="/user/hello">
    <!-- Allows an additional group. Both groups must be included here. -->
    <auth authList='["group name", "other group]' /> 
  </folder>
  <group>
    <!-- obviously unnecessary, only here for demonstration -->
    <auth authList='["group name"]' /> 
    <folder path="/user/hello">
      <!-- this allows anyone to access this resource -->
      <auth authList='null' />
    </folder>
  </group>
</tree>

And then you just set the path to the XML as your tree option.

Arlen22 commented 3 years ago

I was looking over this code and I just realized instead of a JSON attribute, you can also do this.


<auth>
  <authList>group name</authList>
  <authList>other group</authlist>
</auth> 
primetimber commented 3 years ago

thank you. now I have a better understanding. I found my other mistake. I forgot, that there is a difference between installing the tiddlywiki itself and the tiddlyserver m( One of the pull requests (#84) describes it in a way.