Class: OmniAuth::Strategies::Google
- Inherits:
-
Object
- Object
- OmniAuth::Strategies::Google
- Includes:
- OmniAuth::Strategy
- Defined in:
- lib/omniauth/strategies/google.rb
Overview
Authentication strategy for connecting with Google
Defined Under Namespace
Classes: CallbackError
Constant Summary collapse
- PLUS_PROFILE_SCOPE =
'https://www.googleapis.com/auth/plus.me'
- USERINFO_SCOPE =
'https://www.googleapis.com/auth/userinfo.profile'
- DEFAULT_SCOPE =
PLUS_PROFILE_SCOPE
Instance Method Summary collapse
- #callback_phase ⇒ Object
- #client ⇒ Object
- #profile_data ⇒ Object
- #redirect_uri ⇒ Object
- #request_phase ⇒ Object
Instance Method Details
#callback_phase ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/omniauth/strategies/google.rb', line 128 def callback_phase if request.params['error'] || request.params['error_reason'] raise CallbackError.new( request.params['error'], request.params['error_description'] || request.params['error_reason'], request.params['error_uri'] ) end if request.params['code'] client..code = request.params['code'] end client..fetch_access_token! super rescue ::Signet::UnsafeOperationError => e fail!(:unsafe_operation, e) rescue ::Signet::AuthorizationError, CallbackError => e fail!(:invalid_credentials, e) rescue ::MultiJson::DecodeError, ::Signet::ParseError => e fail!(:invalid_response, e) rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e fail!(:timeout, e) end |
#client ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/omniauth/strategies/google.rb', line 25 def client @client ||= (begin client = ::Google::APIClient.new(.) client.key = .api_key if request.ip != '127.0.0.1' client.user_ip = request.ip end if client..kind_of?(::Signet::OAuth2::Client) client..client_id = .client_id client..client_secret = .client_secret client..scope = .scope client..refresh_token = .refresh_token client..redirect_uri = redirect_uri end client end) end |
#profile_data ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/omniauth/strategies/google.rb', line 47 def profile_data if skip_info? raise ArgumentError, "Profile data is not available when the :skip_info option is set." end @profile_data ||= (begin if client..scope.include?(PLUS_PROFILE_SCOPE) plus = client.discovered_api('plus', 'v1') result = client.execute(plus.people.get, {'userId' => 'me'}) result.data elsif client..scope.include?(USERINFO_SCOPE) result = client.execute( :uri => 'https://www.googleapis.com/oauth2/v1/userinfo' ) result.data else raise ArgumentError, "Profile data is not available without requesting " + "the '#{USERINFO_SCOPE}' scope." end end) end |
#redirect_uri ⇒ Object
43 44 45 |
# File 'lib/omniauth/strategies/google.rb', line 43 def redirect_uri full_host + script_name + callback_path end |
#request_phase ⇒ Object
124 125 126 |
# File 'lib/omniauth/strategies/google.rb', line 124 def request_phase redirect client...to_s end |