Skip to content

Instantly share code, notes, and snippets.

@nov
Created March 23, 2011 17:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save nov/883575 to your computer and use it in GitHub Desktop.
Save nov/883575 to your computer and use it in GitHub Desktop.
Rack::OAuth2::Client Sample - Resource Request (Bearer)
require 'rubygems'
require 'rack/oauth2'
def url_for(path)
File.join("http://rack-oauth2-sample.heroku.com", path)
end
resource_of = :user
case resource_of
when :user
token = Rack::OAuth2::AccessToken::Bearer.new(
:access_token => YOUR_ACCESS_TOKEN_FOR_USER
)
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::Bearer.new(
:access_token => YOUR_ACCESS_TOKEN_FOR_CLIENT
)
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