Package: datasette-auth-passwords
datasette-auth-passwordsDatasette plugin for authenticating access using passwordsInstallationInstall this plugin in the same environment as Datasette.$ datasette install datasette-auth-passwordsDemoA demo of this plugin is running athttps://datasette-auth-passwords-demo.datasette.io/The demo is configured to show thepublic.dbdatabase to everyone, but theprivate.dbdatabase only to logged in users.You can log in athttps://datasette-auth-passwords-demo.datasette.io/-/loginwith usernamerootand passwordpassword!.UsageThis plugin works based on a list of username/password accounts that are hard-coded into the plugin configuration.First, you'll need to create a password hash. There are three ways to do that:Install the plugin, then use the interactive tool located at/-/password-toolUse the hosted version of that tool athttps://datasette-auth-passwords-demo.datasette.io/-/password-toolUse thedatasette hash-passwordcommand, described belowNow add the following to yourmetadata.json:{"plugins":{"datasette-auth-passwords":{"someusername_password_hash":{"$env":"PASSWORD_HASH_1"}}}}The password hash can now be specified in an environment variable when you run Datasette. You can do that like so:PASSWORD_HASH_1='pbkdf2_sha256$...' \
    datasette -m metadata.jsonBe sure to use single quotes here otherwise the$symbols in the password hash may be incorrectly interpreted by your shell.You will now be able to log in to your instance using the form at/-/loginwithsomeusernameas the username and the password that you used to create your hash as the password.You can include as many accounts as you like in the configuration, each with different usernames.datasette hash-passwordThe plugin exposes a new CLI command,datasette hash-password. You can run this without arguments to interactively create a new password hash:% datasette hash-password
Password: 
Repeat for confirmation: 
pbkdf2_sha256$260000$1513...Or if you want to use it as part of a script, you can add the--no-confirmoption to generate a hash directly from a value passed to standard input:% echo 'my password' | datasette hash-password --no-confirm
pbkdf2_sha256$260000$daa...Specifying actorsBy default, a logged in user will result in anactor blockthat just contains their username:{"id":"someusername"}You can customize the actor that will be used for a username by including an"actors"configuration block, like this:{"plugins":{"datasette-auth-passwords":{"someusername_password_hash":{"$env":"PASSWORD_HASH_1"},"actors":{"someusername":{"id":"someusername","name":"Some user"}}}}}HTTP Basic authentication optionThis plugin defaults to implementing login using an HTML form that sets a signed authentication cookie.You can alternatively configure it to useHTTP Basic authenticationinstead.Do this by adding"http_basic_auth": trueto thedatasette-auth-passwordsblock in your plugin configuration.This option introduces the following behaviour:Account usernames and passwords are configured in the same way as form-based authenticationEvery page within Datasette - even pages that normally do not use authentication, such as static assets - will display a browser login promptUsers will be unable to log out without closing their browser entirelyThere is a demo of this mode athttps://datasette-auth-passwords-http-basic-demo.datasette.io/- sign in with usernamerootand passwordpassword!Using with datasette publishIf you are publishing data using adatasette publishcommand you can use the--plugin-secretoption to securely configure your password hashes (seesecret configuration values).You would run the command something like this:datasette publish cloudrun mydatabase.db \
    --install datasette-auth-passwords \
    --plugin-secret datasette-auth-passwords root_password_hash 'pbkdf2_sha256$...' \
    --service datasette-auth-passwords-demoThis will allow you to log in as usernamerootusing the password that you used to create the hash.DevelopmentTo set up this plugin locally, first checkout the code. Then create a new virtual environment:cd datasette-auth-passwords
python3 -mvenv venv
source venv/bin/activateOr if you are usingpipenv:pipenv shellNow install the dependencies and tests:pip install -e '.[test]'To run the tests:pytest