Class: Uploadcare::Internal::Authenticator
- Inherits:
-
Object
- Object
- Uploadcare::Internal::Authenticator
- Defined in:
- lib/uploadcare/internal/authenticator.rb
Overview
Handles authentication for Uploadcare REST API requests.
Supports two authentication modes:
- Simple authentication: Basic auth with public_key:secret_key
- Secure authentication: signature-based authentication
Constant Summary collapse
- BODY_DIGEST_NAME =
'MD5'- SIGNATURE_DIGEST_NAME =
'SHA1'
Instance Attribute Summary collapse
-
#default_headers ⇒ Hash
readonly
Default headers included in all requests.
Instance Method Summary collapse
-
#headers(http_method, uri, body = '', content_type = nil) ⇒ Hash
Generate authentication headers for an API request.
-
#initialize(config:) ⇒ Authenticator
constructor
Initialize a new Authenticator.
Constructor Details
#initialize(config:) ⇒ Authenticator
Initialize a new Authenticator.
27 28 29 30 31 32 33 |
# File 'lib/uploadcare/internal/authenticator.rb', line 27 def initialize(config:) @config = config @default_headers = { 'Accept' => 'application/vnd.uploadcare-v0.7+json', 'User-Agent' => Uploadcare::Internal::UserAgent.call(config: config) } end |
Instance Attribute Details
#default_headers ⇒ Hash (readonly)
Returns Default headers included in all requests.
22 23 24 |
# File 'lib/uploadcare/internal/authenticator.rb', line 22 def default_headers @default_headers end |
Instance Method Details
#headers(http_method, uri, body = '', content_type = nil) ⇒ Hash
Generate authentication headers for an API request.
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/uploadcare/internal/authenticator.rb', line 43 def headers(http_method, uri, body = '', content_type = nil) resolved_content_type = content_type || 'application/json' raise Uploadcare::Exception::AuthError, 'Secret Key is blank.' if @config.secret_key.to_s.empty? validate_public_key return simple_auth_headers(resolved_content_type) if @config.auth_type == 'Uploadcare.Simple' secure_auth_headers(http_method, uri, body, resolved_content_type) end |