Skip to content

Add the Cognito tenant registration endpoint and allow /subscriptions as exchange target - #686

Merged
tungleduyxyz merged 1 commit into
masterfrom
sso-aviate-tenants-endpoint
Nov 29, 2026
Merged

tungleduyxyz merged 1 commit into
masterfrom
sso-aviate-tenants-endpoint

Conversation

@tungleduyxyz

Copy link
Copy Markdown
Contributor

Part of #685 (Kaui side of the Aviate getting started migration; Aviate side: killbill/aviate#1288).

Why

Aviate registers the tenants it creates in Kill Bill in Kaui, and opens the subscription form, through the /getting_started/* endpoints of the managed overlay. Kaui provides both natively here, so the overlay can be removed once Aviate uses the Cognito endpoints. The overlay itself is untouched: the new routes do not overlap with /getting_started/*, so this can be released with #684 without any change in managed.

Changes

  • POST /sso/cognito/tenants (alias /sso/aviate/tenants, same convention as the exchange): registers a Kill Bill tenant in kaui_tenants and allows the user on it (Kaui::SsoCognito::TenantsController).
    • Same Cognito token + Kill Bill login (basic or bearer) as the exchange, through the new authenticate_kb_user_without_session! of Kaui::KbCognitoAuthenticatable: no Warden session for the browser, no tenant required (the exchange's bearer mode requires an already known tenant, which is what this call creates).
    • Body: name, tenantKey, tenantSecret, kbTenantId. Responses: 201 registered, 200 already registered (the user is allowed on it, so a retry is safe), 400 missing parameter, 401 token or Kill Bill credentials, 403 rejected by Kill Bill, 409 name used by another tenant, 404 Cognito not configured. Same body as the overlay on success.
  • /subscriptions (and sub-paths) added to the exchange ALLOWED_TARGETS, to keep landing on /subscriptions/new?account_id=...&product_category=BASE.
  • Kaui::SsoCognito::BaseController holds what the two controllers share (CSRF rule for requests without a bearer token, error handling). exchange and session_expired behave as before (the 404 when Cognito is not configured still applies to exchange only).
  • README: allowed targets and a "Registering a tenant" section.

Differences with the overlay's getting_started/tenants

  • Kaui checks with Kill Bill that tenantKey/tenantSecret are valid and belong to kbTenantId (the same call as the tenant creation of the admin screens, Kaui::AdminTenant.find_by_api_key) before storing the secret. Without it, any user with a valid Cognito token could register, or squat the name of, any tenant. Please review: it relies on the user being allowed to read the tenant in Kill Bill.
  • An already registered tenant answers 200 and allows the user on it (the overlay answers 409 and does not). A name used by another tenant still answers 409.
  • No session is created for the browser.

Tests

  • New test/functional/kaui/sso_cognito/tenants_controller_test.rb (15 tests): routes and alias, 404, token errors, basic and bearer success, no session, required parameters, Kill Bill rejections, mismatching id, idempotency and access for a second user, name conflict, CSRF.
  • sso_cognito_controller_test.rb (18 tests) still passes, with a new case for the /subscriptions target (fails without the change).
  • Run with JRuby 10 on SQLite; rubocop is clean. Not run against a real Kill Bill (stubbed).

🤖 Generated with Claude Code

… as exchange target

Aviate registers the tenants it creates in Kill Bill in Kaui, and opens the subscription
form, through the /getting_started/* endpoints of the managed overlay. Provide both natively
so that the overlay can be removed once Aviate uses the Cognito endpoints.

* POST /sso/cognito/tenants (alias /sso/aviate/tenants): registers a Kill Bill tenant in
  kaui_tenants and allows the user on it. Same Cognito token + Kill Bill login (basic or
  bearer) as the exchange, but no session for the browser and no tenant required. Kaui checks
  with Kill Bill that tenantKey/tenantSecret are valid for kbTenantId before storing the
  secret. 201 created, 200 already registered (the user is allowed on it), 400, 401, 403, 409.
* /subscriptions (and its sub-paths) is an allowed target of the exchange, to keep landing on
  /subscriptions/new?account_id=...&product_category=BASE.
* The common part of the two controllers (CSRF rule, error handling) is in
  Kaui::SsoCognito::BaseController. The existing exchange and session_expired behavior is unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@tungleduyxyz
tungleduyxyz merged commit 35a7eb8 into master Nov 29, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant