class Azure::ServiceBus::Auth::WrapService

Public Class Methods

new(host=Azure.config.acs_host, issuer=Azure.config.sb_issuer, access_key=Azure.config.sb_access_key) click to toggle source
Calls superclass method Azure::Core::FilteredService::new
# File lib/azure/service_bus/auth/wrap_service.rb, line 23
def initialize(host=Azure.config.acs_host, issuer=Azure.config.sb_issuer, access_key=Azure.config.sb_access_key)
  super(host)
  @issuer = issuer
  @access_key = access_key
end

Public Instance Methods

get_access_token(resource_uri) click to toggle source

Gets a WRAP access token with specified parameters.

Returns access token (String)

# File lib/azure/service_bus/auth/wrap_service.rb, line 32
def get_access_token(resource_uri)
    uri = wrap_uri

    body = get_wrap_acs_body(resource_uri)

    headers = {
      "Content-Type" => "application/x-www-form-urlencoded",
      "Content-Length" => "0"
    }

    response = call(:post, uri, body, headers)
    parse_token(response.body)
end
get_wrap_acs_body(resource_uri) click to toggle source

Generate the wrap ACS body for the given uri as a String

resource_uri - The resource URI

Returns a url-encoded String

# File lib/azure/service_bus/auth/wrap_service.rb, line 51
def get_wrap_acs_body(resource_uri)
  non_ssl_uri = resource_uri.dup
  non_ssl_uri.scheme = 'http'
  params = {
    :wrap_scope => non_ssl_uri.to_s,
    :wrap_name => @issuer,
    :wrap_password => @access_key
  }
  ::URI.encode_www_form(params)
end
parse_token(body) click to toggle source
# File lib/azure/service_bus/auth/wrap_service.rb, line 75
def parse_token(body)
  begin
    decoded = URI.decode_www_form(body.strip)
    token = decoded.assoc("wrap_access_token").last

    expires_in = decoded.assoc("wrap_access_token_expires_in").last.to_i
    return { :token => token, :expiration => Time.now.to_i + expires_in / 2 }
  rescue => e
    raise "Cannot get the access token from returned string: %s" % body
  end
end
wrap_uri(path="WRAPv0.9", query={}) click to toggle source

Generate the URI for the ACS Wrap service

path - String. Path for the uri (optional, Default=“WRAPv0.9”) query - Hash. Query parameters for the uri (optional)

Returns a URI.

# File lib/azure/service_bus/auth/wrap_service.rb, line 68
def wrap_uri(path="WRAPv0.9", query={})
  query = query || {}
  uri = URI.parse(File.join(host, path))
  uri.query = URI.encode_www_form(query) unless query.empty?
  uri
end