Identity.Name is always null on the client: the access token names the user in unique_name, the client reads name

Đang mở Phù hợp với người mới
#15,051 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
75/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ệ
csharp
Lĩnh vực
authentication

Hướng nghiên cứu

Bắt đầu từ IAuthTokenProvider.ParseAccessToken, nơi ClaimsPrincipal của client được tạo với nameType: "name", rồi so sánh với tên claim mà server ghi (unique_name). Kiểm tra ClaimsPrincipalExtensions.GetUserName() và AuthManager.KeepActiveAccount để xem tên được đọc như thế nào. Hoàn thành khi Identity.Name không null đối với người dùng đã đăng nhập trên client và các bài kiểm thử xác thực hiện có vẫn pass.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

The server writes the access token with JwtSecurityTokenHandler, which writes ClaimTypes.Name under its short name unique_name (its DefaultOutboundClaimTypeMap). IAuthTokenProvider.ParseAccessToken builds the client's ClaimsPrincipal with nameType: "name", so on the client Identity.Name is null for every signed-in user.

The client's authentication state comes from that principal, so context.User.Identity.Name in an AuthorizeView and AuthenticationState.User.Identity.Name are null as well. In the template itself, AuthManager.KeepActiveAccount takes the kept account's UserName from it, so an account whose profile hasn't been loaded is kept with no user name. Most of the template doesn't notice, because ClaimsPrincipalExtensions.GetUserName() reads both ClaimTypes.Name and unique_name.

The parsed principal's name type should be the claim the server writes, so Identity.Name holds the user's name on the client as it does on the server.

Ngôn ngữ chính
C#
Star
1.4k
Fork
264
Merge trung bình
8 giờ 58 phút
Pull request đã merge (30 ngày)
579

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của bitfoundation/bitplatform

Tất cả issue của bitfoundation/bitplatform

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.