Browse Source

change from google_apps to google_oauth2

pull/1/head
Nicolae Claudius 11 years ago
parent
commit
aacc7f4baa
  1. 2
      Gemfile
  2. 30
      Gemfile.lock
  3. 6
      app/controllers/users/omniauth_callbacks_controller.rb
  4. 2
      app/helpers/users/authentications_helper.rb
  5. 2
      app/models/user.rb
  6. 2
      app/views/users/registrations/_new.html.erb
  7. 2
      app/views/users/sessions/new.html.erb
  8. 6
      config/initializers/devise.rb
  9. 3
      config/settings.sample.yml

2
Gemfile

@ -4,7 +4,7 @@ gem 'rails', '4.0.2'
gem 'mysql2', '~> 0.3.13' gem 'mysql2', '~> 0.3.13'
gem 'devise', '~> 3.2.2' gem 'devise', '~> 3.2.2'
gem 'omniauth', '~> 1.1.4' gem 'omniauth', '~> 1.1.4'
gem 'omniauth-google-apps', '~> 0.1.0' gem 'omniauth-google-oauth2', '~> 0.2.2'
gem 'cancan', '= 1.6.7' gem 'cancan', '= 1.6.7'
gem 'squeel', '~> 1.1.0' gem 'squeel', '~> 1.1.0'
gem 'sentient_model', '~> 1.0.4' gem 'sentient_model', '~> 1.0.4'

30
Gemfile.lock

@ -122,6 +122,8 @@ GEM
railties (>= 3.0.0) railties (>= 3.0.0)
faker (1.2.0) faker (1.2.0)
i18n (~> 0.5) i18n (~> 0.5)
faraday (0.8.9)
multipart-post (~> 1.2.0)
font-awesome-rails (4.0.3.0) font-awesome-rails (4.0.3.0)
railties (>= 3.2, < 5.0) railties (>= 3.2, < 5.0)
fssm (0.2.10) fssm (0.2.10)
@ -129,6 +131,7 @@ GEM
tilt tilt
hashie (2.0.5) hashie (2.0.5)
hike (1.2.3) hike (1.2.3)
httpauth (0.2.0)
i18n (0.6.9) i18n (0.6.9)
jquery-rails (3.0.4) jquery-rails (3.0.4)
railties (>= 3.0, < 5.0) railties (>= 3.0, < 5.0)
@ -136,6 +139,8 @@ GEM
jquery-ui-rails (4.1.1) jquery-ui-rails (4.1.1)
railties (>= 3.1.0) railties (>= 3.1.0)
json (1.8.1) json (1.8.1)
jwt (0.1.10)
multi_json (>= 1.5)
kaminari (0.15.0) kaminari (0.15.0)
actionpack (>= 3.0.0) actionpack (>= 3.0.0)
activesupport (>= 3.0.0) activesupport (>= 3.0.0)
@ -155,6 +160,7 @@ GEM
mini_portile (0.5.2) mini_portile (0.5.2)
minitest (4.7.5) minitest (4.7.5)
multi_json (1.8.2) multi_json (1.8.2)
multipart-post (1.2.0)
mysql2 (0.3.14) mysql2 (0.3.14)
nested_form (0.3.2) nested_form (0.3.2)
nilify_blanks (1.0.3) nilify_blanks (1.0.3)
@ -163,19 +169,23 @@ GEM
nokogiri (1.6.1) nokogiri (1.6.1)
mini_portile (~> 0.5.0) mini_portile (~> 0.5.0)
nprogress-rails (0.1.2.3) nprogress-rails (0.1.2.3)
oauth2 (0.8.1)
faraday (~> 0.8)
httpauth (~> 0.1)
jwt (~> 0.1.4)
multi_json (~> 1.0)
rack (~> 1.2)
oily_png (1.1.0) oily_png (1.1.0)
chunky_png (~> 1.2.7) chunky_png (~> 1.2.7)
omniauth (1.1.4) omniauth (1.1.4)
hashie (>= 1.2, < 3) hashie (>= 1.2, < 3)
rack rack
omniauth-google-apps (0.1.0) omniauth-google-oauth2 (0.2.2)
omniauth (~> 1.0) omniauth (~> 1.0)
omniauth-openid (~> 1.0) omniauth-oauth2
ruby-openid (~> 2.3.0) omniauth-oauth2 (1.1.1)
ruby-openid-apps-discovery (~> 1.2.0) oauth2 (~> 0.8.0)
omniauth-openid (1.0.1)
omniauth (~> 1.0) omniauth (~> 1.0)
rack-openid (~> 1.3.1)
orm_adapter (0.5.0) orm_adapter (0.5.0)
polyamorous (0.6.4) polyamorous (0.6.4)
activerecord (>= 3.0) activerecord (>= 3.0)
@ -183,9 +193,6 @@ GEM
quiet_assets (1.0.2) quiet_assets (1.0.2)
railties (>= 3.1, < 5.0) railties (>= 3.1, < 5.0)
rack (1.5.2) rack (1.5.2)
rack-openid (1.3.1)
rack (>= 1.1.0)
ruby-openid (>= 2.1.8)
rack-pjax (0.7.0) rack-pjax (0.7.0)
nokogiri (~> 1.5) nokogiri (~> 1.5)
rack (~> 1.3) rack (~> 1.3)
@ -238,9 +245,6 @@ GEM
rspec-core (~> 2.14.0) rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0) rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0) rspec-mocks (~> 2.14.0)
ruby-openid (2.3.0)
ruby-openid-apps-discovery (1.2.0)
ruby-openid (>= 2.1.7)
safe_yaml (0.9.7) safe_yaml (0.9.7)
sass (3.2.13) sass (3.2.13)
sass-rails (4.0.1) sass-rails (4.0.1)
@ -331,7 +335,7 @@ DEPENDENCIES
nprogress-rails (~> 0.1.2.2) nprogress-rails (~> 0.1.2.2)
oily_png (~> 1.1.0) oily_png (~> 1.1.0)
omniauth (~> 1.1.4) omniauth (~> 1.1.4)
omniauth-google-apps (~> 0.1.0) omniauth-google-oauth2 (~> 0.2.2)
quiet_assets (~> 1.0.1) quiet_assets (~> 1.0.1)
rails (= 4.0.2) rails (= 4.0.2)
rails-settings-cached (~> 0.3.1) rails-settings-cached (~> 0.3.1)

6
app/controllers/users/omniauth_callbacks_controller.rb

@ -1,7 +1,7 @@
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def google_apps def google_oauth2
oauthorize 'google_apps' oauthorize 'google_oauth2'
end end
protected protected
@ -11,7 +11,7 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
@user = find_or_create_user(provider) @user = find_or_create_user(provider)
return redirect_to(:back) unless @user && @user.active_for_authentication? return redirect_to(:back) unless @user && @user.active_for_authentication?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", kind: provider.camelcase flash[:notice] = I18n.t "devise.omniauth_callbacks.success", kind: provider.camelcase
session["devise.google_apps_data"] = env["omniauth.auth"] session["devise.google_data"] = env["omniauth.auth"]
@user.remember_me! if session.delete(:user_remember_me) == "1" @user.remember_me! if session.delete(:user_remember_me) == "1"
sign_in_and_redirect @user, event: :authentication sign_in_and_redirect @user, event: :authentication
end end

2
app/helpers/users/authentications_helper.rb

@ -1,7 +1,7 @@
module Users::AuthenticationsHelper module Users::AuthenticationsHelper
def authentication_provider_column(record, column) def authentication_provider_column(record, column)
case record.provider case record.provider
when 'google_apps' when 'google_oauth2'
ret = <<-DOC ret = <<-DOC
<span class="btn btn-block btn-social btn-google-plus"> <span class="btn btn-block btn-social btn-google-plus">
<i class="fa fa-google-plus"></i> Google <i class="fa fa-google-plus"></i> Google

2
app/models/user.rb

@ -14,7 +14,7 @@ class User < ActiveRecord::Base
:confirmable, :confirmable,
:lockable, :lockable,
:omniauthable, :omniauthable,
:omniauth_providers => [:google_apps] :omniauth_providers => [:google_oauth2]
validates :full_name, :presence => true validates :full_name, :presence => true

2
app/views/users/registrations/_new.html.erb

@ -7,7 +7,7 @@
%> %>
<p> <p>
<%= link_to user_omniauth_authorize_path(:google_apps), <%= link_to user_omniauth_authorize_path(:google_oauth2),
class: 'btn btn-block btn-social btn-google-plus', class: 'btn btn-block btn-social btn-google-plus',
'data-no-turbolink' => true do %> 'data-no-turbolink' => true do %>
<i class="fa fa-google-plus"></i> Sign up with Google <i class="fa fa-google-plus"></i> Sign up with Google

2
app/views/users/sessions/new.html.erb

@ -4,7 +4,7 @@
<div class="col-lg-offset-4 col-lg-4 well"> <div class="col-lg-offset-4 col-lg-4 well">
<p> <p>
<%= link_to user_omniauth_authorize_path(:google_apps), <%= link_to user_omniauth_authorize_path(:google_oauth2),
class: 'btn btn-block btn-social btn-google-plus', class: 'btn btn-block btn-social btn-google-plus',
'data-no-turbolink' => true do %> 'data-no-turbolink' => true do %>
<i class="fa fa-google-plus"></i> Sign in with Google <i class="fa fa-google-plus"></i> Sign in with Google

6
config/initializers/devise.rb

@ -1,5 +1,3 @@
require 'openid/store/filesystem'
# Use this hook to configure devise mailer, warden hooks and so forth. The first # Use this hook to configure devise mailer, warden hooks and so forth. The first
# four configuration values can also be set straight in your models. # four configuration values can also be set straight in your models.
Devise.setup do |config| Devise.setup do |config|
@ -198,9 +196,7 @@ Devise.setup do |config|
# config.omniauth :open_id, name: 'user', # config.omniauth :open_id, name: 'user',
# identifier: 'https://www.google.com/accounts/o8/site-xrds?hd=' + Settings.domain, # identifier: 'https://www.google.com/accounts/o8/site-xrds?hd=' + Settings.domain,
# store: OpenID::Store::Filesystem.new('/tmp') # store: OpenID::Store::Filesystem.new('/tmp')
config.omniauth :google_apps, config.omniauth :google_oauth2, Settings.google_key, Settings.google_secret
store: OpenID::Store::Filesystem.new('/tmp'),
domain: 'gmail.com'
# ==> Warden configuration # ==> Warden configuration
# If you want to use other strategies, that are not supported by Devise, or # If you want to use other strategies, that are not supported by Devise, or

3
config/settings.sample.yml

@ -33,3 +33,6 @@ resolv:
honeypot: userid honeypot: userid
support_mail: "support@entrydns.net" support_mail: "support@entrydns.net"
news_link: "http://twitter.com/#!/entrydns" news_link: "http://twitter.com/#!/entrydns"
google_key: 105547277286.apps.googleusercontent.com
google_secret: 7cIdW07UrWUmeb8QFYV4L63k

Loading…
Cancel
Save