lib/ultradns/api/authentication.rb in ultradns-sdk-0.0.3 vs lib/ultradns/api/authentication.rb in ultradns-sdk-0.0.4
- old
+ new
@@ -37,32 +37,34 @@
refresh if params[:force_refresh]
(params[:headers] ||= {})['Authorization'] = "Bearer #{access_token}"
params
end
- def auth(username, password)
+ def auth(username, password, base_uri)
@auth = {}
@auth[:requested_at] = Time.now.to_i
response = self.class.post('/authorization/token',
body: {
grant_type: 'password',
username: username,
password: password
},
headers: {
'Content-Type' => 'application/x-www-form-urlencoded'
- }
+ },
+ base_uri: base_uri
)
body = response.parsed_response
logger.debug "Auth Response: #{response.inspect}"
raise "Authentication Error: #{response.body}" unless response.code == 200
# temp
@auth[:username] = username
@auth[:password] = password
+ @auth[:base_url] = base_uri
@auth[:access_token] = body['accessToken']
@auth[:refresh_token] = body['refreshToken']
@auth[:expires_in] = body['expiresIn']
end
@@ -76,10 +78,10 @@
(@auth[:requested_at] + @auth[:expires_in]) >= Time.now.to_i
end
def refresh
# expires not available, then reauth
- return auth(@auth[:username], @auth[:password]) if no_expiry?
+ return auth(@auth[:username], @auth[:password], @auth[:base_url]) if no_expiry?
# not expired yet.
return unless refresh?
requested_at = Time.now.to_i