Class: RedirectUriValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
app/validators/redirect_uri_validator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.native_redirect_uriObject


4
5
6
# File 'app/validators/redirect_uri_validator.rb', line 4

def self.native_redirect_uri
  Doorkeeper.configuration.native_redirect_uri
end

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/validators/redirect_uri_validator.rb', line 8

def validate_each(record, attribute, value)
  if value.blank?
    record.errors.add(attribute, :blank)
  else
    value.split.each do |val|
      uri = ::URI.parse(val)
      return if native_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, :secured_uri) if invalid_ssl_uri?(uri)
    end
  end
rescue URI::InvalidURIError
  record.errors.add(attribute, :invalid_uri)
end