GithubHelp home page GithubHelp logo

registrar's Introduction

Registrar

Authentication for internal tools using Gmail OAuth.

Outsource the responsibility of managing user access to Gmail. Instead of re-writing the same simple authentication, only allow users on your Gmail domain access to your internal tool.

Let Gmail be your active user directory. With Registrar in place, anytime someone is given an account on your Gmail domain they will automatically have access. This also removes the worry of deactivating a user in all the right places - just remove them from Gmail and their access is revoked.

Installation

Registrar is a Rails Engine. To get started, simply add it your Gemfile and run bundle install

git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "registrar", github: "procore/registrar"

Registrar comes with a handy install script. Run the installer with

rails generate registrar:install

This will do several things:

  • Create a user model and table (if they do not already exist).
  • Create an initializer
  • Inject the sessions helper and current_user method into ApplicationController
  • Mount the engine in your routes file

Configure

Registrar also needs to have several options configured before it can run properly.

Registrar.configure do |config|
  # Required
  config.google_client_id = ENV.fetch("GOOGLE_CLIENT_ID")
  config.google_client_secret = ENV.fetch("GOOGLE_CLIENT_SECRET")
  config.domain = "example.com"

  # Optional
  config.whitelist += %W(person@other_domain.com)
  config.signin_url = "/signin"
  config.signout_url = "/signout"
  config.after_signin_url = "/"
  config.after_signout_url = "/signout"
  config.with_user_cookie = true
  config.redirect_uri = "https://mydomain.com/oauth/consume"
  config.session_key = :user_email
  config.session_manager_class = MySessionManager
end
  • You can get the google_client_id and google_client_secret from here.
  • The domain option specifies the domain to restrict users to. In the example above, only users with an example.com email address will be allowed through.
  • The whitelist option is intended allow specific users from other domains access to this application.
  • The with_user_cookie option should be used when you need cookies[:user_id] to be set during your normal sessions flow.
  • The redirect_uri option should only be used if you don't want to use the default of <domain initiated from>/auth/google/callback

Usage

For authorization you will have an require_signed_in_user method available to you in your controllers. To require that a user be logged in before viewing a particular page you can do the following in your controller

before_action :require_signed_in_user

Available Routes:

registrar.signin_path
registrar.signout_path

Helper Methods

  • current_user - The currently signed in user
  • signed_in? - Returns true or false depending if the user is signed in.

Overwriting Views

Registrar ships with very, very basic pages. To overwrite the layout create a layout file in app/views/layouts/registrar.html.erb.

Overwrite the sign in page by creating a file in app/views/registrar/sessions/new.html.erb.

Somewhere on the page you will need the link to authenticate:

<%= link_to "/auth/google", "/auth/google" %>

Custom Session Identifiers

If you don't want the default of user.id to be used as your session identifier, then you can use the session_manager_class setting to provide your own class for session management.

# config/initializers/registrar.rb

Registrar.configure do |config|
  config.session_manager_class = MySessionManager
end

Your session manager class has to define two methods, self.session_id and self.find_by_session_id. The former is used to determine what to set in the session upon successful login, and the latter determines how you look up a user with that identifier.

# app/services/my_session_manager.rb

class MySessionManager
  class << self
    def session_id(user)
      user.email
    end

    def find_by_session_id(session_id)
      ::User.find_by(email: session_id)
    end
  end
end

Local development

Testing

  1. run bundle in the root dir
  2. cp spec/test_app/config/database.yml.sample to spec/test_app/config/database.yml and edit for your setup
  3. export RAILS_ENV=test
  4. cd spec/test_app
  5. `rake db:create
  6. cd ../..
  7. rake db:setup db:migrate

You can now run rspec in the root directory.

Licence

Registrar is copyright © 2018 Procore. It is free software, and may be redistributed under the terms specified in the LICENSE file.

About Procore

Procore Logo

Registrar is maintained by Procore Technologies.

Procore - building the software that builds the world.

Learn more about the #1 most widely used construction management software at procore.com Contact us at [email protected]

registrar's People

Contributors

mcasper avatar cgetzen avatar patkoperwas avatar hparker avatar wjessop avatar mikeastock avatar jgittler avatar fairchild avatar

Stargazers

Serhii Ponomarov avatar Anand Dhillon avatar Spencer Neste avatar Taylor Campbell avatar  avatar matias avatar Benjamin Fleischer avatar Danny Phillips avatar Marcus Bernales avatar  avatar AJ Bahnken avatar Andy Maltun avatar  avatar  avatar

Watchers

Jeff Frost avatar Alan Stebbens avatar Christopher Maujean avatar  avatar Himansu Desai avatar Pablo Cordero avatar Remy Younes avatar Benjamin Halsted avatar Cody Roberts avatar Sam Crigman avatar Zach Gross avatar Casey Ochs avatar Greg Sparks avatar Dennis Heckman avatar Lucas Meadows avatar Kevin Kohrt avatar Alex Golikov avatar Vinit Desai avatar Illia Dryha avatar Oleksandr Moskovka avatar Brian Knapp avatar Andrew Callahan avatar Antoine Joulie avatar Serhii Ponomarov avatar Jennifer Dixon avatar Jeremy Lund avatar Claudio Sergio Forain, Jr. avatar James Cloos avatar Jonathan Greene avatar Jose Arantes avatar Andrew Seward avatar Vietor Davis avatar Lauren Brandstein avatar Marcus Bernales avatar Jordan Townsend avatar irving.gomez avatar Dmytro Sinchenko avatar Jed Needle avatar Paul Nispel avatar Lam Chan avatar Tom George avatar Jay Yang avatar  avatar David Martin avatar Jake Sanders avatar Chiranjeevi Patel avatar mmukarram avatar  avatar Bill Hancock avatar Andrei Evseev avatar Sarah Heredia avatar  avatar Michael Parris avatar Michael Stephens avatar Moises Narvaez avatar Dennis Patterson avatar Bradley Zeller avatar Jordan Faust avatar Justin Watts avatar Brett McCarty avatar Klaus Nji avatar Stephen Corgiat avatar Bharath Hariharan avatar Luis de Haro avatar Uday Sharma avatar Marek Piasecki avatar Oleksandr Dervish avatar Kyle Espinola avatar David Borden avatar Louis Mejia avatar Bryce McGaw avatar Kim Hin avatar Adam Eidelsafy avatar David avatar Shane Means avatar Ryan Smith avatar Julie Nisbet avatar Brett Cassedy avatar Sam Close avatar Andy Maltun avatar Yann Lebreton avatar Julian Claudino avatar Pierce Khougaz avatar Andrés avatar Brad Barnhill avatar Jett avatar Dan Nate avatar  avatar Hari avatar Brad Urani avatar Jessica avatar apcarroll avatar Tommy Carli avatar Antonio Samay avatar Davis Martin avatar  avatar Zack Miller avatar Winston Chung avatar haiyang zhang avatar Igor avatar

registrar's Issues

Remove Rails 6 warnings

it seems we need to make a few changes for it to be Rails 6 compliant:

DEPRECATION WARNING: Initialization autoloaded the constant Registrar::SessionManager.
Being able to do this is deprecated. Autoloading during initialization is going
to be an error condition in future versions of Rails.

Gem installation

According to the bundler doc, the github shorthand works only for public repositories: http://bundler.io/git.html

So the following code in Gemfile should not work (and it is not working for me):

gem "registrar", github: "procore/registrar"

Could any of you confirm it?

/cc @mcasper

Generator is not working

I was just following the Readme. I've added registrar to Gemfile and installed it.

$ rails generate registrar:install
Could not find generator 'registrar:install'. Maybe you meant 'annotate:install' or 'chewy:install' or 'test_unit:model'
Run `rails generate --help` for more options.

Also rails g don't show it.

Google wiki pages

Create wiki pages on how to setup a Google OAuth application, and how to grab the client_id/client_secret from it.

Make sure to link to this wiki in the README

Authentication works only on procore.com domains

In SessionsController we check if the app is running on the procore.com domain. Because of this I am not able to authenticate locally from localhost:3000 and on sherpa which is running on http://sherpa.procoretech.com/.

Why do we have this behaviour? What is the advantage of checking the app domain?

May I just remove this check?

/cc @mcasper

Registrar generator install doesn't work

Registrar's rails generator seems to need access to it's configuration even though it shouldn't exist yet because the generator installs the config/initializer.

$ rails generate registrar::install
/Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/bundler/gems/registrar-5fecb699af4b/config/routes.rb:6:in `block in <top (required)>': undefined method `signin_url' for nil:NilClass (NoMethodError)
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/actionpack-5.1.2/lib/action_dispatch/routing/mapper.rb:629:in `instance_exec'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/actionpack-5.1.2/lib/action_dispatch/routing/mapper.rb:629:in `block in with_default_scope'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/actionpack-5.1.2/lib/action_dispatch/routing/mapper.rb:854:in `scope'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/actionpack-5.1.2/lib/action_dispatch/routing/mapper.rb:628:in `with_default_scope'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/actionpack-5.1.2/lib/action_dispatch/routing/route_set.rb:422:in `eval_block'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/actionpack-5.1.2/lib/action_dispatch/routing/route_set.rb:406:in `draw'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/bundler/gems/registrar-5fecb699af4b/config/routes.rb:1:in `<top (required)>'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:286:in `load'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:286:in `block in load'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:258:in `load_dependency'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:286:in `load'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/railties-5.1.2/lib/rails/application/routes_reloader.rb:55:in `block in load_paths'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/railties-5.1.2/lib/rails/application/routes_reloader.rb:55:in `each'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/railties-5.1.2/lib/rails/application/routes_reloader.rb:55:in `load_paths'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/railties-5.1.2/lib/rails/application/routes_reloader.rb:18:in `reload!'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/railties-5.1.2/lib/rails/application/routes_reloader.rb:41:in `block in updater'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activesupport-5.1.2/lib/active_support/file_update_checker.rb:81:in `execute'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/railties-5.1.2/lib/rails/application/routes_reloader.rb:42:in `updater'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/railties-5.1.2/lib/rails/application/routes_reloader.rb:31:in `execute_if_updated'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/railties-5.1.2/lib/rails/application/finisher.rb:128:in `block in <module:Finisher>'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/railties-5.1.2/lib/rails/initializable.rb:30:in `instance_exec'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/railties-5.1.2/lib/rails/initializable.rb:30:in `run'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/railties-5.1.2/lib/rails/initializable.rb:59:in `block in run_initializers'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/2.4.0/tsort.rb:228:in `block in tsort_each'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/2.4.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/2.4.0/tsort.rb:431:in `each_strongly_connected_component_from'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/2.4.0/tsort.rb:349:in `block in each_strongly_connected_component'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/2.4.0/tsort.rb:347:in `each'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/2.4.0/tsort.rb:347:in `call'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/2.4.0/tsort.rb:347:in `each_strongly_connected_component'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/2.4.0/tsort.rb:226:in `tsort_each'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/2.4.0/tsort.rb:205:in `tsort_each'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/railties-5.1.2/lib/rails/initializable.rb:58:in `run_initializers'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/railties-5.1.2/lib/rails/application.rb:353:in `initialize!'
	from /Users/maxhelmetag/procore/dev-academy/config/environment.rb:5:in `<top (required)>'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application.rb:102:in `require'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application.rb:102:in `preload'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application.rb:153:in `serve'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /Users/maxhelmetag/.rbenv/versions/2.4.1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from -e:1:in `<main>'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.