Skip to content

Instantly share code, notes, and snippets.

@carlesso
Created January 22, 2014 16:48
Show Gist options
  • Save carlesso/8562283 to your computer and use it in GitHub Desktop.
Save carlesso/8562283 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'json'
CLIENT_ID="eCGgvaJ3hKHD4kmPazSQrWVHGyZEsbSi"
CLIENT_SECRET="qGQ3sssbcEV5Ihmh"
res = `curl -s https://dnc-test.apigee.net/oauth/client_credential/accesstoken?grant_type=client_credentials -X POST -d "client_id=#{CLIENT_ID}&client_secret=#{CLIENT_SECRET}"`
p = JSON.parse(res)
puts p
# output =>
# {
# "issued_at" : "1390408642776",
# "application_name" : "fd72dc91-06cc-4929-8765-e627c05a6ea2",
# "scope" : "",
# "status" : "approved",
# "api_product_list" : "[cloudflow]",
# "expires_in" : "3599",
# "developer.email" : "[email protected]",
# "organization_id" : "0",
# "token_type" : "BearerToken",
# "client_id" : "eCGgvaJ3hKHD4kmPazSQrWVHGyZEsbSi",
# "access_token" : "UvpBdlcHjdESSjNgyYSrA76os8UT",
# "organization_name" : "dnc",
# "refresh_token_expires_in" : "0",
# "refresh_count" : "0"
# }%
token = p["access_token"]
# Using access token from before
fail_call = `curl -s https://dnc-test.apigee.net/v1/oauth/ -X GET`
puts "Fail call:"
puts fail_call
ok_call = `curl -s https://dnc-test.apigee.net/v1/oauth/ -X GET --header "Authentication: Bearer #{token}"`
puts "OK call:"
puts ok_call
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment