Class: SimpleOAuth::Header
- Inherits:
-
Object
- Object
- SimpleOAuth::Header
- Extended by:
- Encoding, ClassMethods
- Defined in:
- lib/simple_oauth/header.rb,
lib/simple_oauth/header/class_methods.rb
Overview
Generates OAuth 1.0 Authorization headers for HTTP requests
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- OAUTH_SCHEME =
OAuth header scheme prefix
"OAuth".freeze
- OAUTH_PREFIX =
Prefix for OAuth parameters
"oauth_".freeze
- DEFAULT_SIGNATURE_METHOD =
Default signature method per RFC 5849
"HMAC-SHA1".freeze
- OAUTH_VERSION =
OAuth version
"1.0".freeze
- ATTRIBUTE_KEYS =
Valid OAuth attribute keys that can be included in the header
i[body_hash callback consumer_key nonce signature_method token verifier version].freeze
- IGNORED_KEYS =
Keys that are used internally but should not appear in attributes
i[consumer_secret token_secret signature realm ignore_extra_keys].freeze
- PARSE_KEYS =
Valid keys when parsing OAuth parameters (ATTRIBUTE_KEYS + signature)
[*ATTRIBUTE_KEYS, :signature].freeze
Constants included from Encoding
Instance Attribute Summary collapse
-
#body ⇒ String?
readonly
The raw request body for oauth_body_hash computation.
-
#method ⇒ String
readonly
The HTTP method for the request.
-
#options ⇒ Hash
readonly
The OAuth options including credentials and signature.
-
#params ⇒ Hash
readonly
The request parameters to be signed.
Instance Method Summary collapse
-
#initialize(method, url, params, oauth = {}, body = nil) ⇒ Header
constructor
Creates a new OAuth header.
-
#signed_attributes ⇒ Hash
Returns the OAuth attributes including the signature.
-
#to_s ⇒ String
Returns the OAuth Authorization header string.
-
#url ⇒ String
Returns the normalized URL without query string or fragment.
-
#valid?(secrets = {}) ⇒ Boolean
Validates the signature in the header against the provided secrets.
Methods included from ClassMethods
body_hash, default_options, parse, parse_form_body
Methods included from Encoding
Constructor Details
#initialize(method, url, params, oauth = {}, body = nil) ⇒ Header
Creates a new OAuth header
82 83 84 85 86 87 88 |
# File 'lib/simple_oauth/header.rb', line 82 def initialize(method, url, params, oauth = {}, body = nil) @method = method.to_s.upcase @uri = normalize_uri(url) @params = params @body = body = (oauth, body) end |
Instance Attribute Details
#body ⇒ String? (readonly)
The raw request body for oauth_body_hash computation
54 55 56 |
# File 'lib/simple_oauth/header.rb', line 54 def body @body end |
#method ⇒ String (readonly)
The HTTP method for the request
40 41 42 |
# File 'lib/simple_oauth/header.rb', line 40 def method @method end |
#options ⇒ Hash (readonly)
The OAuth options including credentials and signature
61 62 63 |
# File 'lib/simple_oauth/header.rb', line 61 def end |
#params ⇒ Hash (readonly)
The request parameters to be signed
47 48 49 |
# File 'lib/simple_oauth/header.rb', line 47 def params @params end |
Instance Method Details
#signed_attributes ⇒ Hash
Returns the OAuth attributes including the signature
139 140 141 |
# File 'lib/simple_oauth/header.rb', line 139 def signed_attributes header_attributes.merge(oauth_signature: signature) end |
#to_s ⇒ String
Returns the OAuth Authorization header string
111 112 113 |
# File 'lib/simple_oauth/header.rb', line 111 def to_s "#{OAUTH_SCHEME} #{normalized_attributes}" end |
#url ⇒ String
Returns the normalized URL without query string or fragment
98 99 100 |
# File 'lib/simple_oauth/header.rb', line 98 def url @uri.dup.tap { |uri| uri.query = nil }.to_str end |
#valid?(secrets = {}) ⇒ Boolean
Validates the signature in the header against the provided secrets
124 125 126 127 128 129 130 |
# File 'lib/simple_oauth/header.rb', line 124 def valid?(secrets = {}) = .dup #: Hash[Symbol, untyped] .merge!(secrets) .fetch(:signature).eql?(signature) ensure .replace() end |