Module: Rack::OAuth2::Util
- Defined in:
- lib/rack/oauth2/util.rb
Class Method Summary collapse
- .base64_encode(text) ⇒ Object
- .compact_hash(hash) ⇒ Object
- .parse_uri(uri) ⇒ Object
- .redirect_uri(base_uri, location, params) ⇒ Object
- .uri_match?(base, given) ⇒ Boolean
- .urlsafe_base64_encode(text) ⇒ Object
- .www_form_url_decode(text) ⇒ Object
- .www_form_url_encode(text) ⇒ Object
Class Method Details
.base64_encode(text) ⇒ Object
15 16 17 |
# File 'lib/rack/oauth2/util.rb', line 15 def base64_encode(text) Base64.encode64(text).delete("\n") end |
.compact_hash(hash) ⇒ Object
23 24 25 26 27 |
# File 'lib/rack/oauth2/util.rb', line 23 def compact_hash(hash) hash.reject do |key, value| value.blank? end end |
.parse_uri(uri) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rack/oauth2/util.rb', line 29 def parse_uri(uri) case uri when URI::Generic uri when String URI.parse(uri) else raise "Invalid format of URI is given." end end |
.redirect_uri(base_uri, location, params) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rack/oauth2/util.rb', line 40 def redirect_uri(base_uri, location, params) redirect_uri = parse_uri base_uri encoded_response_params = Util.compact_hash(params).to_query.gsub('+', '%20') case location when :query redirect_uri.query = [redirect_uri.query, encoded_response_params].compact.join('&') when :fragment redirect_uri.fragment = encoded_response_params end redirect_uri.to_s end |
.uri_match?(base, given) ⇒ Boolean
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rack/oauth2/util.rb', line 52 def uri_match?(base, given) base = parse_uri(base) given = parse_uri(given) base.path = '/' if base.path.blank? given.path = '/' if given.path.blank? [:scheme, :host, :port].all? do |key| base.send(key) == given.send(key) end && !!(/^#{base.path}/ =~ given.path) rescue false end |
.urlsafe_base64_encode(text) ⇒ Object
19 20 21 |
# File 'lib/rack/oauth2/util.rb', line 19 def urlsafe_base64_encode(text) Base64.urlsafe_encode64(text, padding: false) end |
.www_form_url_decode(text) ⇒ Object
11 12 13 |
# File 'lib/rack/oauth2/util.rb', line 11 def www_form_url_decode(text) URI.decode_www_form_component(text) end |
.www_form_url_encode(text) ⇒ Object
7 8 9 |
# File 'lib/rack/oauth2/util.rb', line 7 def www_form_url_encode(text) URI.encode_www_form_component(text) end |