module Cerner::OAuth1a::Protocol
Public: OAuth 1.0a protocol utilities.
Constants
- BAD_REQUEST_PROBLEMS
Public: The oauth_problem values that are mapped to HTTP 400 Bad Request. The values come from wiki.oauth.net/w/page/12238543/ProblemReporting and are mapped based on oauth.net/core/1.0/#rfc.section.10.
- UNAUTHORIZED_PROBLEMS
Public: The oauth_problem values that are mapped to HTTP 401 Unauthorized. The values come from wiki.oauth.net/w/page/12238543/ProblemReporting and are mapped based on oauth.net/core/1.0/#rfc.section.10.
Public Class Methods
Public: Converts a oauth_problem value to an HTTP Status using the mappings in ::BAD_REQUEST_PROBLEMS and ::UNAUTHORIZED_PROBLEMS.
problem - A String containing the oauth_problem value. default - An optional Symbol containing the value to return if an
unknown problem value is passed. Defaults to :unauthorized.
Returns :unauthorized, :bad_request or the value passed in the default
parameter.
# File lib/cerner/oauth1a/protocol.rb, line 159 def self.convert_problem_to_http_status(problem, default = :unauthorized) return default unless problem problem = problem.to_s return :unauthorized if UNAUTHORIZED_PROBLEMS.include?(problem) return :bad_request if BAD_REQUEST_PROBLEMS.include?(problem) default end
Public: Alias for Protocol.generate_www_authenticate_header
Public: Parses a URL-encoded query string into a Hash with symbolized keys.
query - String containing a URL-encoded query string to parse.
Returns a Hash with symbolized keys matching the query parameter names.
Raises ArgumentError if query is nil.
# File lib/cerner/oauth1a/protocol.rb, line 28 def self.parse_url_query_string(query) raise ArgumentError, 'query is nil' unless query Hash[URI.decode_www_form(query).map { |pair| [pair[0].to_sym, pair[1]] }] end
Public: Alias for Protocol.parse_authorization_header
Public: Encodes the passed text using the percent encoding variant described in the OAuth 1.0a specification.
Reference: tools.ietf.org/html/rfc5849#section-3.6
text - A String containing the text to encode.
Returns a String that has been encoded.
# File lib/cerner/oauth1a/protocol.rb, line 17 def self.percent_encode(text) URI.encode_www_form_component(text).gsub('+', '%20') end
Public: Returns a String containing a realm value from the URI. The String will be a rooted (path removed) and canonicalized URL of the URL passed.
uri - A URI instance containing the URL to construct the realm for.
Returns a String containing the realm value.
Raises ArgumentError if uri is nil.
# File lib/cerner/oauth1a/protocol.rb, line 180 def self.realm_for(uri) raise ArgumentError, 'uri is nil' unless uri realm = URI("#{uri.scheme}://#{uri.host}:#{uri.port}") realm.to_s end