Skip to content
This repository has been archived by the owner on Mar 27, 2018. It is now read-only.

Commit

Permalink
Migrate from Google Open ID to Oauth2
Browse files Browse the repository at this point in the history
  • Loading branch information
Rashmi Yadav + Zoee Silcock committed Apr 30, 2015
1 parent 4ec5928 commit 16b1afe
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
source 'http://rubygems.org'
ruby '2.1.0'
ruby '2.2.2'

gem 'sinatra'

gem 'dotenv'
gem 'omniauth-google-apps'
gem 'omniauth-google-oauth2'

#assets
gem 'sinatra-asset-pipeline', require: 'sinatra/asset_pipeline'
Expand Down
39 changes: 21 additions & 18 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,38 @@ GEM
coffee-script-source (1.6.3)
dotenv (0.8.0)
execjs (2.0.2)
faraday (0.9.1)
multipart-post (>= 1.2, < 3)
handlebars_assets (0.15)
execjs (>= 1.2.9)
multi_json
sprockets (>= 2.0.3)
tilt
hashie (2.0.5)
hashie (3.4.1)
hike (1.2.3)
jwt (1.4.1)
multi_json (1.8.4)
omniauth (1.2.1)
hashie (>= 1.2, < 3)
multi_xml (0.5.5)
multipart-post (2.0.0)
oauth2 (1.0.0)
faraday (>= 0.8, < 0.10)
jwt (~> 1.0)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (~> 1.2)
omniauth (1.2.2)
hashie (>= 1.2, < 4)
rack (~> 1.0)
omniauth-google-apps (0.1.0)
omniauth (~> 1.0)
omniauth-openid (~> 1.0)
ruby-openid (~> 2.3.0)
ruby-openid-apps-discovery (~> 1.2.0)
omniauth-openid (1.0.1)
omniauth (~> 1.0)
rack-openid (~> 1.3.1)
omniauth-google-oauth2 (0.2.6)
omniauth (> 1.0)
omniauth-oauth2 (~> 1.1)
omniauth-oauth2 (1.3.0)
oauth2 (~> 1.0)
omniauth (~> 1.2)
rack (1.5.2)
rack-openid (1.3.1)
rack (>= 1.1.0)
ruby-openid (>= 2.1.8)
rack-protection (1.5.2)
rack
rake (10.1.1)
ruby-openid (2.3.0)
ruby-openid-apps-discovery (1.2.0)
ruby-openid (>= 2.1.7)
sass (3.2.14)
sinatra (1.4.4)
rack (~> 1.4)
Expand Down Expand Up @@ -74,7 +77,7 @@ DEPENDENCIES
coffee-script
dotenv
handlebars_assets
omniauth-google-apps
omniauth-google-oauth2
sass
sinatra
sinatra-asset-pipeline
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ The app uses [Keen.io](http://keen.io) as a data backend. So your Sendgrid accou

## Options
### Authentication
Build in support for authentication with Google apps. Set up your domain with the `GOOGLE_APPS_DOMAIN` environment variable. Remove the variable to disable authentication.
Build in support for authentication with Google Oauth2. Set up your client id with the `GOOGLE_CLIENT_ID` environment variable and client secret with the `GOOGLE_CLIENT_SECRET`. Remove the `GOOGLE_CLIENT_ID` variable to disable authentication.

The app uses [Omniauth](https://github.com/intridea/omniauth) for authentication so it can easily be replaced/combined with other providers than the provided Google Apps solution.
The app uses [Omniauth](https://github.com/intridea/omniauth) for authentication so it can easily be replaced/combined with other providers than the provided Google Oauth2 solution.

### Custom attributes
Show your custom Sendgrid arguments by setting the `CUSTOM_EVENT_ATTRIBUTES` environment variable with a comma separated list of attributes.
Expand Down
4 changes: 2 additions & 2 deletions lib/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class App < Sinatra::Base
use Rack::Session::Cookie, key: 'rack.session', path: '/', secret: ENV['SESSION_SECRET']

use OmniAuth::Builder do
provider :google_apps, domain: ENV['GOOGLE_APPS_DOMAIN'] if ENV['GOOGLE_APPS_DOMAIN']
provider :google_oauth2,ENV["GOOGLE_CLIENT_ID"], ENV["GOOGLE_CLIENT_SECRET"]
end

set :root, Pathname(__dir__).parent
Expand All @@ -31,7 +31,7 @@ class App < Sinatra::Base
end

get '/*' do
if ENV['GOOGLE_APPS_DOMAIN'] && session[:omniauth].nil?
if ENV['GOOGLE_CLIENT_ID'] && session[:omniauth].nil?
erb :sign_in
else
erb :app
Expand Down
2 changes: 1 addition & 1 deletion views/sign_in.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<div class="row">
<div class="col-md-12 signin">
<p>
<a href="/auth/google_apps" class="btn btn-block btn-primary">Sign in</a>
<a href="/auth/google_oauth2" class="btn btn-block btn-primary">Sign in</a>
</p>
</div>
</div>
Expand Down

2 comments on commit 16b1afe

@himynameisjonas
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! 🌹

This commit doesn't lock that authentication to a specific google apps domain (I could still access the deployed app)

@jorkas
Copy link

@jorkas jorkas commented on 16b1afe May 12, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@himynameisjonas thanks, we will have a look!

Please sign in to comment.