Skip to content

Commit b7ae3d3

Browse files
Chris Hendrixiredelmeier
Chris Hendrix
authored andcommitted
Upgrade from Google OpenID to Google OAuth2
[Fixes #94585256] Signed-off-by: Isobel Redelmeier <[email protected]>
1 parent 639a010 commit b7ae3d3

11 files changed

+45
-30
lines changed

.env-development

+3
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ export WORDPRESS_BASIC_AUTH_PASSWORD=password
44
export WORDPRESS_XMLRPC_ENDPOINT_PATH=/wordpress/xmlrpc.php
55
export WORDPRESS_USER=user
66
export WORDPRESS_PASSWORD=password
7+
export GOOGLE_CLIENT_ID=your_id_here
8+
export GOOGLE_CLIENT_SECRET=your_secret_here
9+
export GOOGLE_CLIENT_DOMAIN=your_domain_here

.env-example

+3
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ WORDPRESS_BASIC_AUTH_PASSWORD=password
44
WORDPRESS_XMLRPC_ENDPOINT_PATH=/wordpress/xmlrpc.php
55
WORDPRESS_USER=user
66
WORDPRESS_PASSWORD=password
7+
GOOGLE_CLIENT_ID=your_id_here
8+
GOOGLE_CLIENT_SECRET=your_secret_here
9+
GOOGLE_CLIENT_DOMAIN=your_domain_here

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ gem 'rails', '4.1.0.rc1'
55
gem 'pg'
66
gem 'unicorn'
77
gem 'jquery-rails'
8-
gem 'omniauth-google-apps'
8+
gem 'omniauth-google-oauth2'
99
gem 'github-markdown', require: 'github/markdown'
1010
gem 'exceptional'
1111
gem 'protected_attributes'

Gemfile.lock

+21-18
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ GEM
8484
fakefs (0.5.0)
8585
faker (1.2.0)
8686
i18n (~> 0.5)
87+
faraday (0.9.1)
88+
multipart-post (>= 1.2, < 3)
8789
ffi (1.9.3)
8890
font-awesome-sass-rails (3.0.2.2)
8991
railties (>= 3.1.1)
@@ -93,14 +95,15 @@ GEM
9395
thor (>= 0.13.6)
9496
fssm (0.2.10)
9597
github-markdown (0.6.4)
96-
hashie (2.0.5)
98+
hashie (3.4.1)
9799
highline (1.6.21)
98100
hike (1.2.3)
99101
i18n (0.6.9)
100102
jquery-rails (3.1.0)
101103
railties (>= 3.0, < 5.0)
102104
thor (>= 0.14, < 2.0)
103105
json (1.8.1)
106+
jwt (1.5.0)
104107
kgio (2.9.2)
105108
launchy (2.4.2)
106109
addressable (~> 2.3)
@@ -113,6 +116,8 @@ GEM
113116
mini_portile (0.6.0)
114117
minitest (5.3.0)
115118
multi_json (1.10.1)
119+
multi_xml (0.5.5)
120+
multipart-post (2.0.0)
116121
net-scp (1.2.0)
117122
net-ssh (>= 2.6.5)
118123
net-sftp (2.1.2)
@@ -122,25 +127,26 @@ GEM
122127
net-ssh (>= 2.6.5)
123128
nokogiri (1.6.3.1)
124129
mini_portile (= 0.6.0)
125-
omniauth (1.2.1)
126-
hashie (>= 1.2, < 3)
130+
oauth2 (1.0.0)
131+
faraday (>= 0.8, < 0.10)
132+
jwt (~> 1.0)
133+
multi_json (~> 1.3)
134+
multi_xml (~> 0.5)
135+
rack (~> 1.2)
136+
omniauth (1.2.2)
137+
hashie (>= 1.2, < 4)
127138
rack (~> 1.0)
128-
omniauth-google-apps (0.1.0)
129-
omniauth (~> 1.0)
130-
omniauth-openid (~> 1.0)
131-
ruby-openid (~> 2.3.0)
132-
ruby-openid-apps-discovery (~> 1.2.0)
133-
omniauth-openid (1.0.1)
134-
omniauth (~> 1.0)
135-
rack-openid (~> 1.3.1)
139+
omniauth-google-oauth2 (0.2.6)
140+
omniauth (> 1.0)
141+
omniauth-oauth2 (~> 1.1)
142+
omniauth-oauth2 (1.3.0)
143+
oauth2 (~> 1.0)
144+
omniauth (~> 1.2)
136145
pg (0.17.1)
137146
polyglot (0.3.4)
138147
protected_attributes (1.0.5)
139148
activemodel (>= 4.0.1, < 5.0)
140149
rack (1.5.2)
141-
rack-openid (1.3.1)
142-
rack (>= 1.1.0)
143-
ruby-openid (>= 2.1.8)
144150
rack-test (0.6.2)
145151
rack (>= 1.0)
146152
rails (4.1.0.rc1)
@@ -171,9 +177,6 @@ GEM
171177
rspec-core (~> 2.14.0)
172178
rspec-expectations (~> 2.14.0)
173179
rspec-mocks (~> 2.14.0)
174-
ruby-openid (2.3.0)
175-
ruby-openid-apps-discovery (1.2.0)
176-
ruby-openid (>= 2.1.7)
177180
rubyzip (1.1.6)
178181
sass (3.2.14)
179182
sass-rails (4.0.1)
@@ -241,7 +244,7 @@ DEPENDENCIES
241244
launchy
242245
letter_opener
243246
minitest
244-
omniauth-google-apps
247+
omniauth-google-oauth2
245248
pg
246249
protected_attributes
247250
rails (= 4.1.0.rc1)

README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ The following environment variables are necessary for posting to email via SendG
4343

4444
export SENDGRID_USERNAME=<username>
4545
export SENDGRID_PASSWORD=<password>
46+
47+
The following environment variables are necessary to integrate with google oauth2.
48+
49+
export GOOGLE_CLIENT_ID=<client_id>
50+
export GOOGLE_CLIENT_SECRET=<client_secret>
51+
52+
You can find these in the [Google Developers Console](https://console.developers.google.com). See the
53+
[OmniAuth Google OAuth2 repo](https://github.com/zquestz/omniauth-google-oauth2) for more details.
4654

4755
To use these environment variables in development mode:
4856

@@ -106,4 +114,4 @@ Whiteboard was written by [Matthew Kocher](https://github.com/mkocher).
106114

107115
License
108116
=======
109-
Whiteboard is MIT Licensed. See MIT-LICENSE for details.
117+
Whiteboard is MIT Licensed. See MIT-LICENSE for details.

app/controllers/application_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class ApplicationController < ActionController::Base
55

66
def require_login
77
mapper = IpToStandupMapper.new
8-
redirect_to '/auth/google_apps' unless session[:logged_in] || mapper.authorized?(ip_address_string: request.remote_ip)
8+
redirect_to '/auth/google_oauth2' unless session[:logged_in] || mapper.authorized?(ip_address_string: request.remote_ip)
99
end
1010

1111
# Adds an outer container element around any yielded HTML.

app/controllers/sessions_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class SessionsController < ApplicationController
22
skip_before_filter :verify_authenticity_token, only: :create
33

44
def create
5-
session[:logged_in] = true if request.env['omniauth.auth']['info']['email'] =~ /.*@pivotal\.io/
5+
session[:logged_in] = true
66
session[:username] = request.env['omniauth.auth']['info']['name']
77
redirect_to '/'
88
end

config/initializers/omniauth.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
Rails.application.config.middleware.use OmniAuth::Builder do
2-
provider :google_apps, domain: 'pivotal.io'
2+
provider :google_oauth2, ENV['GOOGLE_CLIENT_ID'], ENV['GOOGLE_CLIENT_SECRET'],
3+
{
4+
hd: ENV['GOOGLE_CLIENT_DOMAIN'] || 'pivotal.io'
5+
}
36
end

config/routes.rb

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
end
2525
end
2626

27+
get '/auth/:provider/callback', to: 'sessions#create'
2728
post '/auth/:provider/callback', to: 'sessions#create'
2829
get '/logout', to: 'sessions#destroy'
2930

spec/controllers/application_controller_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
allow(request).to receive(:remote_ip).and_return('')
1414
get :index
1515
response.should be_redirect
16-
expect(response).to redirect_to 'http://test.host/auth/google_apps'
16+
expect(response).to redirect_to 'http://test.host/auth/google_oauth2'
1717
end
1818
end

spec/controllers/sessions_controller_spec.rb

-6
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@
1515
post :create
1616
request.session['username'].should == 'Dennis'
1717
end
18-
19-
it "does not allow someone from outside pivotal.io to log in" do
20-
request.env['omniauth.auth'] = { 'info' => { 'email' => '[email protected]' } }
21-
post :create
22-
request.session['logged_in'].should be_nil
23-
end
2418
end
2519

2620
describe '#destroy' do

0 commit comments

Comments
 (0)