Skip to content

Instantly share code, notes, and snippets.

@johnnyhalife
Created February 20, 2010 15:40
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 johnnyhalife/309732 to your computer and use it in GitHub Desktop.
Save johnnyhalife/309732 to your computer and use it in GitHub Desktop.
Rack::Auth::WRAP protected resource client
require 'rubygems'
require 'cgi'
require 'base64'
require 'restclient'
require 'hmac/sha2'
SHARED_SECRET = "NjkzNTczOTAtMDA2MC0wMTJkLTQ1M2YtMDAyMzMyYjFmYWY4\n"
simple_web_token = {'Audience' => "http://localhost:4567",
'Issuer' => "urn:demo-issuer",
'ExpiresOn' => (Time.now.to_i + 60).to_s,
'Email' => 'johnny.halife@sample.com'}.map{|k, v| "#{k}=#{CGI.escape(v)}"}.join("&")
signature = Base64.encode64(HMAC::SHA256.new(Base64.decode64(SHARED_SECRET)).update(simple_web_token.toutf8).digest).strip
simple_web_token += "&HMACSHA256=#{CGI.escape(signature)}"
puts RestClient.get("http://localhost:4567/", "Authorization" => "WRAP access_token=#{CGI.escape(simple_web_token)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment