Skip to content

Pass tenant context (name/id) to JavaScript providers - #98

Merged
KrisSimon merged 2 commits into
mainfrom
feature/provider-tenant-info
Jul 7, 2026
Merged

Pass tenant context (name/id) to JavaScript providers#98
KrisSimon merged 2 commits into
mainfrom
feature/provider-tenant-info

Conversation

@KrisSimon

Copy link
Copy Markdown
Contributor

Summary

Tenant JavaScript providers (UserLoginProvider / UserValidationProvider) previously received only the username/password. That is not enough to talk to an external, multi-tenant user service such as Uitrusting, whose API is scoped by tenant (e.g. /tenants/{tenantId}/users). This PR exposes the tenant to the provider script.

What changed

The constructor argument now carries a nested tenant object:

class UserLoginProvider {
  constructor(credentials) {
    const tenantName = credentials.tenant.name;   // always present
    const tenantId   = credentials.tenant.id;     // Kubernetes CRD UID; null for file-based tenants
    // … authenticate against the tenant-scoped external service …
  }
}
  • New JSInputTenant { name, id }id is the Kubernetes CRD UID when the tenant is loaded from a CRD, nil for file-based tenants (identify those by name).
  • tenant added to JSInputCredentials and JSInputUsername.
  • Threaded through all four provider call sites: LoginController (interactive login), ActivateController (device grant), the password grant, and UserValidation (refresh-token re-validation).

The field is additive — existing provider scripts that ignore tenant keep working unchanged.

Tests

  • UserLoginTenantContextTest (new): a provider script reads credentials.tenant.name/.id and the values are asserted end-to-end; plus JSInputTenant(from:) mapping for Kubernetes vs. file tenant refs.
  • Updated JSInputParameterTest and the other provider tests for the new field (encode/decode/round-trip).

Verification

  • swift build clean; provider + controller suites 102/102 pass; ./tooling.sh lint 0 violations.
  • Not run: full e2e suite (needs a kind cluster).

Provider scripts (UserLoginProvider / UserValidationProvider) previously only
received the username/password. To let a provider target an external, multi-
tenant user service (e.g. Uitrusting, whose API is scoped by tenant id), expose
the tenant to the script as a nested 'tenant' object on the constructor argument:

    constructor(credentials) {
      const name = credentials.tenant.name;
      const id   = credentials.tenant.id; // Kubernetes CRD UID, null for file tenants
    }

Adds JSInputTenant and threads it through all four provider call sites (login,
activate, password grant, refresh validation). The field is additive, so
existing provider scripts keep working.
Expose the tenant to provider scripts as { name, namespace } instead of
{ name, id }. CRD tenants are stored as "<namespace>/<name>"; the name is now
the bare tenant name and namespace is the Kubernetes namespace (nil for
file-based tenants).
@KrisSimon
KrisSimon merged commit b327474 into main Jul 7, 2026
6 checks passed
@KrisSimon
KrisSimon deleted the feature/provider-tenant-info branch July 7, 2026 15:37
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