Class: OAuth::TwoLeggedAccessToken

Inherits:
AccessToken
  • Object
show all
Defined in:
lib/two-legged-oauth/access_token.rb

Overview

The TwoLeggedAccessToken is used for the actual “real” web service calls that you perform against Google Apps APIs with 2LO (2 legged authentication). Use this instead of the normal AccessToken and it should play out of the box.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(consumer, xoauth_requestor_id) ⇒ TwoLeggedAccessToken

Returns a new instance of TwoLeggedAccessToken.

Parameters:

  • consumer (OAuth::Consumer)

    a properly initialized oauth consumer

  • xoauth_requestor_id (String)

    usually the email of the user ([email protected])



12
13
14
15
# File 'lib/two-legged-oauth/access_token.rb', line 12

def initialize(consumer, xoauth_requestor_id)
  super(consumer)
  @xoauth_requestor_id = xoauth_requestor_id
end

Instance Attribute Details

#xoauth_requestor_idObject

Returns the value of attribute xoauth_requestor_id.



8
9
10
# File 'lib/two-legged-oauth/access_token.rb', line 8

def xoauth_requestor_id
  @xoauth_requestor_id
end

Instance Method Details

#request(http_method, path, *arguments) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/two-legged-oauth/access_token.rb', line 17

def request(http_method, path, *arguments)
  Logger.debug("Original OAuth request path : #{path}")
  request_uri = URI.parse(path)

  if xoauth_requestor_id
    xoauth_param = "xoauth_requestor_id=#{xoauth_requestor_id}"
    escaped_xoauth_param = "xoauth_requestor_id=#{CGI.escape(xoauth_requestor_id)}"

    if request_uri.query
      request_uri.query.gsub!(xoauth_param, '')
      request_uri.query.gsub!(escaped_xoauth_param, '')
    end

    request_uri.query = !request_uri.query.nil? && request_uri.query != "" ?
        "#{request_uri.query}&#{escaped_xoauth_param}" :
        "#{escaped_xoauth_param}"

    path = request_uri.to_s
  end

  Logger.debug("Hacked OAuth request path : #{path}")
  super(http_method, path, *arguments)
end