Created
February 20, 2010 15:40
-
-
Save johnnyhalife/309732 to your computer and use it in GitHub Desktop.
Rack::Auth::WRAP protected resource client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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