[Bug] User Realm Discovery drops the authority's port, so username/password sign-in fails on non-443 authorities
Maintainer antworten meist innerhalb von 2 Tagen
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 25/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- azure, python
- Bereich
- authentication
Rechercherichtung
The bug is in msal/authority.py, where the User Realm Discovery URL is built from Authority.instance (hostname only) instead of netloc, and the _domains_without_user_realm_discovery memo is keyed the same way. Read canonicalize() and the user realm lookup, then reproduce with a local HTTPS server on a non-443 port. Done when the userrealm request goes to the authority's port and tests cover a non-default port. Note that PR #990 is already open against this issue.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Describe the bug
acquire_token_by_username_password() ignores the port of an authority on a non-default port when it does User Realm Discovery. With authority="https://localhost:8443/organizations", tenant discovery correctly goes to https://localhost:8443/organizations/v2.0/.well-known/openid-configuration, but the user realm request goes to https://localhost/common/userrealm/{username}?api-version=1.0, which is port 443.
#484 fixed the same thing for tenant discovery, for an Azure CLI custom cloud whose activeDirectory endpoint is https://localhost:3001 (Azure/azure-cli#22553). User Realm Discovery still builds its URL from Authority.instance, which canonicalize() sets to authority.hostname, without the port:
So in that same custom-cloud setup, az login --use-device-code and az login --service-principal work, but az login -u USER -p PASSWORD dials port 443 instead.
To Reproduce
Any OIDC-compliant authority served on a port other than 443 works. Here it is a local Entra-compatible server behind HTTPS on 8443:
import msal
app = msal.PublicClientApplication(
"04b07795-8ddb-461a-bbee-02f9e1bf7b46",
authority="https://localhost:8443/organizations",
instance_discovery=False)
app.acquire_token_by_username_password(
"[email protected]", "password",
scopes=["https://management.core.windows.net//.default"])
Expected behavior
GET https://localhost:8443/common/userrealm/[email protected]?api-version=1.0, then the token request.
What you see instead
The server on 8443 receives only the tenant discovery request. MSAL then sends GET https://localhost/common/userrealm/... to port 443. Depending on the machine, that is refused, hangs (WSL2 with mirrored networking), or reaches whatever else is listening on 443.
The MSAL Python version you are using
1.39.0, and dev at e86a1aa.
Additional context
The fix is to build the URL from the authority's netloc instead of instance. The same applies to the _domains_without_user_realm_discovery memo, so that a 404 from one port doesn't turn off User Realm Discovery for another. instance should stay as it is, because the token cache uses it as the account's environment. I have a PR with tests ready to open.
- Vorherrschende Sprache
- Python
- Sterne
- 971
- Forks
- 223
- Ø Merge
- 3 T. 2 Std.
- Gemergte PRs (30 T.)
- 4
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus AzureAD/microsoft-authentication-library-for-python
-
[Bug] Outdated cryptography version ceiling prevents upgrading to v51Evtl. vergeben @Roshithapendela hat das heute übernommen. Offenneeds attention untriaged
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
AzureAD/microsoft-authentication-library-for-python#997 · 2 Kommentare · 1 Reaktion ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
AzureAD/microsoft-authentication-library-for-python#980 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 55/100
AzureAD/microsoft-authentication-library-for-python#984 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
[Bug] Support library-agnostic HTTP clients for Service Fabric managed identityEvtl. vergeben @4gust hat das vor 20 Tagen übernommen. OffenAzureSDK bug P1
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
AzureAD/microsoft-authentication-library-for-python#965 · 1 Kommentar · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 2 Tagen
-
http_client docstring does not say that timeout, verify and proxies only configure the default sessionEvtl. vergeben @HardMax71 hat das vor 84 Tagen übernommen. Offen
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 25/100
AzureAD/microsoft-authentication-library-for-python#960 ·
Maintainer antworten meist innerhalb von 2 Tagen
Alle Issues in AzureAD/microsoft-authentication-library-for-python
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
bad-antics/lateralus-lang#1623 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
fossguild/thelifesnake#82 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Unfitted DialectClassifier crashes with a confusing ValueError: raise a clear "not fitted" errorOffengood first issue
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
omarelshamy25x/shamy-arabic-nlp#111 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
pietbarber/Manage2Soar#1189 ·
Maintainer antworten meist innerhalb von 1 Tag
-
BUG: write_netcdf fails on Tutorial 3 BEM output with pandas CategoricalDtype DOF coordinatesEvtl. vergeben @dtgaebe hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
sandialabs/WecOptTool#467 ·