Class: Azure::ServiceBus::Auth::SharedAccessSigner
- Inherits:
-
Core::Auth::Signer
- Object
- Core::Auth::Signer
- Azure::ServiceBus::Auth::SharedAccessSigner
- Defined in:
- lib/azure/service_bus/auth/shared_access_signer.rb
Instance Attribute Summary collapse
-
#expiry_offset ⇒ Object
The number of seconds from the time of signature that the SAS token will expire.
-
#key_name ⇒ Object
The number of seconds from the time of signature that the SAS token will expire.
Instance Method Summary collapse
-
#initialize(key_name = Azure.sb_sas_key_name, key = Azure.sb_sas_key, expiry_offset = 60*5) ⇒ SharedAccessSigner
constructor
Public: Initialize the Signer.
- #name ⇒ Object
- #sign_request(req) ⇒ Object
- #token(uri) ⇒ Object
Constructor Details
#initialize(key_name = Azure.sb_sas_key_name, key = Azure.sb_sas_key, expiry_offset = 60*5) ⇒ SharedAccessSigner
Public: Initialize the Signer.
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_offset ⇒ Object
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_name ⇒ Object
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
#name ⇒ Object
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 |