Skip to content

Instantly share code, notes, and snippets.

@nov
Created April 21, 2011 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nov/933885 to your computer and use it in GitHub Desktop.
Save nov/933885 to your computer and use it in GitHub Desktop.
Rack::OAuth2::Client Sample - Resource Request (MAC)
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment