Class: Linkshare::Strategy

Inherits:
OAuth2::Strategy::Base
  • Object
show all
Defined in:
lib/linkshare/strategy.rb

Instance Method Summary collapse

Instance Method Details

#authorization(client_id, client_secret) ⇒ Object

Returns the Authorization header value for Basic Authentication

Parameters:

  • The (String)

    client ID

  • the (String)

    client secret



34
35
36
# File 'lib/linkshare/strategy.rb', line 34

def authorization(client_id, client_secret)
  'Basic ' + Base64.encode64(client_id + ':' + client_secret).gsub("\n", '')
end

#get_token(username, password, sid, params = {}, opts = {}) ⇒ Object

Retrieve an access token given the specified End User username, password and Linkshare AccountID.

Parameters:

  • username (String)

    the End User username

  • password (String)

    the End User password

  • sid (String)

    the Account ID

  • params (Hash) (defaults to: {})

    additional params



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/linkshare/strategy.rb', line 11

def get_token(username, password, sid, params = {}, opts = {})
  request_body = opts.delete('auth_scheme') == 'request_body'
  params = {'grant_type' => 'password',
            'username'   => username,
            'password'   => password,
            'scope' => sid
          }.merge(client_params).merge(params)

  params.merge!('client_params' => {
    :headers => {
      'Authorization' => authorization(client_params['client_id'], client_params['client_secret']),
      'Accept' => 'application/xml'}
    })

  # params.merge(:parse => :xml)
  @client.get_token(params, opts)
end