Metadata-Version: 2.4
Name: scalio-identity
Version: 0.11.0
Summary: Sign-in through Scalio ID, Entra app roles and second factor, shared by the Scalio apps
License: Proprietary
Requires-Python: >=3.11
Description-Content-Type: text/markdown
Requires-Dist: PyJWT[crypto]>=2.10
Requires-Dist: httpx>=0.27
Provides-Extra: mfa
Requires-Dist: pyotp>=2.9; extra == "mfa"
Requires-Dist: webauthn>=2.0; extra == "mfa"
Provides-Extra: web
Requires-Dist: fastapi>=0.110; extra == "web"
Requires-Dist: pymongo>=4.6; extra == "web"
Provides-Extra: passwords
Requires-Dist: bcrypt>=4.1; extra == "passwords"
Provides-Extra: localauth
Requires-Dist: fastapi>=0.110; extra == "localauth"
Requires-Dist: pymongo>=4.6; extra == "localauth"
Requires-Dist: email-validator>=2.0; extra == "localauth"
Requires-Dist: pyotp>=2.9; extra == "localauth"
Requires-Dist: webauthn>=2.0; extra == "localauth"
Requires-Dist: bcrypt>=4.1; extra == "localauth"
Requires-Dist: scalio-platform>=0.16.0; extra == "localauth"
Provides-Extra: testing
Requires-Dist: cbor2>=5.6; extra == "testing"
Requires-Dist: cryptography>=42; extra == "testing"
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
Requires-Dist: pyotp>=2.9; extra == "dev"
Requires-Dist: webauthn>=2.0; extra == "dev"
Requires-Dist: cbor2>=5.6; extra == "dev"
Requires-Dist: ruff>=0.6; extra == "dev"
Requires-Dist: bcrypt>=4.1; extra == "dev"
Requires-Dist: fastapi>=0.110; extra == "dev"
Requires-Dist: pymongo>=4.6; extra == "dev"
Requires-Dist: mongomock-motor>=0.0.29; extra == "dev"
Requires-Dist: email-validator>=2.0; extra == "dev"
Requires-Dist: scalio-platform>=0.16.0; extra == "dev"
Requires-Dist: pyright==1.1.414; extra == "dev"

# scalio-identity

Identity helpers shared by the Scalio apps Nexus, Citadel, Rosetta and Foundry. Decisions: scalio-docs ADR 0028
(`idm/I1`–`I12`), concept `concepts/central-user-management.md`. Protocol of the broker: scalio-docs
`interfaces/scalio-id-oidc.md`.

```
pip install "scalio-identity[mfa,web,passwords]"          # app
pip install "scalio-identity[mfa,web,passwords,testing]"  # app tests
```

| Module | What it does |
| --- | --- |
| `scalio_identity.broker` | Sign-in through Scalio ID: `Broker.from_env()`, `Flow.new()`, `authorize_url()`, `redeem()` → `Identity`; `check_binding()` refuses another organisation (`SCALIO_ORG_ID`) or tenant; `check_access(ident, Binding.of(...))` (0.3.0, ADR 0063) also knows customer organisations of an MSP instance and MSP delegations (`via_msp`) and says how the person comes in (instance / customer / delegated) |
| `scalio_identity.roles` | `RoleMap("Nexus", {"Admin": "admin", ...})`: Entra app roles (`Nexus.Admin`) → app role, unknown = no rights |
| `scalio_identity.accounts` | Account lookup by Scalio ID subject, then Microsoft tenant + object id; e-mail only for a one-time link; name and e-mail follow Entra (`follow_entra`), unlink, merge, start password (ADR 0059) |
| `scalio_identity.passwords` | bcrypt `hash_password` / `verify_password` with the 72-byte limit (0.6.0, AR15): new passwords over 72 bytes raise `PasswordTooLong` (message de/en, `check_new_password` for validators), a login with one is just wrong, `verify_password` never raises |
| `scalio_identity.mfa` | TOTP (replay safe), backup codes, passkeys (WebAuthn, user verification required). 0.8.0: `authentication_options(rp_id, allow_ids=...)` offers only the named passkeys, for apps that ask for the email first (Compass, ADR 0083) |
| `scalio_identity.setup` | First-run setup code (`FirstRun`) and password sign-in policy (`PasswordPolicy`, `meta_policy`, `policy_router`), 0.4.0 (C2). Document names, key field and user collection are settings, so each app keeps its data |
| `scalio_identity.signin` | `ScalioSignIn`: sign-in routes through Scalio ID with state, handoff, accounts, Entra roles, customer and delegated people, setup by Microsoft and linking; the app subclasses it and overrides its hooks (0.4.0, C2). 0.5.0: «Tenant hinzufügen» (`/consent`, admin consent through Scalio ID, hook `add_role_tenant(tid, domain)`, back to `tenants_page?entra_tenant=added`), first admin's tenant on the list, listed tenants may sign in next to the home tenant (ADR 0068). 0.7.0: a delegated MSP person gets the role of the delegation (`app_role` from Scalio ID, mapped by `RoleMap`, `role_managed_by: "delegation"`, follows it at every sign-in) instead of waiting for approval (ADR 0083) |
| `scalio_identity.localauth` | `LocalAuth`: local accounts of an app (password, second factor, passkeys, session, first setup, invitations) under /api/auth; the app subclasses it (0.9.0, QA5). 0.10.0: weak `JWT_SECRET` never signs (M5) |
| `scalio_identity.users` | `UserAdmin`: the user list for administrators under /api/users (add, change, lock, start password, second factor, Microsoft link, merge, role source local/entra, invitations); hooks `valid_role`, `audit`, `check_role` (licence), `row_extra`, `apply_access` (customers per account, field `access`), `send_invite`; helpers `role_config`, `managed_by_entra`, `ROLE_TENANTS`, `keeps_an_admin` (0.11.0, QA5 step 2) |
| `scalio_identity.testing` | `FakeBroker` (Scalio ID in memory, `httpx.MockTransport`) and `SoftKey` (software passkey) |

With `setup` and `signin` (extra `web`) the app keeps only a small adapter: its session, role source, licence check
and customer organisations. Without them the app keeps its own routes and this package only checks.

## Settings of an app

| Variable | Meaning |
| --- | --- |
| `SCALIO_ID_ISSUER` | broker, e.g. `https://sso.scaliocloud.com`; empty = Scalio ID off |
| `SCALIO_ID_CLIENT_ID` | the app's origin; default from the app's own URL |
| `SCALIO_ORG_ID` | Scalio organisation of a SaaS instance (set at provisioning); empty on self-hosted |

## Development

```
pip install -e ".[dev]"
ruff check . && pytest -q
```

Release: bump `pyproject.toml` and `__version__`, a scalio-docs PR with `python3 tools/changelog.py --repo scalio-identity release <version>` (changelog in scalio-docs `changelog/scalio-identity/`, ADR 0066), merge, then "Freigeben" in the Scalio Dev
cockpit (or Actions → Publish with the version). PyPI trusted publishing, environment `pypi`, no token.
