Module: Ey::Hmac
- Defined in:
- lib/ey-hmac/version.rb,
lib/ey-hmac.rb
Defined Under Namespace
Classes: Adapter, Faraday, Rack
Constant Summary collapse
- VERSION =
'2.4.0'
- Error =
Class.new(StandardError)
- MissingSecret =
Class.new(Error)
- MissingAuthorization =
Class.new(Error)
- SignatureMismatch =
Class.new(Error)
- ExpiredHmac =
Class.new(Error)
Class Method Summary collapse
-
.authenticate!(request, options = {}) {|key_id| ... } ⇒ TrueClass
Check Adapter#authorization_signature against calculated Adapter#signature.
-
.authenticated?(request, options = {}) {|key_id| ... } ⇒ Boolean
Success of authentication.
- .default_adapter ⇒ Object
- .default_adapter=(default_adapter) ⇒ Object
-
.sign!(request, key_id, key_secret, options = {}) ⇒ String
Signs request by calculating signature and adding it to the specified header.
Class Method Details
.authenticate!(request, options = {}) {|key_id| ... } ⇒ TrueClass
Check Ey::Hmac::Adapter#authorization_signature against calculated Ey::Hmac::Adapter#signature
95 96 97 98 99 100 101 |
# File 'lib/ey-hmac.rb', line 95 def self.authenticate!(request, = {}, &block) adapter = [:adapter] || Ey::Hmac.default_adapter raise ArgumentError, 'Missing adapter and Ey::Hmac.default_adapter' unless adapter adapter.new(request, ).authenticate!(&block) end |
.authenticated?(request, options = {}) {|key_id| ... } ⇒ Boolean
Returns success of authentication.
69 70 71 72 73 74 75 |
# File 'lib/ey-hmac.rb', line 69 def self.authenticated?(request, = {}, &block) adapter = [:adapter] || Ey::Hmac.default_adapter raise ArgumentError, 'Missing adapter and Ey::Hmac.default_adapter' unless adapter adapter.new(request, ).authenticated?(&block) end |
.default_adapter ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/ey-hmac.rb', line 26 def self.default_adapter @default_adapter ||= if defined?(::Rack) || defined?(::Rails) Ey::Hmac::Adapter::Rack elsif defined?(::Faraday) Ey::Hmac::Adapter::Faraday end end |
.default_adapter=(default_adapter) ⇒ Object
22 23 24 |
# File 'lib/ey-hmac.rb', line 22 def self.default_adapter=(default_adapter) @default_adapter = default_adapter end |
.sign!(request, key_id, key_secret, options = {}) ⇒ String
Signs request by calculating signature and adding it to the specified header
47 48 49 50 51 52 53 |
# File 'lib/ey-hmac.rb', line 47 def self.sign!(request, key_id, key_secret, = {}) adapter = [:adapter] || Ey::Hmac.default_adapter raise ArgumentError, 'Missing adapter and Ey::Hmac.default_adapter' unless adapter adapter.new(request, ).sign!(key_id, key_secret) end |