Easy authentication for Hanami
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
lib/hanami
test
.gitignore
.travis.yml
CODE_OF_CONDUCT.md
Gemfile
LICENSE.txt
README.md
Rakefile
hanami-mimoto.gemspec

README.md

(This is an implementation proposal)

Hanami Mimoto

Easy authentication for Hanami

Mimoto uses Warden gem as it's base.

Installation

In the Gemfile:

gem 'hanami-mimoto'

Then run:

bundle install

Install Mimoto within your project

hanami g mimoto:install <app> <entity> # e.g. hanami g mimoto:install web user

If the app exists it will add the following files:

    apps
    └── web
        ├── application.rb
        ├── assets
        │   ├── favicon.ico
        │   ├── images
        │   ├── javascripts
        │   └── stylesheets
        ├── config
        │   └── routes.rb
        ├── controllers
        │   ├── **registrations**
        │   │   ├── create.rb
        │   │   ├── destroy.rb
        │   │   ├── edit.rb
        │   │   ├── new.rb
        │   │   └── update.rb
        │   └── **sessions**
        │       ├── create.rb
        │       ├── destroy.rb
        │       └── new.rb
        ├── templates
        │   ├── application.html.erb
        │   ├── **registrations**
        │   │   ├── create.html.erb
        │   │   ├── destroy.html.erb
        │   │   ├── edit.html.erb
        │   │   └── update.html.erb
        │   └── **sessions**
        │       ├── create.html.erb
        │       ├── destroy.html.erb
        │       └── new.html.erb
        └── views
            ├── application_layout.rb
            ├── **registrations**
            │   ├── create.rb
            │   ├── destroy.rb
            │   ├── edit.rb
            │   └── update.rb
            └── **sessions**
                ├── create.rb
                ├── destroy.rb
                └── new.rb

And it would edit the following files:

bookshelf/apps/web/application.rb

  require 'hanami/helpers'
  require 'hanami/assets'
  
  module Web
    class Application < Hanami::Application
      include Hanami::Mimoto[scope: :user, strategies: :password] # added

      configure do
      ...

This will:

  • configure middleware
  • include Hanami::Mimoto::Controller in controller.prep block, so it sets current_user object (it may be current_admin, etc. depending on what is passed in to include Hanami::Mimoto[scope: ...] )

bookshelf/lib/bookshelf/repositories/user_repository.rb (it would be only edited if existed, otherwise it will be created)

  class UserRepository < Hanami::Repository
    include Hanami::Mimoto::Model[strategies: :password]
    ...
  end

This will:

  • add methods that are required to perform authenticatation by specified action (some convention here to get going, e.g. accessors to password fields, etc.)

bookshelf/apps/web/config/routes.rb

...
Hanami::Mimoto::Routes[scope: :user, strategies: :password].(self)
...

This will:

  • add routes to handle user scope sessions/registrations (think warden scope)

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test 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/[USERNAME]/hanami-mimoto. 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.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

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