[Bug] User Realm Discovery drops the authority's port, so username/password sign-in fails on non-443 authorities
Les mainteneurs répondent en général sous 2 jours
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 25/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- azure, python
- Domaine
- authentication
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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.
- Langage dominant
- Python
- Étoiles
- 971
- Forks
- 223
- Merge moyen
- 3 j 2 h
- PR mergées (30 j)
- 4
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de AzureAD/microsoft-authentication-library-for-python
-
[Bug] Outdated cryptography version ceiling prevents upgrading to v51Peut-être pris @Roshithapendela l’a pris aujourd’hui. Ouverteneeds attention untriaged
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
AzureAD/microsoft-authentication-library-for-python#997 · 2 commentaires · 1 réaction ·
Les mainteneurs répondent en général sous 2 jours
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 88/100
AzureAD/microsoft-authentication-library-for-python#980 ·
Les mainteneurs répondent en général sous 2 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 55/100
AzureAD/microsoft-authentication-library-for-python#984 ·
Les mainteneurs répondent en général sous 2 jours
-
[Bug] Support library-agnostic HTTP clients for Service Fabric managed identityPeut-être pris @4gust l’a pris il y a 20 jours. OuverteAzureSDK bug P1
Difficulté 4/5 3-5 jours Accessibilité débutants 48/100
AzureAD/microsoft-authentication-library-for-python#965 · 1 commentaire · 1 personne assignée ·
Les mainteneurs répondent en général sous 2 jours
-
http_client docstring does not say that timeout, verify and proxies only configure the default sessionPeut-être pris @HardMax71 l’a pris il y a 84 jours. Ouverte
Difficulté 1/5 Moins d'une heure Accessibilité débutants 25/100
AzureAD/microsoft-authentication-library-for-python#960 ·
Les mainteneurs répondent en général sous 2 jours
Toutes les issues de AzureAD/microsoft-authentication-library-for-python
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
bad-antics/lateralus-lang#1623 ·
Les mainteneurs répondent en général sous 1 jour
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
fossguild/thelifesnake#82 ·
Les mainteneurs répondent en général sous 1 jour
-
Unfitted DialectClassifier crashes with a confusing ValueError: raise a clear "not fitted" errorOuvertegood first issue
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
omarelshamy25x/shamy-arabic-nlp#111 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
pietbarber/Manage2Soar#1189 ·
Les mainteneurs répondent en général sous 1 jour
-
BUG: write_netcdf fails on Tutorial 3 BEM output with pandas CategoricalDtype DOF coordinatesPeut-être pris @dtgaebe l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
sandialabs/WecOptTool#467 ·