Popularity
0.8
Growing
Activity
5.2
Declining
19
3
1

Description

Use the Kno service for passwordless authentication, it handles sending emails so you don't have too. It also allows users to set up device based authentication so they don't have to wait for any email, after the first.

Monthly Downloads: 110
Programming language: Ruby
License: Apache License 2.0
Tags: Authorization     Security     Web Frameworks     Rack     Rails     Authentication    

Kno Ruby alternatives and similar gems

Based on the "Authorization" category

Do you think we are missing an alternative of Kno Ruby or a related project?

Add another 'Authorization' Gem

README

Kno Ruby

Gem Version

Go Passwordless with trykno.com

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

Installation

Add kno as a dependency in your Gemfile:

gem 'kno'

Then, install it using bundler:

$ bundle install

Usage

This library integrates Kno into any Rack-based application, including Rails, Hanami and Sinatra.

<!-- - Rails

Rails integration

<!-- See [MyRailsApp](examples/my_rails_app) -->

Configure middleware

Add Kno::Session to the middleware stack, by configuring it in /my_app/config/application.rb

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.

persona_id = request.env['kno'].persona_id

With Kno, users are uniquely identified by their persona_id. If the request is unauthenticated, then the value will be nil.

Local development

Authentication is now setup for local development. Run locally and click the sign in button and you should see a sign in modal.

[Local development screenshot](assets/images/screenshot.png)

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 site_token and api_token. 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.

Contributing

Contributions are very welcome. Please do open an issue or pull request or reach out to us at team@trykno.com

Docker

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