Class: Azure::ServiceBus::Auth::SharedAccessSigner

Inherits:
Core::Auth::Signer
  • Object
show all
Defined in:
lib/azure/service_bus/auth/shared_access_signer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key_name = Azure.sb_sas_key_name, key = Azure.sb_sas_key, expiry_offset = 60*5) ⇒ SharedAccessSigner

Public: Initialize the Signer.

Parameters:

  • key_name (String) (defaults to: Azure.sb_sas_key_name)

    The service bus SAS key name. Defaults to the one in the global configuration.

  • key (String) (defaults to: Azure.sb_sas_key)

    The service bus SAS key encoded in Base64. Defaults to the one in the global configuration.

  • expiry_offset (Integer) (defaults to: 60*5)

    The number of seconds from the time of signature that the SAS token will expire. Defaults to 30 minutes.



16
17
18
19
# File 'lib/azure/service_bus/auth/shared_access_signer.rb', line 16

def initialize(key_name=Azure.sb_sas_key_name, key=Azure.sb_sas_key, expiry_offset = 60*5)
  @access_key = key
  @key_name, @expiry_offset = key_name, expiry_offset
end

Instance Attribute Details

#expiry_offsetObject

The number of seconds from the time of signature that the SAS token will expire



9
10
11
# File 'lib/azure/service_bus/auth/shared_access_signer.rb', line 9

def expiry_offset
  @expiry_offset
end

#key_nameObject

The number of seconds from the time of signature that the SAS token will expire



9
10
11
# File 'lib/azure/service_bus/auth/shared_access_signer.rb', line 9

def key_name
  @key_name
end

Instance Method Details

#nameObject



21
22
23
# File 'lib/azure/service_bus/auth/shared_access_signer.rb', line 21

def name
  'SharedAccessSignature'
end

#sign_request(req) ⇒ Object



32
33
34
# File 'lib/azure/service_bus/auth/shared_access_signer.rb', line 32

def sign_request(req)
  req.headers['Authorization'] = token(req.uri)
end

#token(uri) ⇒ Object



25
26
27
28
29
30
# File 'lib/azure/service_bus/auth/shared_access_signer.rb', line 25

def token(uri)
  url_encoded_resource = CGI.escape(uri.to_s.downcase).gsub('+', '%20').downcase
  expiry = Time.now.to_i + expiry_offset
  sig = CGI.escape(signature(url_encoded_resource, expiry)).gsub('+', '%20')
  "#{name} sig=#{sig}&se=#{expiry}&skn=#{key_name}&sr=#{url_encoded_resource}"
end