module Signet::OAuth2
An implementation of tools.ietf.org/html/draft-ietf-oauth-v2-10
This module will be updated periodically to support newer drafts of the specification, as they become widely deployed.
Public Class Methods
parse_basic_credentials(credential_string)
click to toggle source
# File lib/signet/oauth_2.rb, line 54 def self.parse_basic_credentials(credential_string) decoded = Base64.decode64(credential_string) client_id, client_secret = decoded.split(':', 2) return [['client_id', client_id], ['client_secret', client_secret]] end
parse_bearer_credentials(credential_string)
click to toggle source
# File lib/signet/oauth_2.rb, line 60 def self.parse_bearer_credentials(credential_string) access_token = credential_string[/^([^,\s]+)(?:\s|,|$)/i, 1] parameters = [] parameters << ['access_token', access_token] auth_param_string = credential_string[/^(?:[^,\s]+)\s*,\s*(.*)$/i, 1] if auth_param_string # This code will rarely get called, but is included for completeness parameters.concat(Signet.parse_auth_param_list(auth_param_string)) end return parameters end
parse_credentials(body, content_type)
click to toggle source
# File lib/signet/oauth_2.rb, line 76 def self.parse_credentials(body, content_type) if !body.kind_of?(String) raise TypeError, "Expected String, got #{body.class}." end case content_type when /^application\/json.*/ return MultiJson.load(body) when /^application\/x-www-form-urlencoded.*/ return Hash[Addressable::URI.form_unencode(body)] else raise ArgumentError, "Invalid content type '#{content_type}'" end end
parse_oauth_challenge(challenge_string)
click to toggle source
# File lib/signet/oauth_2.rb, line 72 def self.parse_oauth_challenge(challenge_string) return Signet.parse_auth_param_list(challenge_string) end
parse_www_authenticate_header(field_value)
click to toggle source
# File lib/signet/oauth_2.rb, line 42 def self.parse_www_authenticate_header(field_value) auth_scheme = field_value[/^([-._0-9a-zA-Z]+)/, 1] case auth_scheme when /^OAuth$/i # Other token types may be supported eventually return self.parse_oauth_challenge(field_value[/^OAuth\s+(.*)$/i, 1]) else raise ParseError, 'Parsing non-OAuth WWW-Authenticate headers is out of scope.' end end