Use the Kno service for passwordless authentication, it handles sending emails so you don't have to. It also allows users to set up device-based authentication so they don't have to wait for any email (after the first).
kno as a dependency in your
Then, install it using bundler:
$ bundle install
This library integrates Kno into any Rack-based application, including Rails, Hanami and Sinatra.
Kno::Session to the middleware stack, by configuring it in
module MyApp class Application < Rails::Application # ... config.load_defaults 6.0 config.middleware.use Kno::Session, sign_in_redirect: "/" end end
Make sure to add
Kno::Session after the default middleware as it requires the session middleware to be applied.
Add sign in/out button
Use the helpers that Kno added to the request to show the correct sign in, or sign out, button.
<%= request.env['kno'].session_button().html_safe %>
Check the user is authenticated
Controllers can check if a user is authenticated by looking up their
persona_id = request.env['kno'].persona_id
With Kno, users are uniquely identified by their
If the request is unauthenticated, then the value will be nil.
Authentication is now setup for local development. Run locally and click the sign in button and you should see a sign in modal.
Enter your real email address. Kno runs a service for local development that sends a limited number of emails.
Get production keys
To use Kno in production you will need site and API tokens for your application.
Create an account at trykno.com and follow the guidance to create your first space.
This will direct you to create a
Add these to your environment and edit the middleware configuration.
config.middleware.use Kno::Session, sign_in_redirect: "/" site_token: ENV["KNO_SITE_TOKEN"], api_token: ENV["KNO_API_TOKEN"]
NOTE: The tokens do not have to be stored in the environment. However the api token MUST be kept secure and should not be committed to your applications source code.
Contributions are very welcome. Please do open an issue or pull request or reach out to us at email@example.com
If you do not have node installed, you can run locally in Docker with the following command.
docker run \ -it \ --rm \ -w="/opt/app" \ -v="$(pwd):/opt/app" \ --env="PORT=3000" \ -p="3000:3000" \ --network="host" \ ruby:2.7.0 bash
NOTE: You will need to bundle install every time you start a container with this command