Sha256: af3610fca3c1deef69c36bf37c88c7e7608168065090b06ee6e4d54150d2cbfb

Contents?: true

Size: 729 Bytes

Versions: 6

Compression:

Stored size: 729 Bytes

Contents

require 'uri'

class RedirectUriValidator < ActiveModel::EachValidator
  def self.test_redirect_uri
    Doorkeeper.configuration.test_redirect_uri
  end

  def validate_each(record, attribute, value)
    uri = ::URI.parse(value)
    return if test_redirect_uri?(uri)
    record.errors.add(attribute, :fragment_present) unless uri.fragment.nil?
    record.errors.add(attribute, :relative_uri) if uri.scheme.nil? || uri.host.nil?
    record.errors.add(attribute, :has_query_parameter) unless uri.query.nil?
  rescue URI::InvalidURIError
    record.errors.add(attribute, :invalid_uri)
  end

private

  def test_redirect_uri?(uri)
    self.class.test_redirect_uri.present? && uri.to_s == self.class.test_redirect_uri.to_s
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
doorkeeper-1.0.0.rc1 app/validators/redirect_uri_validator.rb
doorkeeper-0.7.4 app/validators/redirect_uri_validator.rb
doorkeeper-0.7.3 app/validators/redirect_uri_validator.rb
doorkeeper-0.7.2 app/validators/redirect_uri_validator.rb
doorkeeper-0.7.1 app/validators/redirect_uri_validator.rb
doorkeeper-0.7.0 app/validators/redirect_uri_validator.rb