Skip to content

Instantly share code, notes, and snippets.

@esparkman
Created December 27, 2010 21:21
Show Gist options
  • Save esparkman/756568 to your computer and use it in GitHub Desktop.
Save esparkman/756568 to your computer and use it in GitHub Desktop.
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'
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
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