Created
December 27, 2010 21:21
-
-
Save esparkman/756568 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TypeError (can't convert String into Integer): | |
app/models/user.rb:12:in `[]' | |
app/models/user.rb:12:in `find_for_google_apps_oauth' | |
app/controllers/users/omniauth_callbacks_controller.rb:17:in `google_apps' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
# Include default devise modules. Others available are: | |
# :token_authenticatable, :confirmable, :lockable and :timeoutable | |
devise :database_authenticatable, :omniauthable, :registerable, | |
:recoverable, :rememberable, :trackable, :validatable | |
# Setup accessible (or protected) attributes for your model | |
attr_accessible :email, :password, :password_confirmation, :remember_me | |
def self.find_for_google_apps_oauth(access_token, signed_in_resource=nil) | |
data = access_token['extra'],['user_hash'] | |
if user = User.find_by_email(data["email"]) | |
user | |
else # Create a user with a stub password | |
User.create!(:email => data["email"], :password => Devise.friendly_token[0,20]) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController | |
def google_apps | |
# You need to implement the method below in your model | |
@user = User.find_for_google_apps_oauth(env["omniauth.auth"], current_user) | |
if @user.persisted? | |
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Google" | |
sign_in_and_redirect @user, :event => :authentication | |
else | |
session["devise.google_apps_data"] = env["omniauth.auth"] | |
redirect_to new_user_registration_url | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment