fleetmesh-auth 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. fleetmesh_auth-0.1.0/LICENSE +121 -0
  2. fleetmesh_auth-0.1.0/PKG-INFO +66 -0
  3. fleetmesh_auth-0.1.0/README.md +48 -0
  4. fleetmesh_auth-0.1.0/fleetmesh_auth/__init__.py +71 -0
  5. fleetmesh_auth-0.1.0/fleetmesh_auth/__main__.py +5 -0
  6. fleetmesh_auth-0.1.0/fleetmesh_auth/directory.py +60 -0
  7. fleetmesh_auth-0.1.0/fleetmesh_auth/engine.py +404 -0
  8. fleetmesh_auth-0.1.0/fleetmesh_auth/http_routes.py +129 -0
  9. fleetmesh_auth-0.1.0/fleetmesh_auth/nip46_bunker.py +162 -0
  10. fleetmesh_auth-0.1.0/fleetmesh_auth/principal.py +214 -0
  11. fleetmesh_auth-0.1.0/fleetmesh_auth/providers/__init__.py +12 -0
  12. fleetmesh_auth-0.1.0/fleetmesh_auth/providers/base.py +34 -0
  13. fleetmesh_auth-0.1.0/fleetmesh_auth/providers/key_did.py +238 -0
  14. fleetmesh_auth-0.1.0/fleetmesh_auth/providers/local_operator.py +92 -0
  15. fleetmesh_auth-0.1.0/fleetmesh_auth/providers/meshtube.py +266 -0
  16. fleetmesh_auth-0.1.0/fleetmesh_auth/schema_probe.py +23 -0
  17. fleetmesh_auth-0.1.0/fleetmesh_auth/server.py +144 -0
  18. fleetmesh_auth-0.1.0/fleetmesh_auth/settings.py +76 -0
  19. fleetmesh_auth-0.1.0/fleetmesh_auth/studio_directory.py +344 -0
  20. fleetmesh_auth-0.1.0/fleetmesh_auth/ui_widget.py +1076 -0
  21. fleetmesh_auth-0.1.0/fleetmesh_auth.egg-info/PKG-INFO +66 -0
  22. fleetmesh_auth-0.1.0/fleetmesh_auth.egg-info/SOURCES.txt +28 -0
  23. fleetmesh_auth-0.1.0/fleetmesh_auth.egg-info/dependency_links.txt +1 -0
  24. fleetmesh_auth-0.1.0/fleetmesh_auth.egg-info/entry_points.txt +2 -0
  25. fleetmesh_auth-0.1.0/fleetmesh_auth.egg-info/requires.txt +1 -0
  26. fleetmesh_auth-0.1.0/fleetmesh_auth.egg-info/top_level.txt +1 -0
  27. fleetmesh_auth-0.1.0/pyproject.toml +34 -0
  28. fleetmesh_auth-0.1.0/setup.cfg +4 -0
  29. fleetmesh_auth-0.1.0/tests/test_browser_signer.py +213 -0
  30. fleetmesh_auth-0.1.0/tests/test_fleetmesh_auth.py +622 -0
@@ -0,0 +1,121 @@
1
+ Creative Commons Legal Code
2
+
3
+ CC0 1.0 Universal
4
+
5
+ CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
6
+ LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
7
+ ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
8
+ INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
9
+ REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
10
+ PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
11
+ THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
12
+ HEREUNDER.
13
+
14
+ Statement of Purpose
15
+
16
+ The laws of most jurisdictions throughout the world automatically confer
17
+ exclusive Copyright and Related Rights (defined below) upon the creator
18
+ and subsequent owner(s) (each and all, an "owner") of an original work of
19
+ authorship and/or a database (each, a "Work").
20
+
21
+ Certain owners wish to permanently relinquish those rights to a Work for
22
+ the purpose of contributing to a commons of creative, cultural and
23
+ scientific works ("Commons") that the public can reliably and without fear
24
+ of later claims of infringement build upon, modify, incorporate in other
25
+ works, reuse and redistribute as freely as possible in any form whatsoever
26
+ and for any purposes, including without limitation commercial purposes.
27
+ These owners may contribute to the Commons to promote the ideal of a free
28
+ culture and the further production of creative, cultural and scientific
29
+ works, or to gain reputation or greater distribution for their Work in
30
+ part through the use and efforts of others.
31
+
32
+ For these and/or other purposes and motivations, and without any
33
+ expectation of additional consideration or compensation, the person
34
+ associating CC0 with a Work (the "Affirmer"), to the extent that he or she
35
+ is an owner of Copyright and Related Rights in the Work, voluntarily
36
+ elects to apply CC0 to the Work and publicly distribute the Work under its
37
+ terms, with knowledge of his or her Copyright and Related Rights in the
38
+ Work and the meaning and intended legal effect of CC0 on those rights.
39
+
40
+ 1. Copyright and Related Rights. A Work made available under CC0 may be
41
+ protected by copyright and related or neighboring rights ("Copyright and
42
+ Related Rights"). Copyright and Related Rights include, but are not
43
+ limited to, the following:
44
+
45
+ i. the right to reproduce, adapt, distribute, perform, display,
46
+ communicate, and translate a Work;
47
+ ii. moral rights retained by the original author(s) and/or performer(s);
48
+ iii. publicity and privacy rights pertaining to a person's image or
49
+ likeness depicted in a Work;
50
+ iv. rights protecting against unfair competition in regards to a Work,
51
+ subject to the limitations in paragraph 4(a), below;
52
+ v. rights protecting the extraction, dissemination, use and reuse of data
53
+ in a Work;
54
+ vi. database rights (such as those arising under Directive 96/9/EC of the
55
+ European Parliament and of the Council of 11 March 1996 on the legal
56
+ protection of databases, and under any national implementation
57
+ thereof, including any amended or successor version of such
58
+ directive); and
59
+ vii. other similar, equivalent or corresponding rights throughout the
60
+ world based on applicable law or treaty, and any national
61
+ implementations thereof.
62
+
63
+ 2. Waiver. To the greatest extent permitted by, but not in contravention
64
+ of, applicable law, Affirmer hereby overtly, fully, permanently,
65
+ irrevocably and unconditionally waives, abandons, and surrenders all of
66
+ Affirmer's Copyright and Related Rights and associated claims and causes
67
+ of action, whether now known or unknown (including existing as well as
68
+ future claims and causes of action), in the Work (i) in all territories
69
+ worldwide, (ii) for the maximum duration provided by applicable law or
70
+ treaty (including future time extensions), (iii) in any current or future
71
+ medium and for any number of copies, and (iv) for any purpose whatsoever,
72
+ including without limitation commercial, advertising or promotional
73
+ purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
74
+ member of the public at large and to the detriment of Affirmer's heirs and
75
+ successors, fully intending that such Waiver shall not be subject to
76
+ revocation, rescission, cancellation, termination, or any other legal or
77
+ equitable action to disrupt the quiet enjoyment of the Work by the public
78
+ as contemplated by Affirmer's express Statement of Purpose.
79
+
80
+ 3. Public License Fallback. Should any part of the Waiver for any reason
81
+ be judged legally invalid or ineffective under applicable law, then the
82
+ Waiver shall be preserved to the maximum extent permitted taking into
83
+ account Affirmer's express Statement of Purpose. In addition, to the
84
+ extent the Waiver is so judged Affirmer hereby grants to each affected
85
+ person a royalty-free, non transferable, non sublicensable, non exclusive,
86
+ irrevocable and unconditional license to exercise Affirmer's Copyright and
87
+ Related Rights in the Work (i) in all territories worldwide, (ii) for the
88
+ maximum duration provided by applicable law or treaty (including future
89
+ time extensions), (iii) in any current or future medium and for any number
90
+ of copies, and (iv) for any purpose whatsoever, including without
91
+ limitation commercial, advertising or promotional purposes (the
92
+ "License"). The License shall be deemed effective as of the date CC0 was
93
+ applied by Affirmer to the Work. Should any part of the License for any
94
+ reason be judged legally invalid or ineffective under applicable law, such
95
+ partial invalidity or ineffectiveness shall not invalidate the remainder
96
+ of the License, and in such case Affirmer hereby affirms that he or she
97
+ will not (i) exercise any of his or her remaining Copyright and Related
98
+ Rights in the Work or (ii) assert any associated claims and causes of
99
+ action with respect to the Work, in either case contrary to Affirmer's
100
+ express Statement of Purpose.
101
+
102
+ 4. Limitations and Disclaimers.
103
+
104
+ a. No trademark or patent rights held by Affirmer are waived, abandoned,
105
+ surrendered, licensed or otherwise affected by this document.
106
+ b. Affirmer offers the Work as-is and makes no representations or
107
+ warranties of any kind concerning the Work, express, implied,
108
+ statutory or otherwise, including without limitation warranties of
109
+ title, merchantability, fitness for a particular purpose, non
110
+ infringement, or the absence of latent or other defects, accuracy, or
111
+ the present or absence of errors, whether or not discoverable, all to
112
+ the greatest extent permissible under applicable law.
113
+ c. Affirmer disclaims responsibility for clearing rights of other persons
114
+ that may apply to the Work or any use thereof, including without
115
+ limitation any person's Copyright and Related Rights in the Work.
116
+ Further, Affirmer disclaims responsibility for obtaining any necessary
117
+ consents, permissions or other rights required for any use of the
118
+ Work.
119
+ d. Affirmer understands and acknowledges that Creative Commons is not a
120
+ party to this document and has no duty or obligation with respect to
121
+ this CC0 or use of the Work.
@@ -0,0 +1,66 @@
1
+ Metadata-Version: 2.4
2
+ Name: fleetmesh-auth
3
+ Version: 0.1.0
4
+ Summary: Pluggable white-labeled FleetMesh authentication: DID, NIP-46 bunker, NIP-07, browser-signed keys and service providers
5
+ License-Expression: CC0-1.0
6
+ Project-URL: Source, https://gitlab.pocketlabs.dev/fleetmesh/fleetmesh-auth
7
+ Keywords: fleetmesh,nostr,nip-46,nip-07,did,authentication,sso
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Topic :: Internet :: WWW/HTTP :: Session
12
+ Classifier: Topic :: Security
13
+ Requires-Python: >=3.10
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: fleetmesh-core>=0.2.0
17
+ Dynamic: license-file
18
+
19
+ # FleetMesh Auth (`fleetmesh/fleetmesh-auth`)
20
+
21
+ Standardized, white-labeled, and pluggable authentication & authorization suite for FleetMesh applications (**Fleetmesh Stream Studio**, **MeshTube Admin Deck**, **Fleetmesh Meshnode Ops**, and standalone mesh services).
22
+
23
+ ## Key Features
24
+ 1. **Cryptographic & Sovereign Identity Login (`sovereign_key`)**:
25
+ - **Nostr Bunker (`bunker://<pubkey>?relay=wss://...`)**: NIP-46 remote signer URI parsing and signed challenge verification. A bunker login must carry a signature over a server challenge; the bundled widget does not yet run the NIP-46 handshake that gets one, so its bunker tab cannot complete a login.
26
+ - **NIP-07 Browser Signer (`window.nostr.signEvent`)**: One-click cryptographic challenge signing via browser extension.
27
+ - **Private Key / DID (`nsec1...`, 64-char hex, `did:nostr`, `did:key`)**: the panel signs the challenge in the page (BIP-340 over WebCrypto, `BROWSER_KEY_SIGNER_JS` in `ui_widget.py`) and sends only the public key and signature. The server refuses a raw key outright (`private_key_not_accepted`). It only signs the `<scheme>:<challenge>:<origin>` login message it hashes itself, never a digest the server hands it.
28
+ - **Portable Cross-Site Identity Pass (`fmpass_...` / `mtpass_...`)**: Self-contained signed NIP-98 (`Kind 27235`) SSO tickets. A ticket is the identity of the key that signs it, so only the user's own key can mint one, and the panel mints it in the browser: from a pasted key at sign-in, before the key is cleared, or from the signer extension when "Copy Portable Pass" is clicked. The server mints none, and deletes the ticket-signing key earlier versions kept. A ticket is good for one sign-in within the hour; the copy button never hands out the session token.
29
+ 2. **Pluggable Service & User-Store Providers (`AuthProviderPlugin`)**:
30
+ - **`MeshTubeAuthProvider` (`meshtube`)**: Authenticates against a local or remote MeshTube instance's `users`, `admin_users`, and `api_keys` store.
31
+ - **`LocalOperatorProvider` (`local_operator`)**: Standalone node operator authentication via `MESHNODE_OPERATOR_TOKEN`, `meshctl` control credentials, or authorized operator pubkeys—no MeshTube dependency required.
32
+ 3. **White-Labeled FleetMesh Auth Panel (`ui_widget.py`)**:
33
+ - Supports **Full-Screen Auth Gate** mode (`admin.<domain>`, `ops.<domain>`) and **Slide-Over / Modal** mode (`studio.<domain>`).
34
+ - Mountable `/api/fauth/*` HTTP routes (`GET /api/fauth/config`, `GET /api/fauth/session`, `POST /api/fauth/challenge`, `POST /api/fauth/login`, `POST /api/fauth/logout`, `GET /api/fauth/widget.js`) or runnable as a standalone SSO service (`python3 -m fleetmesh_auth`).
35
+
36
+ ## Configuration
37
+
38
+ Apps build `FleetmeshAuthEngine` themselves; these environment variables set
39
+ who holds which role without changing their code. Lists are separated by
40
+ commas or whitespace. Keys are 64-hex x-only pubkeys, `npub1...` or
41
+ `did:nostr:...`; an entry that does not parse is logged and skipped.
42
+
43
+ | Variable | Effect |
44
+ |---|---|
45
+ | `FLEETMESH_AUTH_OPERATOR_PUBKEYS` | Keys that sign in as node operators (with `admin`). |
46
+ | `FLEETMESH_AUTH_ADMIN_PUBKEYS` | Keys that sign in as admins. `admin` and `node_operator` imply each other in `principal.ROLE_IMPLICATIONS`, so today this grants the same roles as the operator list. |
47
+ | `FLEETMESH_AUTH_TRUSTED_INSTANCES` | Remote MeshTube base URLs a login may name in `instance_url`. The provider's own `instance_url` is always trusted; users verified remotely sign in as creators. |
48
+ | `MESHNODE_OPERATOR_TOKEN` (or `FLEETMESH_OPERATOR_TOKEN`, `MESHTUBE_ADMIN_PASS`) | The local operator provider's password. Unset, operator-token login is refused; there is no default. |
49
+ | `MESHNODE_OPERATOR_USER` (or `MESHTUBE_ADMIN_USER`) | The operator's display name (default `admin`). |
50
+
51
+ Without any of these, a key login is a creator. It is an operator only when the
52
+ key is the co-hosted studio's own operator or node key, or the studio's user
53
+ record has an admin or operator role. `allow_any_sovereign_key=True` (code only)
54
+ makes every key an operator, for single-operator setups. A list passed to a
55
+ provider's constructor replaces the environment's.
56
+
57
+ ## Tests
58
+
59
+ ```
60
+ PYTHONPATH=.:../core:../schema python3 tests/test_fleetmesh_auth.py
61
+ PYTHONPATH=.:../core:../schema python3 tests/test_browser_signer.py # needs node 22+; skipped without it
62
+ ```
63
+
64
+ `test_browser_signer.py` runs the panel's in-page signer under Node against
65
+ `fleetmesh_core`: identical public keys and signatures, nsec decoding, and the
66
+ server accepting what the page signs, and passes minted in the page that sign in as their owner once.
@@ -0,0 +1,48 @@
1
+ # FleetMesh Auth (`fleetmesh/fleetmesh-auth`)
2
+
3
+ Standardized, white-labeled, and pluggable authentication & authorization suite for FleetMesh applications (**Fleetmesh Stream Studio**, **MeshTube Admin Deck**, **Fleetmesh Meshnode Ops**, and standalone mesh services).
4
+
5
+ ## Key Features
6
+ 1. **Cryptographic & Sovereign Identity Login (`sovereign_key`)**:
7
+ - **Nostr Bunker (`bunker://<pubkey>?relay=wss://...`)**: NIP-46 remote signer URI parsing and signed challenge verification. A bunker login must carry a signature over a server challenge; the bundled widget does not yet run the NIP-46 handshake that gets one, so its bunker tab cannot complete a login.
8
+ - **NIP-07 Browser Signer (`window.nostr.signEvent`)**: One-click cryptographic challenge signing via browser extension.
9
+ - **Private Key / DID (`nsec1...`, 64-char hex, `did:nostr`, `did:key`)**: the panel signs the challenge in the page (BIP-340 over WebCrypto, `BROWSER_KEY_SIGNER_JS` in `ui_widget.py`) and sends only the public key and signature. The server refuses a raw key outright (`private_key_not_accepted`). It only signs the `<scheme>:<challenge>:<origin>` login message it hashes itself, never a digest the server hands it.
10
+ - **Portable Cross-Site Identity Pass (`fmpass_...` / `mtpass_...`)**: Self-contained signed NIP-98 (`Kind 27235`) SSO tickets. A ticket is the identity of the key that signs it, so only the user's own key can mint one, and the panel mints it in the browser: from a pasted key at sign-in, before the key is cleared, or from the signer extension when "Copy Portable Pass" is clicked. The server mints none, and deletes the ticket-signing key earlier versions kept. A ticket is good for one sign-in within the hour; the copy button never hands out the session token.
11
+ 2. **Pluggable Service & User-Store Providers (`AuthProviderPlugin`)**:
12
+ - **`MeshTubeAuthProvider` (`meshtube`)**: Authenticates against a local or remote MeshTube instance's `users`, `admin_users`, and `api_keys` store.
13
+ - **`LocalOperatorProvider` (`local_operator`)**: Standalone node operator authentication via `MESHNODE_OPERATOR_TOKEN`, `meshctl` control credentials, or authorized operator pubkeys—no MeshTube dependency required.
14
+ 3. **White-Labeled FleetMesh Auth Panel (`ui_widget.py`)**:
15
+ - Supports **Full-Screen Auth Gate** mode (`admin.<domain>`, `ops.<domain>`) and **Slide-Over / Modal** mode (`studio.<domain>`).
16
+ - Mountable `/api/fauth/*` HTTP routes (`GET /api/fauth/config`, `GET /api/fauth/session`, `POST /api/fauth/challenge`, `POST /api/fauth/login`, `POST /api/fauth/logout`, `GET /api/fauth/widget.js`) or runnable as a standalone SSO service (`python3 -m fleetmesh_auth`).
17
+
18
+ ## Configuration
19
+
20
+ Apps build `FleetmeshAuthEngine` themselves; these environment variables set
21
+ who holds which role without changing their code. Lists are separated by
22
+ commas or whitespace. Keys are 64-hex x-only pubkeys, `npub1...` or
23
+ `did:nostr:...`; an entry that does not parse is logged and skipped.
24
+
25
+ | Variable | Effect |
26
+ |---|---|
27
+ | `FLEETMESH_AUTH_OPERATOR_PUBKEYS` | Keys that sign in as node operators (with `admin`). |
28
+ | `FLEETMESH_AUTH_ADMIN_PUBKEYS` | Keys that sign in as admins. `admin` and `node_operator` imply each other in `principal.ROLE_IMPLICATIONS`, so today this grants the same roles as the operator list. |
29
+ | `FLEETMESH_AUTH_TRUSTED_INSTANCES` | Remote MeshTube base URLs a login may name in `instance_url`. The provider's own `instance_url` is always trusted; users verified remotely sign in as creators. |
30
+ | `MESHNODE_OPERATOR_TOKEN` (or `FLEETMESH_OPERATOR_TOKEN`, `MESHTUBE_ADMIN_PASS`) | The local operator provider's password. Unset, operator-token login is refused; there is no default. |
31
+ | `MESHNODE_OPERATOR_USER` (or `MESHTUBE_ADMIN_USER`) | The operator's display name (default `admin`). |
32
+
33
+ Without any of these, a key login is a creator. It is an operator only when the
34
+ key is the co-hosted studio's own operator or node key, or the studio's user
35
+ record has an admin or operator role. `allow_any_sovereign_key=True` (code only)
36
+ makes every key an operator, for single-operator setups. A list passed to a
37
+ provider's constructor replaces the environment's.
38
+
39
+ ## Tests
40
+
41
+ ```
42
+ PYTHONPATH=.:../core:../schema python3 tests/test_fleetmesh_auth.py
43
+ PYTHONPATH=.:../core:../schema python3 tests/test_browser_signer.py # needs node 22+; skipped without it
44
+ ```
45
+
46
+ `test_browser_signer.py` runs the panel's in-page signer under Node against
47
+ `fleetmesh_core`: identical public keys and signatures, nsec decoding, and the
48
+ server accepting what the page signs, and passes minted in the page that sign in as their owner once.
@@ -0,0 +1,71 @@
1
+ """FleetMesh Auth (`fleetmesh_auth`) — Unified Pluggable Identity & SSO."""
2
+ import os as _os
3
+ import sys as _sys
4
+
5
+ _CORE_DIR = _os.path.abspath(_os.path.join(_os.path.dirname(__file__), "..", "..", "core"))
6
+ if _os.path.isdir(_CORE_DIR) and _CORE_DIR not in _sys.path:
7
+ _sys.path.insert(0, _CORE_DIR)
8
+
9
+ from fleetmesh_auth.engine import FleetmeshAuthEngine
10
+ from fleetmesh_auth.http_routes import (
11
+ extract_request_token,
12
+ handle_fauth_get,
13
+ handle_fauth_post,
14
+ )
15
+ from fleetmesh_auth.nip46_bunker import (
16
+ BunkerDescriptor,
17
+ decode_bech32_hex,
18
+ normalize_pubkey_or_did,
19
+ normalize_secret_key,
20
+ parse_bunker_uri,
21
+ sign_challenge_with_secret_key,
22
+ )
23
+ from fleetmesh_auth.principal import (
24
+ PRESET_WIDGET_CONFIGS,
25
+ AuthPrincipal,
26
+ AuthWidgetConfig,
27
+ expand_roles,
28
+ has_required_role,
29
+ resolve_widget_config,
30
+ )
31
+ from fleetmesh_auth.providers import (
32
+ AuthProviderPlugin,
33
+ LocalOperatorProvider,
34
+ MeshTubeAuthProvider,
35
+ SovereignKeyBunkerProvider,
36
+ )
37
+ from fleetmesh_auth.server import create_auth_http_server
38
+ from fleetmesh_auth.ui_widget import (
39
+ render_auth_bundle_html,
40
+ render_auth_widget_css,
41
+ render_auth_widget_html,
42
+ render_auth_widget_js,
43
+ )
44
+
45
+ __all__ = [
46
+ "AuthPrincipal",
47
+ "AuthProviderPlugin",
48
+ "AuthWidgetConfig",
49
+ "BunkerDescriptor",
50
+ "FleetmeshAuthEngine",
51
+ "LocalOperatorProvider",
52
+ "MeshTubeAuthProvider",
53
+ "PRESET_WIDGET_CONFIGS",
54
+ "SovereignKeyBunkerProvider",
55
+ "create_auth_http_server",
56
+ "decode_bech32_hex",
57
+ "expand_roles",
58
+ "extract_request_token",
59
+ "handle_fauth_get",
60
+ "handle_fauth_post",
61
+ "has_required_role",
62
+ "normalize_pubkey_or_did",
63
+ "normalize_secret_key",
64
+ "parse_bunker_uri",
65
+ "render_auth_bundle_html",
66
+ "render_auth_widget_css",
67
+ "render_auth_widget_html",
68
+ "render_auth_widget_js",
69
+ "resolve_widget_config",
70
+ "sign_challenge_with_secret_key",
71
+ ]
@@ -0,0 +1,5 @@
1
+ """CLI entrypoint for `python3 -m fleetmesh_auth`."""
2
+ from fleetmesh_auth.server import main
3
+
4
+ if __name__ == "__main__":
5
+ main()
@@ -0,0 +1,60 @@
1
+ """Where an app keeps its users: the one surface fleetmesh_auth needs from it.
2
+
3
+ fleetmesh_auth proves who someone is; the app hosting it decides who its users
4
+ are. A `UserDirectory` finds or creates the app's record for a proven pubkey,
5
+ names the keys the app itself runs as, and carries sessions into the app's own
6
+ session tables when it has any. `StudioDirectory` (studio_directory.py) adapts
7
+ a co-hosted StudioEngine; an app without users of its own passes none.
8
+ """
9
+ from __future__ import annotations
10
+
11
+ from typing import TYPE_CHECKING, FrozenSet, List, Optional, Protocol, TypedDict
12
+
13
+ if TYPE_CHECKING:
14
+ from fleetmesh_auth.principal import AuthPrincipal
15
+
16
+
17
+ class UserRecord(TypedDict):
18
+ user_id: str
19
+ handle: str
20
+ display_name: str
21
+ roles: List[str]
22
+
23
+
24
+ class UserDirectory(Protocol):
25
+ def own_pubkeys(self) -> FrozenSet[str]:
26
+ """Pubkeys the app runs as (operator, node): they sign in as operators."""
27
+ ...
28
+
29
+ def find_user(self, pubkey_hex: str) -> Optional[UserRecord]:
30
+ """The app's user for this pubkey, if it has one."""
31
+ ...
32
+
33
+ def create_user(self, pubkey_hex: str, handle_hint: Optional[str]) -> Optional[UserRecord]:
34
+ """Make a user for a pubkey seen for the first time; None if the app declines."""
35
+ ...
36
+
37
+ def link_session(
38
+ self,
39
+ token: str,
40
+ principal: "AuthPrincipal",
41
+ issued_at: int,
42
+ expires_at: int,
43
+ operator_pubkeys: FrozenSet[str],
44
+ ) -> None:
45
+ """Make `token` a session in the app's own tables too (no-op if it keeps none)."""
46
+ ...
47
+
48
+ def has_session(self, token: str) -> bool:
49
+ ...
50
+
51
+ def resolve_session(self, token: str, now: int, ttl_sec: int) -> Optional["AuthPrincipal"]:
52
+ """A session (or API key) the app issued itself, as a principal."""
53
+ ...
54
+
55
+ def revoke_session(self, token: str) -> None:
56
+ ...
57
+
58
+ def default_db_path(self) -> Optional[str]:
59
+ """Where fleetmesh_auth's own database should live beside the app's, if anywhere."""
60
+ ...