public
Last active

Rack::OAuth2::Client Sample - Resource Request (MAC)

  • Download Gist
resource_request_sample.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
require 'rubygems'
require 'rack/oauth2'
 
def url_for(path)
File.join("https://rack-oauth2-sample-mac.heroku.com", path)
end
 
resource_of = :user
 
case resource_of
when :user
token = Rack::OAuth2::AccessToken::MAC.new(
:access_token => YOUR_ACCESS_TOKEN_FOR_USER,
:mac_key => YOUR_ACCESS_TOKEN_SECRET_FOR_USER,
:mac_algorithm => 'hmac-sha-256'
)
begin
p token.get url_for('/protected_resources')
p token.post url_for('/protected_resources'), {}
rescue => e
p e.response.headers[:www_authenticate]
end
when :client
token = Rack::OAuth2::AccessToken::MAC.new(
:access_token => YOUR_ACCESS_TOKEN_FOR_CLIENT,
:mac_key => YOUR_ACCESS_TOKEN_SECRET_FOR_CLIENT,
:mac_algorithm => 'hmac-sha-256'
)
begin
p token.get url_for('/client_statistic')
rescue => e
p e.response.headers[:www_authenticate]
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.