{"id":22876291,"url":"https://github.com/legalforce-oss/hanami-authentication","last_synced_at":"2026-05-16T21:01:43.155Z","repository":{"id":56875770,"uuid":"105508623","full_name":"legalforce-oss/hanami-authentication","owner":"legalforce-oss","description":null,"archived":false,"fork":false,"pushed_at":"2017-11-24T09:23:09.000Z","size":29,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-14T19:46:33.984Z","etag":null,"topics":["authentication","gem","hanami","ruby"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/legalforce-oss.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-02T07:32:11.000Z","updated_at":"2021-03-25T10:51:37.000Z","dependencies_parsed_at":"2022-08-20T22:00:38.620Z","dependency_job_id":null,"html_url":"https://github.com/legalforce-oss/hanami-authentication","commit_stats":null,"previous_names":["legalforce/hanami-authentication"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/legalforce-oss/hanami-authentication","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/legalforce-oss%2Fhanami-authentication","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/legalforce-oss%2Fhanami-authentication/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/legalforce-oss%2Fhanami-authentication/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/legalforce-oss%2Fhanami-authentication/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/legalforce-oss","download_url":"https://codeload.github.com/legalforce-oss/hanami-authentication/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/legalforce-oss%2Fhanami-authentication/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265105781,"owners_count":23712209,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","gem","hanami","ruby"],"created_at":"2024-12-13T15:13:55.957Z","updated_at":"2026-05-16T21:01:43.053Z","avatar_url":"https://github.com/legalforce-oss.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hanami::Authentication\n[![Gem Version](https://badge.fury.io/rb/hanami-authentication.svg)](https://badge.fury.io/rb/hanami-authentication)\n![](http://ruby-gem-downloads-badge.herokuapp.com/hanami-authentication?type=total)\n\n\n`Hanami::Authentication` is simple authentication helpers for [hanami-controller](https://github.com/hanami/controller)\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'hanami-authentication'\n```\n\n## Usage\n\n### Setup\n```ruby\n# application.rb\ncontroller.prepare do\n  include Hanami::Authentication\n\n  before authenticate  # This will use callbacks if authentication is failed.  \n  before authenticate! # This will force to halt by 401 if authentication is failed.\n  \n  after_session_expired do # This will be called if authenticate method is called when session is expired.\n    flash[:error] = 'The session is expired.'\n    redirect_to routes.root_path\n  end\n\n  after_authentication_failed do # This will be called if authenticate method is called when user has not logged in.\n    flash[:error] = 'Please login'\n    redirect_to routes.root_path\n  end\nend\n```\n\n\n### Methods\n\n#### Login example\n```ruby\n# in_your_login_action.rb\ndef call(params)\n  email = params[:email]\n  password = params[:password]\n  remember_me = params[:remember_me]\n\n  @current_user = @repository.find_by_email(email)\n\n  if match_password?(@current_user, password)\n    login(@current_user, remember_me: remember_me)\n    flash[:success] = 'Successful logged in'\n    redirect_to routes.root_path\n  else\n    flash[:error] = 'Email or password is incorrect'\n    redirect_to routes.root_path\n  end\nend\n```\n\n#### Logout example\n```ruby\n# in_your_login_action.rb\ndef call(params)\n  logout\nend\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/legalforce/hanami-auth. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Hanami::Auth project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/unhappychoice/hanami-authentication/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flegalforce-oss%2Fhanami-authentication","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flegalforce-oss%2Fhanami-authentication","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flegalforce-oss%2Fhanami-authentication/lists"}