Class: Shmac::Authentication
- Inherits:
-
Object
- Object
- Shmac::Authentication
- Includes:
- Comparable
- Defined in:
- lib/shmac/authentication.rb
Instance Attribute Summary collapse
-
#header_namespace ⇒ Object
readonly
Returns the value of attribute header_namespace.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
Class Method Summary collapse
- .generate_authorization_header(request, secret:, access_key:, organization:, header_namespace: nil) ⇒ Object
- .generate_signature(request, secret:, header_namespace: nil) ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
- #authentic? ⇒ Boolean
-
#initialize(secret, request, header_namespace: nil, request_adapter: nil) ⇒ Authentication
constructor
A new instance of Authentication.
- #request ⇒ Object
- #request_adapter ⇒ Object
- #signature ⇒ Object
Constructor Details
#initialize(secret, request, header_namespace: nil, request_adapter: nil) ⇒ Authentication
Returns a new instance of Authentication.
22 23 24 25 26 27 |
# File 'lib/shmac/authentication.rb', line 22 def initialize secret, request, header_namespace: nil, request_adapter: nil @secret = secret @request = request @request_adapter = request_adapter @header_namespace = header_namespace end |
Instance Attribute Details
#header_namespace ⇒ Object (readonly)
Returns the value of attribute header_namespace.
8 9 10 |
# File 'lib/shmac/authentication.rb', line 8 def header_namespace @header_namespace end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
8 9 10 |
# File 'lib/shmac/authentication.rb', line 8 def secret @secret end |
Class Method Details
.generate_authorization_header(request, secret:, access_key:, organization:, header_namespace: nil) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/shmac/authentication.rb', line 10 def self. request, secret:, access_key:, organization:, header_namespace: nil AuthorizationHeader.generate( organization: organization, access_key: access_key, signature: self.generate_signature(request, secret: secret, header_namespace: header_namespace) ).to_s end |
.generate_signature(request, secret:, header_namespace: nil) ⇒ Object
18 19 20 |
# File 'lib/shmac/authentication.rb', line 18 def self.generate_signature request, secret:, header_namespace: nil new(secret, request, header_namespace: header_namespace).signature end |
Instance Method Details
#==(other) ⇒ Object
29 30 31 |
# File 'lib/shmac/authentication.rb', line 29 def == other other.is_a?(self.class) && self.signature == other.signature end |
#authentic? ⇒ Boolean
41 42 43 44 45 |
# File 'lib/shmac/authentication.rb', line 41 def authentic? return false if request..to_s.strip.empty? AuthorizationHeader.new(request.).signature == self.signature end |
#request ⇒ Object
47 48 49 |
# File 'lib/shmac/authentication.rb', line 47 def request request_adapter.call @request end |
#request_adapter ⇒ Object
51 52 53 |
# File 'lib/shmac/authentication.rb', line 51 def request_adapter @request_adapter ||= ->(r) { r } end |
#signature ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/shmac/authentication.rb', line 33 def signature SignatureCalculator.new( secret: self.secret, request: self.request, header_namespace: self.header_namespace ).to_s end |