3. Authentication Provider Plugins (API Version 1)#

fleetmesh-auth provides identity verification and session management for FleetMesh services. It ships with two built-in providers:

  • sovereign_key: cryptographic keys, DIDs, NIP-07 browser extensions, NIP-46 bunkers, passkeys, and portable passes (fmpass_).

  • local_operator: local node operator credentials.

Integration with any external account system is implemented as a provider plugin—a Python package discovered and loaded by fleetmesh-auth. The fleetmesh-auth-acme package serves as the worked example throughout this specification and illustrates the standard layout for third-party provider implementations.

3.1. Plugin Interface#

A provider plugin is a subclass of fleetmesh_auth.AuthProviderPlugin:

from fleetmesh_auth import AuthPrincipal, AuthProviderPlugin


class AcmeProvider(AuthProviderPlugin):
    provider_id = "acme"                         # [a-z][a-z0-9_]*, stable
    display_name = "Sign in with Acme"
    description = "Your Acme account."
    supported_methods = ["service_login", "api_key"]
    token_prefixes = ("acme_",)                  # tokens it issues
    login_form = {                               # what the panel shows; None for no form
        "title": "Acme account",
        "submit": "Sign in with Acme",
        "hint": "Your Acme username and password.",
        "fields": [
            {"name": "username", "label": "Username", "type": "text", "autocomplete": "username"},
            {"name": "password", "label": "Password", "type": "password", "autocomplete": "current-password"},
        ],
    }

    def __init__(self, base_url=""):
        self.base_url = base_url

    @classmethod
    def from_settings(cls, settings):            # FLEETMESH_AUTH_ACME_BASE_URL
        return cls(base_url=settings.get("base_url"))

    def authenticate(self, payload, context):
        ...
        return {"ok": True, "principal": AuthPrincipal(..., provider=self.provider_id)}
        # or {"ok": False, "error": "invalid_acme_credentials"}

3.1.1. Interface Specification#

Attribute / Method

Specification

provider_id

Stable lowercase identifier matching ^[a-z][a-z0-9_]{0,63}$. This value MUST NOT change across releases because principals and persisted sessions reference it.

supported_methods

List of auth_method identifiers accepted by the provider. Including service_login designates the plugin as an account provider: login requests that omit an explicit provider are evaluated against each account provider in registration order, with local_operator evaluated last.

token_prefixes

Tuple of prefixes for tokens issued by this provider. Any login payload carrying a matching prefix in token, api_key, ticket, or portable_ticket is routed exclusively to this provider. Each prefix SHOULD end with _. The prefixes fmpass_ and fmauth_ are reserved by fleetmesh-auth.

login_form

Schema describing the form rendered by the sign-in panel, or None if no interactive form is required. Each field type MUST be text or password. Submitted field values are sent under their declared name alongside provider and auth_method: "service_login". A provider that declares login_form MUST accept service_login.

register_form

Optional. Schema describing an account registration form, using the same structure as login_form. Declaring register_form requires implementing register; describe() subsequently reports supports_registration: true so sign-in panels can present a registration workflow.

register(payload, context)

Optional. Creates an account from the register_form fields and returns {"ok": True, "principal": AuthPrincipal} (from which the engine opens a session with auth_method set to service_login unless the principal specifies otherwise) or {"ok": False, "error": code}. Standard error codes recognized by the sign-in panel are handle_taken, invalid_handle, weak_password, and invalid_email. Implementations MUST NOT raise exceptions for invalid user input; unhandled exceptions are logged and returned as provider_error. The default implementation refuses with registration_unsupported.

check_handle(handle)

Optional. Evaluates whether handle is eligible for registration to support live validation in sign-up forms (GET /api/fauth/register/check). Implementations MUST return strictly {"ok": True, "available": bool, "reason": None | "handle_taken" | "invalid_handle"} with no additional keys, or {"ok": False, "error": code} if the lookup cannot be completed (for example, provider_error when a backing store is unavailable). Before invoking this method, the engine trims whitespace, strips a single leading @, and rejects empty strings, values exceeding 64 characters, or characters outside [A-Za-z0-9._-] as invalid_handle; the plugin applies any stricter provider-specific constraints. Overriding this method causes describe() to report supports_handle_check: true; the base method raises NotImplementedError and is never invoked when unoverridden. Implementations MUST NOT raise for invalid input and MUST NOT include additional fields in the response, as the endpoint is publicly accessible.

describe()

Returns public provider metadata served at /api/fauth/config and /api/fauth/providers. The default implementation serializes the declared attributes. Subclasses MAY extend this metadata but MUST NOT include secrets or sensitive internal configuration.

authenticate(payload, context)

Verifies credentials and returns {"ok": True, "principal": AuthPrincipal} or {"ok": False, "error": code}. Implementations MUST NOT raise exceptions for invalid credentials; unhandled exceptions are logged and cause authentication to fail with provider_error.

from_settings(settings)

Factory classmethod used to instantiate the provider from environment configuration. settings.get(name) reads FLEETMESH_AUTH_<PROVIDER_ID>_<NAME>; settings.list() and settings.urls() parse delimited lists; settings.raw(env_name) reads legacy environment variable names.

api_version

Integer plugin API version (1). Plugins declaring an unsupported version are skipped during discovery.

3.1.2. Authentication Context#

The context parameter (AuthContext) passed to authenticate and register provides:

  • host: the host application instance supplied to the engine, if present. Plugins brokering a co-hosted application use this object to validate logins and API keys.

  • directory: the host application’s user directory.

  • web_auth: the challenge and ticket verifier instance.

  • domain, app_preset, and allow_any_sovereign_key: request- and engine-scoped policy parameters.

3.1.3. Authorization and Role Scope#

Roles attached to an AuthPrincipal represent assertions vouched for by the authenticating provider. Plugins MUST grant administrative roles (admin, node_operator) only for accounts authoritative on the local node. When a service plugin verifies a user against a remote instance, the resulting local principal MUST be assigned standard creator privileges rather than inheriting administrative roles from the remote system.

3.2. Plugin Discovery and Loading#

fleetmesh-auth discovers provider plugins through two mechanisms:

  1. Installed package entry points, declared in pyproject.toml:

    [project.entry-points."fleetmesh_auth.providers"]
    acme = "acme_fauth:AcmeProvider"
    
  2. FLEETMESH_AUTH_PLUGINS, a comma- or whitespace-separated list of module:Attribute import specifications for code loaded from PYTHONPATH without installed package metadata.

Specific providers can be excluded by listing their provider_id values in FLEETMESH_AUTH_DISABLED_PROVIDERS.

A plugin is skipped with a logged warning—without interrupting authentication for other providers—if any of the following conditions occur:

  • importing the module or attribute fails;

  • api_version is not supported by the current fleetmesh-auth release;

  • provider_id violates the identifier syntax rules;

  • provider_id conflicts with an already registered provider.

Host applications can bypass automatic discovery by passing FleetmeshAuthEngine(plugins=[...]) to register an explicit set of providers, or FleetmeshAuthEngine(plugins=False) to load no external plugins.

3.3. Account Registration#

A plugin that supports account creation declares register_form and implements register:

class AcmeProvider(AuthProviderPlugin):
    ...
    register_form = {
        "title": "Create an Acme account",
        "fields": [
            {"name": "username", "label": "Username", "type": "text"},
            {"name": "password", "label": "Password", "type": "password", "autocomplete": "new-password"},
            {"name": "email", "label": "Email", "type": "text"},
        ],
    }

    def register(self, payload, context):
        if self.exists(payload.get("username")):
            return {"ok": False, "error": "handle_taken"}
        ...
        return {"ok": True, "principal": AuthPrincipal(..., provider=self.provider_id)}

Submitting POST /api/fauth/register with {"provider": "acme", ...fields} invokes FleetmeshAuthEngine.register(payload, domain=, app_preset=) and returns the same response structure as a successful login (session_token, expires_at, principal).

When the request omits provider and exactly one registered provider supports registration, the engine selects that provider automatically; otherwise it refuses with provider_required. Other refusal codes include:

  • registration_unsupported: the selected provider (or all registered providers) does not implement register.

  • provider_not_enabled: the provider is disabled for the node or active preset.

  • method_not_enabled: none of the provider’s supported_methods (typically service_login) is enabled.

  • insufficient_role: the request specifies a required_role that the newly created principal does not hold (the sign-in panel forwards its preset’s required_role, matching login behavior).

At the HTTP layer, /api/fauth/register returns status 400 for form and selection errors (handle_taken, invalid_handle, weak_password, invalid_email, provider_required, unknown_provider, registration_unsupported) and status 401 for policy or provider failures.

3.3.1. Handle Availability Checks#

A provider that supports registration MAY also implement pre-submission handle validation:

    def check_handle(self, handle):
        if not self.HANDLE_RE.fullmatch(handle):
            return {"ok": True, "available": False, "reason": "invalid_handle"}
        if self.exists(handle):
            return {"ok": True, "available": False, "reason": "handle_taken"}
        return {"ok": True, "available": True, "reason": None}

GET /api/fauth/register/check?provider=acme&handle=ann invokes FleetmeshAuthEngine.check_handle(provider_id, handle, app_preset=) and returns strictly {"ok": true, "available": bool, "reason": "handle_taken" | "invalid_handle" | null}.

The engine trims handle, strips a single leading @, and immediately returns invalid_handle for empty strings, handles exceeding 64 characters, or handles containing characters outside [A-Za-z0-9._-]. The provider query parameter is required.

HTTP error status mappings:

  • 400: provider_required, unknown_provider, handle_check_unsupported (provider does not implement check_handle), and registration_unsupported.

  • 401: provider_not_enabled and provider_error (the hook raised an exception or returned ok: false).

3.3.1.1. Security Considerations#

Although /api/fauth/register/check discloses no account details beyond what a registration attempt itself reveals, it is an unauthenticated handle-existence oracle. Implementations SHOULD:

  • perform a single lightweight lookup (relying on engine-level pre-validation to filter malformed input before querying the backing store);

  • ensure comparable response times for available and taken handles;

  • apply edge rate limiting equivalent to that enforced on /api/fauth/register.

3.4. Sign-In Panel Integration#

When the sign-in panel initializes, it queries /api/fauth/config to construct its Account tab. It renders one form per registered provider that declares a login_form, providing a selector when multiple account providers are available. Default widget presets configure enabled_providers: ["*"] to expose all registered providers; host applications MAY restrict this list.

Host applications can define custom widget presets (served via /api/fauth/config?preset=acme and widget.js?preset=acme) without forking fleetmesh-auth:

from fleetmesh_auth import register_widget_preset

register_widget_preset("acme", {"app_title": "Acme", "brand_badge": "ACME", "required_role": "viewer"}, base="ops")

Registered preset names take precedence over built-in presets (allowing built-in presets such as admin to be overridden). Unrecognized configuration keys are logged and ignored, and app_id defaults to the preset name. Standalone server deployments can configure presets through the FLEETMESH_AUTH_PRESETS_JSON environment variable using a JSON object of the form {name: {"base": ..., ...overrides}}.

For backward compatibility with servers older than 0.2.0 that omit login_form from provider metadata, the panel renders a standard username and password form for account providers.

3.4.1. Login and Sign-Up Mode#

Configuring AuthWidgetConfig(primary_actions=['login', 'signup']) renders a two-button primary action bar rather than a flat list of authentication methods:

  • Login displays the login_form of the provider selected by primary_methods (or, if unspecified, the sole or first provider declaring a login_form).

  • Sign up displays the register_form returned by describe() for that provider—or for the provider named by signup_provider, or the first provider reporting supports_registration: true—and submits {provider, auth_method: "service_login", ...fields} to POST /api/fauth/register. If no provider defines a register_form, the pane displays "Sign up is not available".

  • All remaining authentication methods and providers are grouped under a collapsed More options section (configurable via more_options_label).

The panel treats register_form and supports_registration as optional fields, preserving compatibility with older servers.

3.5. Conformance Testing#

Provider plugins can be validated against the plugin contract using the built-in test helper:

from fleetmesh_auth.plugin_testing import check_provider

def test_standard():
    check_provider(AcmeProvider)       # what the entry point names

check_provider instantiates the plugin using the same lifecycle as FleetmeshAuthEngine and verifies that:

  • all required class attributes conform to the declaration rules;

  • describe() produces JSON-serializable public metadata;

  • empty and invalid credentials return structured error codes without raising exceptions;

  • register({}) returns a structured refusal without raising exceptions, and any plugin declaring register_form implements register;

  • describe() reports supports_handle_check accurately and, when implemented, check_handle returns the exact documented schema without raising for both an available-looking handle and a single-character handle;

  • tokens matching token_prefixes are routed exclusively to the plugin.