Module: OAuthenticator
- Extended by:
- RackTestSigner
- Defined in:
- lib/oauthenticator/version.rb,
lib/oauthenticator/config_methods.rb,
lib/oauthenticator/faraday_signer.rb,
lib/oauthenticator/signed_request.rb,
lib/oauthenticator/rack_test_signer.rb,
lib/oauthenticator/signable_request.rb,
lib/oauthenticator/rack_authenticator.rb,
lib/oauthenticator/parse_authorization.rb
Overview
OAuthenticator
Defined Under Namespace
Modules: ConfigMethods, RackTestSigner Classes: DuplicatedParameters, Error, FaradaySigner, NonceUsedError, ParseError, RackAuthenticator, SignableRequest, SignedRequest
Constant Summary collapse
- VERSION =
OAuthenticator::VERSION
"1.4.1"
- URI_PARSER =
URI.const_defined?(:DEFAULT_PARSER) ? URI::DEFAULT_PARSER : URI
Class Method Summary collapse
-
.escape(value) ⇒ String
escape a value.
-
.parse_authorization(header) ⇒ Hash<String, String>
Parsed authorization parameters.
-
.unescape(value) ⇒ String
unescape a value.
Methods included from RackTestSigner
Class Method Details
.escape(value) ⇒ String
escape a value
66 67 68 |
# File 'lib/oauthenticator/parse_authorization.rb', line 66 def escape(value) URI_PARSER.escape(value.to_s, /[^a-z0-9\-\.\_\~]/i) end |
.parse_authorization(header) ⇒ Hash<String, String>
Returns parsed authorization parameters.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/oauthenticator/parse_authorization.rb', line 32 def (header) header = header.to_s scanner = StringScanner.new(header) auth_parse_error = proc { || raise ParseError.new(, {'Authorization' => []}) } scanner.scan(/OAuth\s*/i) || auth_parse_error.call("Authorization scheme is not OAuth - received: #{header}") attributes = {} while scanner.scan(/(\w+)="([^"]*)"\s*(,?)\s*/) key = scanner[1] value = scanner[2] comma_follows = !scanner[3].empty? if !comma_follows && !scanner.eos? auth_parse_error.call("Could not parse Authorization header: #{header}\naround or after character #{scanner.pos}: #{scanner.rest}") end (attributes[unescape(key)] ||= []) << unescape(value) end unless scanner.eos? auth_parse_error.call("Could not parse Authorization header: #{header}\naround or after character #{scanner.pos}: #{scanner.rest}") end duplicates = attributes.reject { |k,v| v.size <= 1 } if duplicates.any? errors = duplicates.map do |k,vs| {k => ["Received multiple instances of Authorization parameter #{k}. Received values were: #{vs.inspect}"]} end.inject({}, &:update) raise DuplicatedParameters.new("Received duplicate parameters: #{duplicates.keys.inspect}", errors) end return attributes.map { |k,v| {k => v.first} }.inject({}, &:update) end |
.unescape(value) ⇒ String
unescape a value
73 74 75 |
# File 'lib/oauthenticator/parse_authorization.rb', line 73 def unescape(value) URI_PARSER.unescape(value.to_s) end |