Skip to content

Instantly share code, notes, and snippets.

@ecarnevale
Created Nov 12, 2014
Embed
What would you like to do?
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