Sha256: d5da817cc2308c71a655d9f907119767b1c566852bb53c165d0454c2b54f6f2a

Contents?: true

Size: 965 Bytes

Versions: 5

Compression:

Stored size: 965 Bytes

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)
          uri = URI.parse(redirect_uri).normalize
          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
        rescue
          raise InvalidRequestError, "Redirect URL looks fishy to me"
        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

5 entries across 5 versions & 1 rubygems

Version Path
rack-oauth2-server-2.0.1 lib/rack/oauth2/server/utils.rb
rack-oauth2-server-2.0.0 lib/rack/oauth2/server/utils.rb
rack-oauth2-server-2.0.0.beta6 lib/rack/oauth2/server/utils.rb
rack-oauth2-server-2.0.0.beta5 lib/rack/oauth2/server/utils.rb
rack-oauth2-server-2.0.0.beta4 lib/rack/oauth2/server/utils.rb