{"id":13563449,"url":"https://github.com/tomas/entrance","last_synced_at":"2025-03-22T09:31:55.998Z","repository":{"id":17132830,"uuid":"19899197","full_name":"tomas/entrance","owner":"tomas","description":"Lean, non-intrusive authentication for Rails and Sinatra, with out-of-the-box support for OAuth2.","archived":false,"fork":false,"pushed_at":"2021-03-21T02:46:45.000Z","size":112,"stargazers_count":14,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-04-27T05:40:36.058Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tomas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-05-18T00:09:49.000Z","updated_at":"2024-02-28T10:41:33.000Z","dependencies_parsed_at":"2022-07-26T12:32:12.859Z","dependency_job_id":null,"html_url":"https://github.com/tomas/entrance","commit_stats":null,"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomas%2Fentrance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomas%2Fentrance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomas%2Fentrance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomas%2Fentrance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomas","download_url":"https://codeload.github.com/tomas/entrance/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244937751,"owners_count":20535124,"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":[],"created_at":"2024-08-01T13:01:19.407Z","updated_at":"2025-03-22T09:31:55.569Z","avatar_url":"https://github.com/tomas.png","language":"Ruby","funding_links":[],"categories":["Display manager","Ruby"],"sub_categories":["Graphic"],"readme":"Entrance\n========\n\nClean, adaptable authentication library for Rails and Sinatra.\n\n    $ gem install entrance\n\n# Usage\n\n``` rb\n# in an intializer, e.g. config/initializers/entrance.rb\n\nrequire 'entrance'\n\nEntrance.configure do |config|\n  config.access_denied_redirect_to = '/login'\n  config.remember_for              = 1.month\n  config.reset_password_window     = 2.hours\n  config.cookie_secure             = Rails.env.production?\nend\n\n# in your controller\n\nclass ApplicationController \u003c ActionController::Base\n  include Entrance::Controller\n\n  before_filter :login_required # provided by Entrance::Controller\n\n  ...\nend\n\n# in your model\n\nclass User\n  include Entrance::Model\n\n  ... (setup fields)\n  \n  provides_entrance do |fields|\n    fields.username = :email\n    fields.password = :password\n  end\nend\n```\n\nNow, you're ready to roll.\n\n``` rb\nclass SessionsController \u003c ApplicationController\n\n  skip_before_filter :login_required\n  \n  def new\n    # render login form\n  end\n\n  def create\n    if user = authenticate_and_login(params[:email], params[:password], params[:remember_me] == 'on')\n      redirect_to '/app'\n    else\n      redirect_to '/login', :notice =\u003e \"Invalid credentials.\"\n    end\n  end\n\nend\n```\n\nIf you need more control, -- like checking a users state before letting him in -- you can call directly the model's `.authenticate` method, and then call the `login!` method once you're ready.\n\n``` rb\n  def create\n    if user = User.authenticate(params[:email], params[:password]) and user.active?\n      login!(user, params[:remember_me] == '1')\n      redirect_to '/app'\n    else\n      redirect_to '/login', :notice =\u003e \"Invalid credentials.\"\n    end\n  end\n```\n\nAs you can see, Entrance comes with out-of-box support for the \"remember me\" option. It also supports the usual 'reset password' token/email logic, but that's it. That's as far as Entrance goes -- we want to keep things simple and lean.\n\n## Entrance::Config\n\nAll available options, along with their defaults.\n\n``` rb\nEntrance.configure do |config|\n  # strategies\n  config.cipher                     = Entrance::Ciphers::BCrypt # can also be Entrance::Ciphers::SHA1\n  config.secret                     = nil\n  config.stretches                  = 10\n\n  # access denied\n  config.access_denied_redirect_to  = '/login'\n  config.access_denied_message_key  = nil # e.g. 'messages.access_denied'\n\n  # reset password\n  config.reset_password_mailer      = 'UserMailer'\n  config.reset_password_method      = 'reset_password_request'\n  config.reset_password_window      = 60 * 60 # 1.hour\n\n  # remember me \u0026 cookies\n  config.remember_for               = 60 * 24 * 14 # 2.weeks\n  config.cookie_domain              = nil\n  config.cookie_secure              = true\n  config.cookie_path                = '/'\n  config.cookie_httponly            = false\nend\n```\n\n## Entrance::Fields\n\nAs declared in your model. Options and their defaults are:\n\n``` rb\nprovides_entrance do |fields|\n  # base\n  fields.unique_key      = 'id' \n  fields.salt            = nil # only required for SHA1 strategy\n\n  # username \u0026 password\n  fields.name            = 'name' # only used by omniauth addon\n  fields.username        = 'email'\n  fields.password        = 'password_hash'\n\n  # remember and reset\n  fields.remember_token  = 'remember_token'\n  fields.remember_until  = 'remember_token_expires_at'\n  fields.reset_token     = 'reset_token'\n  fields.reset_until     = 'reset_token_expires_at'\n\n  # omniauth\n  fields.auth_provider   = 'auth_provider'\n  fields.auth_uid        = 'auth_uid'\nend\n```\n\n## Entrance::Controller\n\nWhen including it into your controller, this module will provide the following methods:\n  \n - authenticate_and_login(username, password, remember_me = false)\n - login!(user, remember_me = false)\n - logout!\n\nAnd the following helpers: \n\n - current_user \n - login_required\n - logged_in?\n - logged_out?\n  \n## Entrance::Model\n\nProvides:\n\n - .provides_entrance(\u0026block)\n - .authenticate(username, password)\n - .with_password_reset_token(token)\n - #password and #password=(value)\n - #remember_me! and #forget_me!  (unless remember_attr is set to nil)\n - #request_password_reset! (unless reset_attr is set to nil)\n\nExamples\n========\n\nThought you might ask. There's a full example Rails app and a Sinatra app in the examples folder. Check them out. \n \nAuthor\n======\n\nWritten by Tomás Pollak.\n\nCopyright\n=========\n\n(c) Fork, Ltd. MIT Licensed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomas%2Fentrance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomas%2Fentrance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomas%2Fentrance/lists"}