Class: PlatformSdk::Identity::Zitadel::Client

Inherits:
Object
  • Object
show all
Includes:
ErrorHandleable
Defined in:
lib/platform_sdk/identity/zitadel/client.rb

Overview

Client for the Zitadel v2 user API. Deliberately mirrors the IS4 Client's #provision_identity signature so consuming apps can call either interchangeably. Short timeouts, no retry middleware: this is the best-effort shadow path and must never hang a provisioning request.

Token acquisition is a seam: the SDK ships Zitadel::AuthClient as the client_credentials implementation, but this class only needs an object responding to #auth_token. Consumers may pass an AuthClient directly, wrap one (e.g. a Rails.cache-backed provider that shares a token across processes), or supply any other object with that interface.

Constant Summary collapse

OPEN_TIMEOUT_SECONDS =
2
READ_TIMEOUT_SECONDS =
5

Constants included from ErrorHandleable

ErrorHandleable::FORM_SECRET_PATTERN, ErrorHandleable::JSON_SECRET_PATTERN, ErrorHandleable::SENSITIVE_KEYS

Instance Method Summary collapse

Methods included from ErrorHandleable

#error_log_payload, #raise_error_with_payload, #scrub_headers, #scrub_request, #scrub_response, #scrub_secrets, #with_rescue

Constructor Details

#initialize(base_url, token_provider) ⇒ Client

Returns a new instance of Client.



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/platform_sdk/identity/zitadel/client.rb', line 23

def initialize(base_url, token_provider)
  @auth = token_provider
  @conn = Faraday.new(base_url) do |conn|
    conn.request :authorization, 'Bearer', -> { @auth.auth_token }
    conn.request :json
    conn.response :raise_error
    conn.response :json
    conn.options.open_timeout = OPEN_TIMEOUT_SECONDS
    conn.options.timeout = READ_TIMEOUT_SECONDS
    conn.adapter :net_http
  end
end

Instance Method Details

#provision_identity(is4_params) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/platform_sdk/identity/zitadel/client.rb', line 36

def provision_identity(is4_params)
  payload = UserPayload.from_is4(is4_params)
  post_payload('/v2/users/human', payload)
rescue PlatformSdk::Identity::ClientError => e
  raise unless e.response&.dig(:status) == 409

  verify_existing!(payload, e)
end