Class: MicrosoftKiotaAbstractions::AllowedHostsValidator
- Inherits:
-
Object
- Object
- MicrosoftKiotaAbstractions::AllowedHostsValidator
- Defined in:
- lib/microsoft_kiota_abstractions/authentication/allowed_hosts_validator.rb
Overview
Maintains a list of valid hosts and allows authentication providers to check whether a host is valid before authenticating a request
Instance Attribute Summary collapse
-
#allowed_hosts ⇒ Object
gets the list of valid hosts.
Instance Method Summary collapse
-
#initialize(allowed_hosts) ⇒ AllowedHostsValidator
constructor
creates a new AllocatedHostsValidator with provided values.
-
#url_host_valid?(url) ⇒ Boolean
checks whether the provided host is valid.
Constructor Details
#initialize(allowed_hosts) ⇒ AllowedHostsValidator
creates a new AllocatedHostsValidator with provided values
10 11 12 13 |
# File 'lib/microsoft_kiota_abstractions/authentication/allowed_hosts_validator.rb', line 10 def initialize(allowed_hosts) @allowed_hosts = {} allowed_hosts.each { |host| @allowed_hosts[host.downcase] = true } end |
Instance Attribute Details
#allowed_hosts ⇒ Object
gets the list of valid hosts
37 38 39 |
# File 'lib/microsoft_kiota_abstractions/authentication/allowed_hosts_validator.rb', line 37 def allowed_hosts @allowed_hosts end |
Instance Method Details
#url_host_valid?(url) ⇒ Boolean
checks whether the provided host is valid
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/microsoft_kiota_abstractions/authentication/allowed_hosts_validator.rb', line 22 def url_host_valid?(url) return true if @allowed_hosts.empty? parsed_url = URI(url) return false if parsed_url.host.nil? return false unless parsed_url.is_a?(URI::HTTPS) @allowed_hosts.key? parsed_url.host.downcase rescue URI::InvalidURIError false end |