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 |
|---|---|
|
Stable lowercase identifier matching |
|
List of |
|
Tuple of prefixes for tokens issued by this provider. Any login payload carrying a matching prefix in |
|
Schema describing the form rendered by the sign-in panel, or |
|
Optional. Schema describing an account registration form, using the same structure as |
|
Optional. Creates an account from the |
|
Optional. Evaluates whether |
|
Returns public provider metadata served at |
|
Verifies credentials and returns |
|
Factory classmethod used to instantiate the provider from environment configuration. |
|
Integer plugin API version ( |
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, andallow_any_sovereign_key: request- and engine-scoped policy parameters.
3.2. Plugin Discovery and Loading#
fleetmesh-auth discovers provider plugins through two mechanisms:
Installed package entry points, declared in
pyproject.toml:[project.entry-points."fleetmesh_auth.providers"] acme = "acme_fauth:AcmeProvider"
FLEETMESH_AUTH_PLUGINS, a comma- or whitespace-separated list ofmodule:Attributeimport specifications for code loaded fromPYTHONPATHwithout 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_versionis not supported by the currentfleetmesh-authrelease;provider_idviolates the identifier syntax rules;provider_idconflicts 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 implementregister.provider_not_enabled: the provider is disabled for the node or active preset.method_not_enabled: none of the provider’ssupported_methods(typicallyservice_login) is enabled.insufficient_role: the request specifies arequired_rolethat the newly created principal does not hold (the sign-in panel forwards its preset’srequired_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 implementcheck_handle), andregistration_unsupported.401:provider_not_enabledandprovider_error(the hook raised an exception or returnedok: 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_formof the provider selected byprimary_methods(or, if unspecified, the sole or first provider declaring alogin_form).Sign up displays the
register_formreturned bydescribe()for that provider—or for the provider named bysignup_provider, or the first provider reportingsupports_registration: true—and submits{provider, auth_method: "service_login", ...fields}toPOST /api/fauth/register. If no provider defines aregister_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 declaringregister_formimplementsregister;describe()reportssupports_handle_checkaccurately and, when implemented,check_handlereturns the exact documented schema without raising for both an available-looking handle and a single-character handle;tokens matching
token_prefixesare routed exclusively to the plugin.