class Atompub::Auth::Wsse

Atompub::Auth::Wsse

Class handles WSSE authentication All you have to do is create this class's object with username and password, and pass to Atompub::Client#new

Usage:

auth = Atompub::Auth::Wsse.new :username => username, :password => password
client = Atompub::Client.new :auth => auth

Public Class Methods

new(params) click to toggle source

initializer

Set two parameters as hash

  • username

  • password

Usage:

auth = Atompub::Auth::Wsse.new :username => name, :password => pass
# File lib/atomutil.rb, line 1684
def initialize(params)
  @username, @password = params[:username], params[:password]
end

Public Instance Methods

authorize(req) click to toggle source

Add credential info to Net::HTTP::Request object

Usaage:

req = Net::HTTP::Get.new uri.request_uri
auth.authorize(req)
# File lib/atomutil.rb, line 1694
def authorize(req)
  req['Authorization'] = 'WSSE profile="UsernameToken"'
  req['X-Wsse'] = gen_token
end

Private Instance Methods

gen_token() click to toggle source

Generate username token for WSSE authentication

# File lib/atomutil.rb, line 1700
def gen_token
  nonce = Array.new(10){rand(0x100000000)}.pack('I*')
  nonce_base64 = [nonce].pack('m').chomp
  now = Time.now.utc.iso8601
  digest = [Digest::SHA1.digest(nonce + now + @password)].pack('m').chomp
  sprintf(%Q<UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s">,
    @username, digest, nonce_base64, now)
end