Module: OAuthenticator
- Defined in:
- lib/oauthenticator/version.rb,
lib/oauthenticator/config_methods.rb,
lib/oauthenticator/faraday_signer.rb,
lib/oauthenticator/signed_request.rb,
lib/oauthenticator/signable_request.rb,
lib/oauthenticator/rack_authenticator.rb,
lib/oauthenticator/parse_authorization.rb
Overview
OAuthenticator
Defined Under Namespace
Modules: ConfigMethods Classes: DuplicatedParameters, Error, FaradaySigner, ParseError, RackAuthenticator, SignableRequest, SignedRequest
Constant Summary collapse
- VERSION =
OAuthenticator::VERSION
"1.0.0"
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.
Class Method Details
.escape(value) ⇒ String
escape a value
63 64 65 |
# File 'lib/oauthenticator/parse_authorization.rb', line 63 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 - recieved: #{header}") attributes = Hash.new { |h,k| h[k] = [] } while match = 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.select { |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
70 71 72 |
# File 'lib/oauthenticator/parse_authorization.rb', line 70 def unescape(value) uri_parser.unescape(value.to_s) end |