Module: Hecks::Ports::Authentication

Defined in:
lib/hecks/ports/authentication.rb

Overview

THE OIDC HANDSHAKE ITSELF — building the URL a browser goes to, and turning the code a provider sends back into a verified (issuer, subject, email) triple. Resolved the same way every other port here resolves its adapter: one adapter registry-wide answers this, not a per-aggregate binding, since a domain has no reason to want a different sign-in provider per aggregate.

THE OTHER HALF of "who is this" — what a verified pair MEANS to this app, whether it resolves to an existing Identity — is Ports::IdentityResolution's job, not this one's. This port only ever talks to the external provider; it never touches the registry's own Identity/Governance data (it takes registry purely to resolve which adapter answers it, same as every port here already does).

Constant Summary collapse

NAME =
"authentication"
ValidationError =
Class.new(StandardError)

Class Method Summary collapse

Class Method Details

.adapter(registry) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/hecks/ports/authentication.rb', line 34

def adapter(registry)
  implementations = registry.adapters.values.select { |a| a.port == NAME }

  case implementations.size
  when 1 then Adapters.const_get(implementations.first.name)
  when 0
    raise Runtime::WiringError,
          "no adapter implements the #{NAME} port — nothing can authenticate a sign-in"
  else
    raise Runtime::WiringError,
          "#{implementations.size} adapters implement the #{NAME} port " \
          "(#{implementations.map(&:name).sort.join(', ')}) — the runtime will not choose for you"
  end
end

.authorization_url(registry) ⇒ Object



26
27
28
# File 'lib/hecks/ports/authentication.rb', line 26

def authorization_url(registry)
  adapter(registry).authorization_url
end

.verify(registry, code:, state:, expected_state:) ⇒ Object



30
31
32
# File 'lib/hecks/ports/authentication.rb', line 30

def verify(registry, code:, state:, expected_state:)
  adapter(registry).verify(code: code, state: state, expected_state: expected_state)
end