Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Empty `AuthToken` Causes Cryptic JWT Parse Error

Đang mở Phù hợp với người mới
#551 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

@aniket866 đang làm issue này rồi.

Từ ngày 28/9/2026.

  • #552 của @aniket866 — đang mở

Đá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
86/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ệ
go
Lĩnh vực
authentication, cli

Hướng nghiên cứu

Bắt đầu trong pkg/connectors/microcks_client.go tại refreshAuthToken và theo dõi cách lỗi của nó đến NewClient và CLI. Tái hiện trường hợp AuthToken rỗng sau khi xóa access token đã cấu hình, sau đó xác minh rằng người dùng nhận được thông báo chưa xác thực như mong đợi thay vì lỗi phân tích JWT.

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

Mô tả

Describe the bug
Description

refreshAuthToken in pkg/connectors/microcks_client.go calls
jwt.ParseUnverified(configCtx.User.AuthToken, &claims) without first checking
whether AuthToken is empty. After a fresh install, after logout --token-only,
or whenever the config exists but contains no token, AuthToken is "". The JWT
parser returns an error for the empty string, which propagates all the way up to
NewClient and then to the user as a low-level JWT error rather than a
human-readable "please run microcks login" message.

// microcks_client.go (refreshAuthToken)
if c.RefreshToken == "" {
    return nil  // ← correctly handles empty refresh token
}
// ... but AuthToken="" is never guarded:
_, _, err = parser.ParseUnverified(configCtx.User.AuthToken, &claims)
if err != nil {
    return err  // ← surfaces as "token is malformed: ..." to the user
}
How to Reproduce
  1. Log in, then selectively clear just the access token from the config:
    # Edit ~/.config/microcks/config and set auth-token to empty string
    microcks service list  # → "token is malformed: token contains an invalid number of segments"
    
  2. Compare with the expected UX:
    # Expected
    Error: not authenticated. Run `microcks login` first.
    
Diagram
flowchart TD
    A["NewClient() called"] --> B["ReadLocalConfig()"]
    B --> C["configCtx.User.AuthToken = ''"]
    C --> D["refreshAuthToken()"]

    D --> E{"c.RefreshToken == ''?"}
    E -- "no — refresh token exists" --> F["jwt.ParseUnverified('' , &claims)"]
    F --> G["jwt.ErrTokenMalformed ← cryptic error"]
    G --> H["NewClient returns error to caller"]
    H --> I["CLI prints: 'token is malformed: token contains an invalid\nnumber of segments' "]

    E -- "yes — no refresh token" --> J["return nil (no-op) "]

    subgraph Fix
        D --> K{"c.AuthToken == ''?"}
        K -- "yes" --> L["return ErrNotAuthenticated "]
        K -- "no" --> F
    end

    style G fill:#e74c3c,color:#fff
    style I fill:#e74c3c,color:#fff
    style J fill:#2ecc71,color:#fff
    style L fill:#2ecc71,color:#fff
Expected behavior

No response

Actual behavior

No response

How to Reproduce?

No response

Microcks version or git rev

No response

Install method (docker-compose, helm chart, operator, docker-desktop extension,...)

No response

Additional information

No response

Ngôn ngữ chính
Go
Star
57
Fork
73
Merge trung bình
1 ngày 9 giờ
Pull request đã merge (30 ngày)
28

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

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 microcks/microcks-cli

Tất cả issue của microcks/microcks-cli

Issue tương tự

Thêm issue về Go

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.