Class: AtprotoAuth::ServerMetadata::OriginUrl

Inherits:
Object
  • Object
show all
Defined in:
lib/atproto_auth/server_metadata/origin_url.rb

Overview

The ‘OriginUrl` class provides validation logic for URLs that must conform to the AT Protocol OAuth “simple origin URL” requirements. These requirements are common between Resource and Authorization Servers and ensure that the URL is valid and secure for use in the protocol. This class validates that the URL:

  • Uses the HTTPS scheme.

  • Points to the root path (either an empty path or “/”).

  • Does not include a query string or fragment.

  • Does not include user or password credentials.

  • May include a non-default port but disallows the default HTTPS port (443).

This model centralizes the URL validation logic to promote reusability and consistency between different server classes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ OriginUrl

Returns a new instance of OriginUrl.



20
21
22
23
# File 'lib/atproto_auth/server_metadata/origin_url.rb', line 20

def initialize(url)
  @url = url
  @uri = URI(url)
end

Instance Attribute Details

#uriObject (readonly)

Returns the value of attribute uri.



18
19
20
# File 'lib/atproto_auth/server_metadata/origin_url.rb', line 18

def uri
  @uri
end

#urlObject (readonly)

Returns the value of attribute url.



18
19
20
# File 'lib/atproto_auth/server_metadata/origin_url.rb', line 18

def url
  @url
end

Instance Method Details

#valid?Boolean

Determines if a URL conforms to AT Protocol OAuth “simple origin URL” requirements

Returns:

  • (Boolean)

    true if the URL is a valid origin URL



27
28
29
30
31
32
33
34
# File 'lib/atproto_auth/server_metadata/origin_url.rb', line 27

def valid?
  https_scheme? &&
    root_path? &&
    !uri.query &&
    !uri.fragment &&
    !uri.userinfo &&
    (!explicit_port? || uri.port != 443)
end