[Bug] User Realm Discovery drops the authority's port, so username/password sign-in fails on non-443 authorities
Maintainer thường phản hồi trong vòng 7 ngày
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- azure, python
- Lĩnh vực
- authentication
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 971
- Fork
- 223
- Merge trung bình
- 4 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 3
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của AzureAD/microsoft-authentication-library-for-python
-
needs attention untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
AzureAD/microsoft-authentication-library-for-python#997 ·
Maintainer thường phản hồi trong vòng 7 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
AzureAD/microsoft-authentication-library-for-python#980 ·
Maintainer thường phản hồi trong vòng 7 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 55/100
AzureAD/microsoft-authentication-library-for-python#984 ·
Maintainer thường phản hồi trong vòng 7 ngày
-
[Bug] Support library-agnostic HTTP clients for Service Fabric managed identityCó thể đã có người làm @4gust đã nhận 20 ngày trước. Đang mởAzureSDK bug P1
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
AzureAD/microsoft-authentication-library-for-python#965 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 7 ngày
-
http_client docstring does not say that timeout, verify and proxies only configure the default sessionCó thể đã có người làm @HardMax71 đã nhận 84 ngày trước. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 25/100
AzureAD/microsoft-authentication-library-for-python#960 ·
Maintainer thường phản hồi trong vòng 7 ngày
Tất cả issue của AzureAD/microsoft-authentication-library-for-python
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
bad-antics/lateralus-lang#1623 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
fossguild/thelifesnake#82 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Unfitted DialectClassifier crashes with a confusing ValueError: raise a clear "not fitted" errorĐang mởgood first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
omarelshamy25x/shamy-arabic-nlp#111 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
pietbarber/Manage2Soar#1189 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
BUG: write_netcdf fails on Tutorial 3 BEM output with pandas CategoricalDtype DOF coordinatesCó thể đã có người làm @dtgaebe đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
sandialabs/WecOptTool#467 ·