[Bug] User Realm Discovery drops the authority's port, so username/password sign-in fails on non-443 authorities
維護者通常 2 天內回覆
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 25/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- azure, python
研究方向
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.
由索引模型根據 Issue 內容生成。
描述
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.
- 主要語言
- Python
- 星號
- 971
- 分支
- 223
- 平均合併
- 3 天 2 小時
- 30 天內合併 PR
- 4
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
AzureAD/microsoft-authentication-library-for-python 的其他 Issue
-
[Bug] Outdated cryptography version ceiling prevents upgrading to v51可能已有人在做 @Roshithapendela 今天認領。 未關閉needs attention untriaged
難度 2/5 1-3 小時 新手友好度 75/100
AzureAD/microsoft-authentication-library-for-python#997 · 2 則留言 · 1 個 reaction ·
維護者通常 2 天內回覆
-
難度 1/5 1 小時以內 新手友好度 88/100
AzureAD/microsoft-authentication-library-for-python#980 ·
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 55/100
AzureAD/microsoft-authentication-library-for-python#984 ·
維護者通常 2 天內回覆
-
[Bug] Support library-agnostic HTTP clients for Service Fabric managed identity可能已有人在做 @4gust 於 20 天前認領。 未關閉AzureSDK bug P1
難度 4/5 3-5 天 新手友好度 48/100
AzureAD/microsoft-authentication-library-for-python#965 · 1 則留言 · 已指派 1 人 ·
維護者通常 2 天內回覆
-
http_client docstring does not say that timeout, verify and proxies only configure the default session可能已有人在做 @HardMax71 於 84 天前認領。 未關閉
難度 1/5 1 小時以內 新手友好度 25/100
AzureAD/microsoft-authentication-library-for-python#960 ·
維護者通常 2 天內回覆
查看 AzureAD/microsoft-authentication-library-for-python 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 68/100
bad-antics/lateralus-lang#1623 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 74/100
fossguild/thelifesnake#82 ·
維護者通常 1 天內回覆
-
Unfitted DialectClassifier crashes with a confusing ValueError: raise a clear "not fitted" error未關閉good first issue
難度 2/5 1-3 小時 新手友好度 88/100
omarelshamy25x/shamy-arabic-nlp#111 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
pietbarber/Manage2Soar#1189 ·
維護者通常 1 天內回覆
-
BUG: write_netcdf fails on Tutorial 3 BEM output with pandas CategoricalDtype DOF coordinates可能已有人在做 @dtgaebe 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 72/100
sandialabs/WecOptTool#467 ·