class Azure::ServiceBus::Auth::WrapSigner

Attributes

tokens[RW]

Public Class Methods

new(host = nil, options={}) click to toggle source
# File lib/azure/service_bus/auth/wrap_signer.rb, line 25
def initialize(host = nil, options={})
  client = (options[:client] || Azure)
  host = host || client.acs_host
  @tokens = {}
  @wrap_service = Azure::ServiceBus::Auth::WrapService.new(host, nil, nil, options)
end

Public Instance Methods

name() click to toggle source
# File lib/azure/service_bus/auth/wrap_signer.rb, line 34
def name
  'WRAP'
end
sign(method, uri, headers) click to toggle source
# File lib/azure/service_bus/auth/wrap_signer.rb, line 45
def sign(method, uri, headers)
  access_token = get_access_token(create_scope_uri(uri))
  'access_token="%s"' % access_token
end
sign_request(req) click to toggle source
# File lib/azure/service_bus/auth/wrap_signer.rb, line 40
def sign_request(req)
  signature = sign(req.method, req.uri, req.headers)
  req.headers['Authorization'] = "#{name} #{signature}"
end

Private Instance Methods

create_scope_uri(target_uri) click to toggle source
# File lib/azure/service_bus/auth/wrap_signer.rb, line 58
def create_scope_uri(target_uri)
  targetUriComponents = URI.parse(target_uri.to_s)

  # ACS body and caching should be HTTP
  targetUriComponents.scheme = 'http'

  # ACS body and caching should not include query
  targetUriComponents.query = nil

  targetUriComponents
end
get_access_token(uri) click to toggle source
# File lib/azure/service_bus/auth/wrap_signer.rb, line 51
def get_access_token(uri)
  token = tokens[uri.to_s]
  token = tokens[uri.to_s] = @wrap_service.get_access_token(uri) unless valid_token?(token)
  token[:token]
end
valid_token?(token) click to toggle source
# File lib/azure/service_bus/auth/wrap_signer.rb, line 71
def valid_token?(token)
  token and token[:expiration] > Time.now.to_i
end