Sha256: 3789ccf58cd7ed072009513ac1400091ccfbb975b2f62d04f36dda8a338f5a3a

Contents?: true

Size: 1.03 KB

Versions: 6

Compression:

Stored size: 1.03 KB

Contents

module Rack
  module OAuth2
    class Server

      module Utils
        module_function

        # Parses the redirect URL, normalizes it and returns a URI object.
        #
        # Raises InvalidRequestError if not an absolute HTTP/S URL.
        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
          raise InvalidRequestError, "Redirect URL must point to HTTP/S location" unless uri.scheme == "http" || uri.scheme == "https"
          uri
        end

        # Given scope as either array or string, return array of same names,
        # unique and sorted.
        def normalize_scope(scope)
          (Array === scope ? scope.join(" ") : scope || "").split(/\s+/).compact.uniq.sort
        end

      end

    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
tpitale-rack-oauth2-server-2.2.1.2 lib/rack/oauth2/server/utils.rb
tpitale-rack-oauth2-server-2.2.1.1 lib/rack/oauth2/server/utils.rb
tpitale-rack-oauth2-server-2.2.1 lib/rack/oauth2/server/utils.rb
rack-oauth2-server-2.2.1 lib/rack/oauth2/server/utils.rb
rack-oauth2-server-2.2.0 lib/rack/oauth2/server/utils.rb
rack-oauth2-server-2.1.0 lib/rack/oauth2/server/utils.rb