Skip to content

Instantly share code, notes, and snippets.

@ecarnevale
Created November 12, 2014 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ecarnevale/14caabca5f9125a8d0b4 to your computer and use it in GitHub Desktop.
Save ecarnevale/14caabca5f9125a8d0b4 to your computer and use it in GitHub Desktop.
User.rb
class User < ActiveRecord::Base
devise :trackable, :validatable, :database_authenticatable, :rememberable,
:omniauthable, :omniauth_providers => [:google_oauth2]
attr_accessible :email, :password, :password_confirmation, :remember_me, :name, :provider, :uid
def self.find_by_authentication_token(access_token)
client = OAuth2::Client.new(ENV['GOOGLE_OAUTH2_ID'],ENV['GOOGLE_OAUTH2_SECRET'])
begin
response = client.request(:get, 'https://www.googleapis.com/oauth2/v2/tokeninfo', :params => {
:access_token => access_token
}).parsed
return User.where(:email => response['email']).first
rescue
# Oauth2::Client throws an Exception when access_token is not valid anymore
return nil
end
end
has_many :openings
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment