Skip to content

Instantly share code, notes, and snippets.

@mgarciap
Created September 11, 2014 19:42
Show Gist options
  • Save mgarciap/f1cc788cb2d5a3b4f2d5 to your computer and use it in GitHub Desktop.
Save mgarciap/f1cc788cb2d5a3b4f2d5 to your computer and use it in GitHub Desktop.
cc_api = Faraday.new 'https://api.10.244.0.34.xip.io', :ssl => {:verify => false} do |conn|
conn.request :url_encoded
conn.response :logger
conn.adapter Faraday.default_adapter
end
response = cc_api.get do |req|
req.url '/v2/info'
req.headers['Accept'] = 'application/json'
end
response_json = JSON.parse(response.body)
token_endpoint = response_json["token_endpoint"]
uaa_api = Faraday.new token_endpoint, :ssl => {:verify => false} do |conn|
conn.request :url_encoded
conn.response :logger
conn.adapter Faraday.default_adapter
end
username = 'admin'
password = 'admin'
token_config = uaa_api.post do |req|
req.url '/oauth/token'
req.headers['Accept'] = 'application/json'
req.headers['Authorization'] = 'Basic Y2Y6'
req.body = "username=#{username}&password=#{password}&client_id=app&grant_type=password"
end
token_config_json = JSON.parse(token_config.body)
puts 'Access Token: ' + token_config_json['access_token']
puts 'token_type: ' + token_config_json['token_type']
token_type = token_config_json['token_type']
access_token = token_config_json['access_token']
orgs = cc_api.get do | req|
req.url '/v2/organizations'
req.headers['Authorization'] = token_type + ' ' + access_token
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment