lambda-erp 1.4.23__tar.gz → 1.4.24__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.
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/PKG-INFO +1 -1
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/oauth.py +93 -2
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/pyproject.toml +1 -1
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/.gitignore +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/LICENSE +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/README.md +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/__init__.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/attachments.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/auth.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/bootstrap.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/chat.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/chat_links.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/demo_limits.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/deps.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/erp_context.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/errors.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/list_values.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/llm_provider.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/main.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/mcp_oauth.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/mentions.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/menu_layout.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/pdf.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/pdf_contract.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/pdf_exports.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/pdf_fonts.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/pdf_pages.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/pdf_profiles.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/pdf_templates.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/pricing_actions.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/providers.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/record_attachments.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/record_notes.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/remarks_md.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/routers/__init__.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/routers/accounting.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/routers/actions.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/routers/admin.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/routers/analytics.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/routers/availability.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/routers/bank_reconciliation.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/routers/bank_statements.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/routers/chat_api.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/routers/documents.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/routers/masters.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/routers/mcp.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/routers/pdf_templates.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/routers/proposals.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/routers/reports.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/routers/setup.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/services.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/stock_actions.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/templates/_proposal_totals.html +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/templates/_record_base.html +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/templates/delivery_note.html +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/templates/document.html +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/templates/proposal.html +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/templates/record.html +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/templates/reservation.html +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/time_filters.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/tool_permissions.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/api/write_context.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/docs/agents/README.md +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/frontend/LICENSE +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/frontend/README.md +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/frontend/src/api/client.ts +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/__init__.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/accounting/__init__.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/accounting/bank_account.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/accounting/bank_reconciliation.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/accounting/bank_statement_import.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/accounting/bank_transaction.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/accounting/budget.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/accounting/camt.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/accounting/chart_of_accounts.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/accounting/general_ledger.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/accounting/journal_entry.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/accounting/payment_entry.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/accounting/pos_invoice.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/accounting/purchase_invoice.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/accounting/revaluation.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/accounting/sales_invoice.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/accounting/settlement.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/accounting/setup/__init__.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/accounting/setup/engine.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/accounting/setup/pack.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/accounting/setup/packs/__init__.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/accounting/setup/packs/ch.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/accounting/setup/packs/de_common.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/accounting/setup/packs/de_skr03.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/accounting/setup/packs/de_skr04.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/accounting/setup/packs/generic.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/accounting/setup/profiles.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/accounting/setup/spine.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/accounting/subscription.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/addresses.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/assets/__init__.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/assets/asset.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/assets/lifecycle.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/assets/reservation.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/backlog.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/bundles.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/buying/__init__.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/buying/purchase_order.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/controllers/__init__.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/controllers/currency.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/controllers/defaults.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/controllers/item_price.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/controllers/item_prices.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/controllers/price_resolution.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/controllers/pricing_rule.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/controllers/tax_defaults.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/controllers/taxes_and_totals.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/database.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/exceptions.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/hooks.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/master_integrity.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/model.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/permissions.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/selling/__init__.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/selling/proposal.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/selling/quotation.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/selling/sales_order.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/simulation.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/stock/__init__.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/stock/consignment.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/stock/delivery_note.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/stock/purchase_receipt.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/stock/reservation.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/stock/serial.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/stock/stock_count.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/stock/stock_entry.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/stock/stock_ledger.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/timestamps.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/units.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/utils.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/validation.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/lambda_erp/workflow.py +0 -0
- {lambda_erp-1.4.23 → lambda_erp-1.4.24}/terraform/README.md +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""Social login (Google / Apple) for Lambda ERP.
|
|
1
|
+
"""Social login (Google / Apple / Microsoft) for Lambda ERP.
|
|
2
2
|
|
|
3
3
|
OAuth/OIDC is layered on top of the existing password auth without changing what
|
|
4
4
|
a session *is*: once a provider has proven the user's identity, we mint the very
|
|
@@ -20,6 +20,14 @@ Design notes:
|
|
|
20
20
|
The OIDC nonce is stored with that flow and verified in the ID token.
|
|
21
21
|
- A provider is simply *disabled* (its buttons hidden) whenever its env vars are
|
|
22
22
|
absent, so local/dev runs need no OAuth setup.
|
|
23
|
+
- Microsoft (any Microsoft account by default: personal accounts and the
|
|
24
|
+
users of any organisation) differs in two ways, both handled in
|
|
25
|
+
`_microsoft_identity`: the token's issuer names the user's own tenant, so
|
|
26
|
+
it is checked against the tenant id inside the token instead of one fixed
|
|
27
|
+
string; and the `email` claim is not proof of ownership for organisation
|
|
28
|
+
accounts (their admin can write any address into it, the "nOAuth" attack),
|
|
29
|
+
so the address is only taken when its domain is the one the tenant has
|
|
30
|
+
verified for the user's sign-in name.
|
|
23
31
|
"""
|
|
24
32
|
|
|
25
33
|
import os
|
|
@@ -83,14 +91,47 @@ PROVIDERS = {
|
|
|
83
91
|
"scope": "openid email name",
|
|
84
92
|
"response_mode": "form_post",
|
|
85
93
|
},
|
|
94
|
+
"microsoft": {
|
|
95
|
+
"label": "Microsoft",
|
|
96
|
+
# Per tenant; checked in _microsoft_identity.
|
|
97
|
+
"issuer": None,
|
|
98
|
+
# Built from MICROSOFT_OAUTH_TENANT in _discovery_url.
|
|
99
|
+
"discovery": None,
|
|
100
|
+
"scope": "openid email profile",
|
|
101
|
+
"response_mode": None,
|
|
102
|
+
},
|
|
86
103
|
}
|
|
87
104
|
|
|
105
|
+
# The tenant every personal Microsoft account (outlook.com, hotmail.com, ...)
|
|
106
|
+
# belongs to.
|
|
107
|
+
MICROSOFT_CONSUMER_TENANT = "9188040d-6c67-4c5b-b112-36a304b66dad"
|
|
108
|
+
_GUID = re.compile(r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}")
|
|
109
|
+
_EMAIL = re.compile(r"[^@\s]+@[^@\s]+\.[^@\s]+")
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _microsoft_tenant() -> str:
|
|
113
|
+
"""Who may sign in with Microsoft: "common" (default: any Microsoft
|
|
114
|
+
account), "organizations" (work and school accounts only), "consumers"
|
|
115
|
+
(personal accounts only), or one tenant's id for a single organisation."""
|
|
116
|
+
tenant = (os.environ.get("MICROSOFT_OAUTH_TENANT") or "common").strip().lower()
|
|
117
|
+
if tenant in ("common", "organizations", "consumers") or _GUID.fullmatch(tenant):
|
|
118
|
+
return tenant
|
|
119
|
+
raise HTTPException(status_code=500, detail="MICROSOFT_OAUTH_TENANT must be common, organizations, consumers or a tenant id")
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def _discovery_url(provider: str) -> str:
|
|
123
|
+
if provider == "microsoft":
|
|
124
|
+
return f"https://login.microsoftonline.com/{_microsoft_tenant()}/v2.0/.well-known/openid-configuration"
|
|
125
|
+
return PROVIDERS[provider]["discovery"]
|
|
126
|
+
|
|
88
127
|
|
|
89
128
|
def _client_id(provider: str) -> str | None:
|
|
90
129
|
if provider == "google":
|
|
91
130
|
return os.environ.get("GOOGLE_OAUTH_CLIENT_ID")
|
|
92
131
|
if provider == "apple":
|
|
93
132
|
return os.environ.get("APPLE_OAUTH_CLIENT_ID")
|
|
133
|
+
if provider == "microsoft":
|
|
134
|
+
return os.environ.get("MICROSOFT_OAUTH_CLIENT_ID")
|
|
94
135
|
return None
|
|
95
136
|
|
|
96
137
|
|
|
@@ -103,6 +144,8 @@ def _client_secret(provider: str) -> str | None:
|
|
|
103
144
|
"""
|
|
104
145
|
if provider == "google":
|
|
105
146
|
return os.environ.get("GOOGLE_OAUTH_CLIENT_SECRET")
|
|
147
|
+
if provider == "microsoft":
|
|
148
|
+
return os.environ.get("MICROSOFT_OAUTH_CLIENT_SECRET")
|
|
106
149
|
if provider == "apple":
|
|
107
150
|
team_id = os.environ.get("APPLE_TEAM_ID")
|
|
108
151
|
key_id = os.environ.get("APPLE_KEY_ID")
|
|
@@ -141,7 +184,7 @@ _jwks_cache: dict[str, dict] = {}
|
|
|
141
184
|
|
|
142
185
|
def _discovery(provider: str) -> dict:
|
|
143
186
|
if provider not in _discovery_cache:
|
|
144
|
-
url =
|
|
187
|
+
url = _discovery_url(provider)
|
|
145
188
|
resp = httpx.get(url, timeout=10)
|
|
146
189
|
resp.raise_for_status()
|
|
147
190
|
_discovery_cache[provider] = resp.json()
|
|
@@ -306,6 +349,7 @@ def _verify_id_token(provider: str, id_token: str, nonce: str) -> dict:
|
|
|
306
349
|
key,
|
|
307
350
|
algorithms=[header.get("alg", "RS256")],
|
|
308
351
|
audience=_client_id(provider),
|
|
352
|
+
# None for Microsoft: its issuer is checked in _microsoft_identity.
|
|
309
353
|
issuer=PROVIDERS[provider]["issuer"],
|
|
310
354
|
# Apple omits at_hash; we don't pass the access token, so disable it.
|
|
311
355
|
options={"verify_at_hash": False},
|
|
@@ -314,9 +358,56 @@ def _verify_id_token(provider: str, id_token: str, nonce: str) -> dict:
|
|
|
314
358
|
raise HTTPException(status_code=400, detail=f"Identity token rejected: {exc}")
|
|
315
359
|
if nonce and claims.get("nonce") != nonce:
|
|
316
360
|
raise HTTPException(status_code=400, detail="Sign-in nonce mismatch")
|
|
361
|
+
if provider == "microsoft":
|
|
362
|
+
claims = _microsoft_identity(claims)
|
|
317
363
|
return claims
|
|
318
364
|
|
|
319
365
|
|
|
366
|
+
def _microsoft_identity(claims: dict) -> dict:
|
|
367
|
+
"""Finish verifying a Microsoft ID token (its signature, audience, expiry
|
|
368
|
+
and nonce are already checked) and put it in the shape the callback
|
|
369
|
+
expects: `sub`, `email`, `email_verified`.
|
|
370
|
+
|
|
371
|
+
Issuer: a token from the multi-tenant endpoint is issued by the user's own
|
|
372
|
+
tenant, `https://login.microsoftonline.com/<tid>/v2.0`. It must be exactly
|
|
373
|
+
that for the `tid` it carries, and that tenant must be one this deployment
|
|
374
|
+
admits (MICROSOFT_OAUTH_TENANT).
|
|
375
|
+
|
|
376
|
+
Subject: tenant id + object id, the user's identity at Microsoft that does
|
|
377
|
+
not change with the app registration (`sub` alone is per registration).
|
|
378
|
+
|
|
379
|
+
E-mail: see the module docstring. Personal accounts: the address Microsoft
|
|
380
|
+
holds. Organisation accounts: the `email` claim only when its domain is
|
|
381
|
+
that of the sign-in name (`preferred_username`), which the tenant has
|
|
382
|
+
verified; else the sign-in name; none for a guest of the tenant.
|
|
383
|
+
"""
|
|
384
|
+
tid = str(claims.get("tid") or "").lower()
|
|
385
|
+
if not _GUID.fullmatch(tid):
|
|
386
|
+
raise HTTPException(status_code=400, detail="Identity token rejected: no tenant")
|
|
387
|
+
if claims.get("iss") != f"https://login.microsoftonline.com/{tid}/v2.0":
|
|
388
|
+
raise HTTPException(status_code=400, detail="Identity token rejected: issuer does not match its tenant")
|
|
389
|
+
personal = tid == MICROSOFT_CONSUMER_TENANT
|
|
390
|
+
admitted = _microsoft_tenant()
|
|
391
|
+
if (admitted == "organizations" and personal) or (admitted == "consumers" and not personal) \
|
|
392
|
+
or (_GUID.fullmatch(admitted) and tid != admitted):
|
|
393
|
+
raise HTTPException(status_code=403, detail="This Microsoft account is not from an organisation that may sign in here")
|
|
394
|
+
|
|
395
|
+
oid = str(claims.get("oid") or "").lower()
|
|
396
|
+
subject = f"{tid}:{oid}" if _GUID.fullmatch(oid) else claims.get("sub")
|
|
397
|
+
|
|
398
|
+
mail = str(claims.get("email") or "").strip().lower()
|
|
399
|
+
upn = str(claims.get("preferred_username") or "").strip().lower()
|
|
400
|
+
mail = mail if _EMAIL.fullmatch(mail) else ""
|
|
401
|
+
upn = upn if _EMAIL.fullmatch(upn) and "#ext#" not in upn else ""
|
|
402
|
+
if personal:
|
|
403
|
+
email = mail or upn
|
|
404
|
+
elif mail and upn and mail.rsplit("@", 1)[1] == upn.rsplit("@", 1)[1]:
|
|
405
|
+
email = mail
|
|
406
|
+
else:
|
|
407
|
+
email = upn
|
|
408
|
+
return {**claims, "sub": subject, "email": email or None, "email_verified": bool(email)}
|
|
409
|
+
|
|
410
|
+
|
|
320
411
|
def _email_is_verified(claims: dict) -> bool:
|
|
321
412
|
val = claims.get("email_verified")
|
|
322
413
|
return val is True or str(val).lower() == "true"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|