43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/http_streaming_client/oauth/adobe.rb', line 43
def self.generate_authorization(uri, username, password, clientId, clientSecret)
logger.debug "generate_authorization: #{uri}"
params = Hash.new
params['grant_type'] = "password"
params['username'] = username
params['password'] = password
params_string = sort_and_percent_encode(params)
logger.debug "params_string: #{params_string}"
basicAuth = "#{clientId}:#{clientSecret}"
basicAuth = Base64.encode64(basicAuth).chomp.gsub(/\n/, '')
logger.debug "base64 encoded authorization: #{basicAuth}"
uri = URI.parse(uri) if uri.is_a?(String)
url_string = "#{uri.scheme}://#{uri.host}#{uri.path}"
response = HttpStreamingClient::Client.post(uri, params_string, {:headers => {'Authorization' => "Basic #{basicAuth}"}})
response_json = JSON.parse(response)
logger.debug "token API response: #{response_json}"
authorization = response_json['access_token']
logger.debug "authorization header: #{authorization}"
return authorization
end
|