Class: OmniAuth::Strategies::GoogleOauth2
- Inherits:
-
OAuth2
- Object
- OAuth2
- OmniAuth::Strategies::GoogleOauth2
- Defined in:
- lib/omniauth/strategies/google_oauth2.rb
Constant Summary collapse
- BASE_SCOPE_URL =
"https://www.googleapis.com/auth/"
- BASE_SCOPES =
%w[profile email openid]
- DEFAULT_SCOPE =
"email,profile"
Instance Method Summary collapse
- #authorize_params ⇒ Object
- #custom_build_access_token ⇒ Object (also: #build_access_token)
- #raw_friend_info(id) ⇒ Object
- #raw_image_info(id) ⇒ Object
- #raw_info ⇒ Object
Instance Method Details
#authorize_params ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/omniauth/strategies/google_oauth2.rb', line 26 def super.tap do |params| [:authorize_options].each do |k| params[k] = request.params[k.to_s] unless [nil, ''].include?(request.params[k.to_s]) end raw_scope = params[:scope] || DEFAULT_SCOPE scope_list = raw_scope.split(" ").map {|item| item.split(",")}.flatten scope_list.map! { |s| s =~ /^https?:\/\// || BASE_SCOPES.include?(s) ? s : "#{BASE_SCOPE_URL}#{s}" } params[:scope] = scope_list.join(" ") params[:access_type] = 'offline' if params[:access_type].nil? params['openid.realm'] = params.delete(:openid_realm) unless params[:openid_realm].nil? session['omniauth.state'] = params[:state] if params['state'] end end |
#custom_build_access_token ⇒ Object Also known as: build_access_token
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/omniauth/strategies/google_oauth2.rb', line 94 def custom_build_access_token access_token = if request.xhr? && request.params['code'] verifier = request.params['code'] client.auth_code.get_token(verifier, ('postmessage'), deep_symbolize(.auth_token_params || {})) elsif request.params['code'] && request.params['redirect_uri'] verifier = request.params['code'] redirect_uri = request.params['redirect_uri'] client.auth_code.get_token(verifier, (redirect_uri), deep_symbolize(.auth_token_params || {})) elsif verify_token(request.params['access_token']) ::OAuth2::AccessToken.from_hash(client, request.params.dup) else verifier = request.params["code"] client.auth_code.get_token(verifier, (callback_url), deep_symbolize(.auth_token_params)) end verify_hd(access_token) access_token end |
#raw_friend_info(id) ⇒ Object
86 87 88 |
# File 'lib/omniauth/strategies/google_oauth2.rb', line 86 def raw_friend_info(id) @raw_friend_info ||= access_token.get("https://www.googleapis.com/plus/v1/people/#{id}/people/visible").parsed end |
#raw_image_info(id) ⇒ Object
90 91 92 |
# File 'lib/omniauth/strategies/google_oauth2.rb', line 90 def raw_image_info(id) @raw_image_info ||= access_token.get("https://www.googleapis.com/plus/v1/people/#{id}?fields=image").parsed end |
#raw_info ⇒ Object
82 83 84 |
# File 'lib/omniauth/strategies/google_oauth2.rb', line 82 def raw_info @raw_info ||= access_token.get('https://www.googleapis.com/plus/v1/people/me/openIdConnect').parsed end |