Module: Rack::OAuth2::Server::Utils

Defined in:
lib/rack/oauth2/server/utils.rb

Class Method Summary collapse

Class Method Details

.normalize_scope(scope) ⇒ Object

Given scope as either array or string, return array of same names, unique and sorted.



21
22
23
# File 'lib/rack/oauth2/server/utils.rb', line 21

def normalize_scope(scope)
  (Array === scope ? scope.join(" ") : scope || "").split(/\s+/).compact.uniq.sort
end

.parse_redirect_uri(redirect_uri) ⇒ Object

Parses the redirect URL, normalizes it and returns a URI object.

Raises InvalidRequestError if not an absolute HTTP/S URL.



11
12
13
14
15
16
17
# File 'lib/rack/oauth2/server/utils.rb', line 11

def parse_redirect_uri(redirect_uri)
  raise InvalidRequestError, "Missing redirect URL" unless redirect_uri
  uri = URI.parse(redirect_uri).normalize rescue nil
  raise InvalidRequestError, "Redirect URL looks fishy to me" unless uri
  raise InvalidRequestError, "Redirect URL must be absolute URL" unless uri.absolute? && uri.host
  uri
end