Class: OAuth2::Strategy::WebServer

Inherits:
Base
  • Object
show all
Defined in:
lib/oauth2/strategy/web_server.rb

Instance Method Summary collapse

Methods inherited from Base

#access_token_url, #authorize_url, #initialize

Constructor Details

This class inherits a constructor from OAuth2::Strategy::Base

Instance Method Details

#access_token(*args) ⇒ Object

DEPRECATED: Use #get_access_token instead.



31
32
33
34
# File 'lib/oauth2/strategy/web_server.rb', line 31

def access_token(*args)
  warn '[DEPRECATED] OAuth2::Strategy::WebServer#access_token is deprecated, use #get_access_token instead. Will be removed in 0.1.0'
  get_access_token(*args)
end

#access_token_params(code, options = {}) ⇒ Object

:nodoc:



36
37
38
39
40
41
# File 'lib/oauth2/strategy/web_server.rb', line 36

def access_token_params(code, options = {}) #:nodoc:
  super(options).merge({
    'type' => 'web_server',
    'code' => code
  })
end

#authorize_params(options = {}) ⇒ Object

:nodoc:



6
7
8
# File 'lib/oauth2/strategy/web_server.rb', line 6

def authorize_params(options = {}) #:nodoc:
  super(options).merge('type' => 'web_server')
end

#get_access_token(code, options = {}) ⇒ Object

Retrieve an access token given the specified validation code. Note that you must also provide a :redirect_uri option in order to successfully verify your request for most OAuth 2.0 endpoints.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/oauth2/strategy/web_server.rb', line 14

def get_access_token(code, options = {})
  response = @client.request(:post, @client.access_token_url, access_token_params(code, options))

  params   = MultiJson.decode(response) rescue nil
  # the ActiveSupport JSON parser won't cause an exception when
  # given a formencoded string, so make sure that it was
  # actually parsed in an Hash. This covers even the case where
  # it caused an exception since it'll still be nil.
  params   = Rack::Utils.parse_query(response) unless params.is_a? Hash

  access   = params['access_token']
  refresh  = params['refresh_token']
  expires_in = params['expires_in']
  OAuth2::AccessToken.new(@client, access, refresh, expires_in)
end