Skip to content

Instantly share code, notes, and snippets.

@hadrienblanc
Created February 19, 2020 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hadrienblanc/cba7c90f768b37d40e3366da6b6df33a to your computer and use it in GitHub Desktop.
Save hadrienblanc/cba7c90f768b37d40e3366da6b6df33a to your computer and use it in GitHub Desktop.
require 'rest-client'
require 'json'
client_id = '42f5e************************'
client_secret = 'secret-b42-************************'
begin
response = RestClient.post('www.my_app.com/oauth/token', {
grant_type: 'client_credentials',
client_id: client_id,
client_secret: client_secret
}) { |response, request, result|
case response.code
when 301, 302, 307
response.follow_redirection
else
response.return!
end
}
puts response.body
rescue RestClient::ExceptionWithResponse => e
puts e.response
end
require 'rest-client'
require 'json'
access_tokken = "bearer_token_********"
access_tokken = "Bearer #{access_tokken}"
url = "my_secret_ressource_endpoint/31"
response = RestClient.get(url, {
Authorization: access_tokken
})
puts response.body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment