Class: HttpStreamingClient::Oauth::Adobe

Inherits:
Base
  • Object
show all
Defined in:
lib/http_streaming_client/oauth/adobe.rb

Class Method Summary collapse

Methods inherited from Base

logger

Class Method Details

.generate_authorization(uri, username, password, clientId, clientSecret) ⇒ Object



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
75
76
77
78
79
# 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}"

	# POST to uri
	assembled_response = ""
	response = HttpStreamingClient::Client.post(uri, params_string, {:headers => {'Authorization' => "Basic #{basicAuth}"}}) { |line|
	  # token server now sending chunked, gzip'd response...
	  logger.debug "line received: #{line}"
	  assembled_response << line
	}
	response_json = JSON.parse(assembled_response)

	logger.debug "token API response: #{response_json}"

	authorization = response_json['access_token']

	logger.debug "authorization header: #{authorization}"

	return authorization
end