module OAuth2Client::UrlHelper
Public Class Methods
http_basic_encode(username, password)
click to toggle source
# File lib/oauth2-client/helper.rb, line 31 def http_basic_encode(username, password) encoded_data = ["#{username}:#{password}"].pack("m0") "Basic #{encoded_data}" end
Public Instance Methods
build_url(uri, opts={})
click to toggle source
convenience method to build response URI
# File lib/oauth2-client/helper.rb, line 7 def build_url(uri, opts={}) path = opts[:path] || '' query = opts[:params] || {} fragment = opts[:fragment] || {} url = Addressable::URI.parse uri url.path = path url.query_values = query unless query.empty? url.fragment = Addressable::URI.form_encode(fragment) unless fragment.empty? url.to_s end
generate_urlsafe_key(size=48)
click to toggle source
generates a random key of up to size
bytes. The value returned is Base64 encoded with non-word characters removed.
# File lib/oauth2-client/helper.rb, line 20 def generate_urlsafe_key(size=48) seed = Time.now.to_i size = size - seed.to_s.length Base64.encode64("#{ OpenSSL::Random.random_bytes(size) }#{ seed }").gsub(/\W/, '') end
Also aliased as: generate_nonce
to_query(params)
click to toggle source
converts a hash to a URI query string @params [Hash] params URI parameters
# File lib/oauth2-client/helper.rb, line 39 def to_query(params) unless params.is_a?(Hash) raise "Expected Hash but got #{params.class.name}" end Addressable::URI.form_encode(params) end
Private Instance Methods
http_basic_encode(username, password)
click to toggle source
# File lib/oauth2-client/helper.rb, line 31 def http_basic_encode(username, password) encoded_data = ["#{username}:#{password}"].pack("m0") "Basic #{encoded_data}" end