Class: NinjaRMM::SignRequestMiddleware
- Inherits:
-
Struct
- Object
- Struct
- NinjaRMM::SignRequestMiddleware
- Defined in:
- lib/ninjarmm/sign_request_middleware.rb
Instance Attribute Summary collapse
-
#access_id ⇒ Object
Returns the value of attribute access_id.
-
#app ⇒ Object
Returns the value of attribute app.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
Instance Method Summary collapse
Instance Attribute Details
#access_id ⇒ Object
Returns the value of attribute access_id
5 6 7 |
# File 'lib/ninjarmm/sign_request_middleware.rb', line 5 def access_id @access_id end |
#app ⇒ Object
Returns the value of attribute app
5 6 7 |
# File 'lib/ninjarmm/sign_request_middleware.rb', line 5 def app @app end |
#secret_key ⇒ Object
Returns the value of attribute secret_key
5 6 7 |
# File 'lib/ninjarmm/sign_request_middleware.rb', line 5 def secret_key @secret_key end |
Instance Method Details
#call(env) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ninjarmm/sign_request_middleware.rb', line 6 def call(env) # establish necessary variables http_method = env[:method].to_s.upcase time_stamp = Time.now.httpdate canonical_resource = env[:url].to_s.delete_prefix(Client::BASE_URL) # define our required string format string = "#{http_method}\n\n\n#{time_stamp}\n#{canonical_resource}" # process string string_base64 = Base64.strict_encode64(string) string_hash = OpenSSL::HMAC.digest('SHA1', secret_key, string_base64) hash_base64 = Base64.strict_encode64(string_hash) # add processed string and time to request headers env[:request_headers].merge!( Authorization: "NJ #{access_id}:#{hash_base64}", Date: time_stamp.to_s ) app.call env end |