diff --git a/Gemfile b/Gemfile index f639e1491..6a6d1f512 100644 --- a/Gemfile +++ b/Gemfile @@ -21,6 +21,7 @@ gem 'jbuilder' gem 'devise', '~> 4.7' gem 'omniauth-github' gem 'omniauth-twitter' +gem 'omniauth-google-oauth2' gem 'chartkick' gem 'groupdate' diff --git a/Gemfile.lock b/Gemfile.lock index aec144b07..95d5ddc25 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -241,6 +241,10 @@ GEM omniauth-github (1.4.0) omniauth (~> 1.5) omniauth-oauth2 (>= 1.4.0, < 2.0) + omniauth-google-oauth2 (0.8.0) + jwt (>= 2.0) + omniauth (>= 1.1.1) + omniauth-oauth2 (>= 1.6) omniauth-oauth (1.1.0) oauth omniauth (~> 1.0) @@ -460,6 +464,7 @@ DEPENDENCIES launchy nokogiri omniauth-github + omniauth-google-oauth2 omniauth-twitter paper_trail pg diff --git a/README.md b/README.md index b01fa9a2f..53661a4d1 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ The CFP App does not provide a public facing website for your conference, though * Ruby 2.6.5 * Bundler (was installed with 1.17.3) * PostgreSQL +* Yarn installed via NPM Make sure you have Ruby and Postgres installed in your environment. Double check in the [Gemfile](../blob/master/Gemfile) for the exact supported version. This is a Rails 5 app and uses bundler to install all required gems. We are also making the assumption that you're familiar with how Rails apps are setup and deployed. If this is not the case then you'll want to refer to documentation that will bridge any gaps in the instructions below. @@ -56,15 +57,22 @@ This will boot up using Foreman and allow the .env file to be read / set for use ### Environment variables -[Omniauth](https://github.com/omniauth/omniauth) is set up to use Twitter and GitHub for logins in production. You'll want to put your own key and secret in for both. Other environment variables will include your postgres user and Rails' secret\_token. +The app uses the following environment variables by default. Some of these may be populated by your service provider in the case of Heroku. TIMEZONE (defaults to Pacific if not set) POSTGRES_USER (dev/test only) MAIL_HOST (production only - from host) MAIL_FROM (production only - from address) SECRET_TOKEN (production only) + +### Oauth Configuration + +[Omniauth](https://github.com/omniauth/omniauth) is set up to use GitHub, Google, or Twitter for login in production. You'll want to read up how to configure Omniauth elsewhere but here are the following key pairs the app will be looking for in your environment variables. + GITHUB_KEY GITHUB_SECRET + GOOGLE_OAUTH_CLIENT_ID + GOOGLE_OAUTH_CLIENT_SECRET TWITTER_KEY TWITTER_SECRET diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index f1b89b43f..ff2734725 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -9,6 +9,10 @@ def github authenticate_with_hash end + def google_oauth2 + authenticate_with_hash + end + def failure redirect_to new_user_session_url, danger: "There was an error authenticating you. Please try again." end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 5c025a063..73660c32e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -121,4 +121,16 @@ def staff_nav? def admin_nav? current_user.admin? end + + def twitter_oauth? + ENV['TWITTER_KEY'].present? + end + + def github_oauth? + ENV['GITHUB_KEY'].present? + end + + def google_oauth? + ENV['GOOGLE_OAUTH_CLIENT_ID'].present? + end end diff --git a/app/models/user.rb b/app/models/user.rb index 4f4be67ad..a62fead79 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -5,7 +5,7 @@ class User < ApplicationRecord # :confirmable, :lockable, :timeoutable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :confirmable, #:validatable, - :omniauthable, omniauth_providers: [:twitter, :github] + :omniauthable, omniauth_providers: [:twitter, :github, :google_oauth2] has_many :invitations, dependent: :destroy has_many :teammates, dependent: :destroy diff --git a/app/views/devise/shared/_links.html.erb b/app/views/devise/shared/_links.html.erb index eacca3509..5d26000e8 100644 --- a/app/views/devise/shared/_links.html.erb +++ b/app/views/devise/shared/_links.html.erb @@ -23,14 +23,23 @@ <%- if devise_mapping.omniauthable? %> - <%= link_to user_twitter_omniauth_authorize_path, class: "btn btn-twitter" do %> - - Sign in with Twitter + <% if twitter_oauth? %> + <%= link_to user_twitter_omniauth_authorize_path, class: "btn btn-twitter" do %> + + Sign in with Twitter + <% end %> <% end %> - <%= link_to user_github_omniauth_authorize_path, class: "btn btn-github" do %> - - Sign in with GitHub + <% if github_oauth? %> + <%= link_to user_github_omniauth_authorize_path, class: "btn btn-github" do %> + + Sign in with GitHub + <% end %> + <% end %> + <% if google_oauth? %> + <%= link_to user_google_oauth2_omniauth_authorize_path, class: "btn btn-default" do %> + + Sign in with Google + <% end %> <% end %> - <% end %> diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 6215eb0f9..653eb9885 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -243,6 +243,7 @@ # up on your models and hooks. config.omniauth :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET'], scope: 'user:email' config.omniauth :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET'] + config.omniauth :google_oauth2, ENV['GOOGLE_OAUTH_CLIENT_ID'], ENV['GOOGLE_OAUTH_CLIENT_SECRET'] config.omniauth :developer unless Rails.env.production? # ==> Warden configuration