Created
November 12, 2014 18:32
-
-
Save ecarnevale/14caabca5f9125a8d0b4 to your computer and use it in GitHub Desktop.
User.rb
This file contains hidden or 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 | |
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