Class: OmniAuth::Strategies::GoogleOauth2AccessToken
- Inherits:
-
Object
- Object
- OmniAuth::Strategies::GoogleOauth2AccessToken
- Includes:
- OmniAuth::Strategy
- Defined in:
- lib/omniauth/strategies/google-oauth2-access-token.rb
Constant Summary collapse
- BASE_SCOPE_URL =
"https://www.googleapis.com/auth/"
- DEFAULT_SCOPE =
"userinfo.email,userinfo.profile"
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
Instance Method Summary collapse
- #authorize_params ⇒ Object
- #callback_phase ⇒ Object
- #client ⇒ Object
- #raw_info ⇒ Object
- #request_phase ⇒ Object
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
30 31 32 |
# File 'lib/omniauth/strategies/google-oauth2-access-token.rb', line 30 def access_token @access_token end |
Instance Method Details
#authorize_params ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/omniauth/strategies/google-oauth2-access-token.rb', line 32 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?:\/\// ? s : "#{BASE_SCOPE_URL}#{s}" } params[:scope] = scope_list.join(" ") params[:access_type] = 'offline' if params[:access_type].nil? session['omniauth.state'] = params[:state] if params['state'] end end |
#callback_phase ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/omniauth/strategies/google-oauth2-access-token.rb', line 84 def callback_phase if !request.params['access_token'] || request.params['access_token'].to_s.empty? raise ArgumentError.new("No access token provided.") end self.access_token = build_access_token self.access_token = self.access_token.refresh! if self.access_token.expired? # TODO: Validate the token # Validate that the token belong to the application # Rails.logger.info "---------------bef" # Rails.logger.info self.access_token.get('/app') # Rails.logger.info "---------------af" # app_raw = self.access_token.get('/app').parsed # Rails.logger.info "---------------2nd" # Rails.logger.info app_raw # if app_raw["id"] != options.client_id.to_s # Rails.logger.info "client_id=#{options.client_id}" # raise ArgumentError.new("Access token doesn't belong to the client.") # end # Preserve compatibility with the google provider in normal case hash = auth_hash hash[:provider] = "google" self.env['omniauth.auth'] = hash call_app! rescue ::OAuth2::Error => e fail!(:invalid_credentials, e) rescue ::MultiJson::DecodeError => e fail!(:invalid_response, e) rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e fail!(:timeout, e) rescue ::SocketError => e fail!(:failed_to_connect, e) end |
#client ⇒ Object
73 74 75 |
# File 'lib/omniauth/strategies/google-oauth2-access-token.rb', line 73 def client ::OAuth2::Client.new(.client_id, .client_secret, deep_symbolize(.)) end |
#raw_info ⇒ Object
69 70 71 |
# File 'lib/omniauth/strategies/google-oauth2-access-token.rb', line 69 def raw_info @raw_info ||= access_token.get('https://www.googleapis.com/oauth2/v1/userinfo').parsed end |
#request_phase ⇒ Object
77 78 79 80 81 82 |
# File 'lib/omniauth/strategies/google-oauth2-access-token.rb', line 77 def request_phase form = OmniAuth::Form.new(:title => "User Token", :url => callback_path) form.text_field "Access Token", "access_token" form. "Sign In" form.to_response end |