Class: Zitadel::Client::Auth::OpenId

Inherits:
Object
  • Object
show all
Defined in:
lib/zitadel/client/auth/open_id.rb

Overview

OpenId retrieves OpenID Connect configuration from a given host.

It builds the well-known configuration URL from the provided hostname, fetches the configuration, and extracts the token endpoint.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hostname) ⇒ OpenId

Initializes a new OpenId instance.

noinspection HttpUrlsUsage

Parameters:

  • hostname (String)

    the hostname for the OpenID provider.

Raises:

  • (RuntimeError)

    if the OpenID configuration cannot be fetched or the token_endpoint is missing.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/zitadel/client/auth/open_id.rb', line 26

def initialize(hostname)
  hostname = "https://#{hostname}" unless hostname.start_with?('http://', 'https://')
  @host_endpoint = hostname
  well_known_url = self.class.build_well_known_url(hostname)

  uri = URI.parse(well_known_url)
  response = Net::HTTP.get_response(uri)
  raise "Failed to fetch OpenID configuration: HTTP #{response.code}" unless response.code.to_i == 200

  config = JSON.parse(response.body)
  token_endpoint = config['token_endpoint']
  raise 'token_endpoint not found in OpenID configuration' unless token_endpoint

  @token_endpoint = token_endpoint
end

Instance Attribute Details

#host_endpointObject

Returns the value of attribute host_endpoint.



17
18
19
# File 'lib/zitadel/client/auth/open_id.rb', line 17

def host_endpoint
  @host_endpoint
end

#token_endpointObject

Returns the value of attribute token_endpoint.



17
18
19
# File 'lib/zitadel/client/auth/open_id.rb', line 17

def token_endpoint
  @token_endpoint
end

Class Method Details

.build_well_known_url(hostname) ⇒ String

Builds the well-known OpenID configuration URL for the given hostname.

Parameters:

  • hostname (String)

    the hostname for the OpenID provider.

Returns:

  • (String)

    the well-known configuration URL.



48
49
50
# File 'lib/zitadel/client/auth/open_id.rb', line 48

def self.build_well_known_url(hostname)
  URI.join(hostname, '/.well-known/openid-configuration').to_s
end