HanamiId

Authentication solution for Hanami framework. Based on Warden and Bcrypt.

HanamiId tries to be a plug-n-play solution like Devise is for Rails. But instead of magic intervention, it generates a separate app with controllers, views, templates full of working code that you can easily change to your liking.
HanamiId doesn't monkey patch anything, doesn't mess with your app configuration and acts completely isolated.

Status

Build Status Gem Known Vulnerabilities Depfu Codacy Badge License: MIT Test Coverage Maintainability

Installation

Add this lines to your application's Gemfile:

gem "hanami_id"

group :plugins do
  gem "hanami_id-generators"
end

And then execute:

$ bundle

Run generator:

$ hanami g auth --app auth --model user

Use --help to see all available options and defaults. They are:

  • --modules
  • --id_type
  • --login_column
  • --password_column

The above command is using Hanami CLI under the hood and will generate an application with all controller actions, entity, repository and all relevant specs (RSpec).

Usage

For project-wide usage add Warden Rack middleware to your project:

# config/environment.rb
Hanami.configure do
  # ...
  use Rack::Session::Cookie, secret: "replace this with some secret key"
  include HanamiId::Warden::AppHelper
end

For usage in a specific app add Warden Rack middleware to that particular app:

# apps/web/application.rb
module Web
  class Application < Hanami::Application
    configure do
      # ...
      sessions :cookie, secret: ENV["WEB_SESSIONS_SECRET"]
      include HanamiId::Warden::AppHelper
    end
  end
end

For usage in single controller action add Warden Rack middleware to that action:

# apps/web/controllers/dashboard/show.rb
module Web
  module Controllers
    module Dashboard
      class Show
        include Web::Action
        include HanamiId::Warden::ActionHelper

        def call(params)
          # ...
        end
      end
    end
  end
end

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/leemour/hanami_id. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

Code of Conduct

Everyone interacting in the HanamiId project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.