Class: MyTargetApi::Auth

Inherits:
Object
  • Object
show all
Extended by:
Request
Defined in:
lib/my_target_api/auth.rb

Overview

authorization

Class Method Summary collapse

Class Method Details

.authorize_urlObject



13
14
15
16
17
# File 'lib/my_target_api/auth.rb', line 13

def authorize_url
  state = (0...32).map { rand(65..90).chr }.join.downcase
  'https://target.my.com/oauth2/authorize?response_type=code' \
    "&client_id=#{MyTargetApi.client_id}&state=#{state}&scope=#{MyTargetApi.scopes}"
end

.get_agency_client_credentials(client_username) ⇒ Hash

We need new method to receive token using agency_client_credentials grant type

Parameters:

  • client_username (String)

    client user_name in myTarget

Returns:

  • (Hash)

    containing requested access_token



22
23
24
25
26
27
# File 'lib/my_target_api/auth.rb', line 22

def get_agency_client_credentials(client_username)
  params = { grant_type: 'agency_client_credentials',
             agency_client_name: client_username,
             v: 2 }
  request :post, '/oauth2/token', params
end

.get_token(code) ⇒ Object



29
30
31
32
# File 'lib/my_target_api/auth.rb', line 29

def get_token(code)
  params = { grant_type: 'authorization_code', code: code, v: 2 }
  request :post, '/oauth2/token', params
end

.refresh_token(code) ⇒ Object



34
35
36
37
# File 'lib/my_target_api/auth.rb', line 34

def refresh_token(code)
  params = { grant_type: 'refresh_token', refresh_token: code, v: 2 }
  request :post, '/oauth2/token', params
end