{
  "id": "go/grpc-unauthenticated-token",
  "signature": "rpc error: code = Unauthenticated desc = missing or invalid authorization token",
  "signature_zh": "rpc 错误：code = Unauthenticated desc = 授权令牌缺失或无效",
  "regex": "rpc\\ error:\\ code\\ =\\ Unauthenticated\\ desc\\ =\\ missing\\ or\\ invalid\\ authorization\\ token",
  "domain": "go",
  "category": "auth_error",
  "subcategory": null,
  "root_cause": "The server's auth interceptor rejected the request because the metadata did not contain a valid bearer token, or the token was expired/malformed. Common when the client forgets to attach metadata or uses the wrong metadata key.",
  "root_cause_type": "generic",
  "root_cause_zh": "服务器的认证拦截器拒绝了请求，因为元数据中不包含有效的 bearer 令牌，或令牌已过期/格式错误。常见于客户端忘记附加元数据或使用了错误的元数据键。",
  "versions": [
    {
      "version": "1.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "gRPC metadata keys are lowercased; an uppercase key like \"Authorization\" is not recognized by the server's lookup for \"authorization\".",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "An expired or missing token never becomes valid on retry; the server rejects each attempt identically.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Attach the token via outgoing metadata with a lowercase key and the Bearer scheme:\n\nmd := metadata.Pairs(\"authorization\", \"Bearer \"+token)\nctx := metadata.NewOutgoingContext(context.Background(), md)\nresp, err := client.Do(ctx, req)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.88,
      "how": "Use a client interceptor to inject a freshly refreshed token on every call:\n\nfunc authInterceptor(token *oauth2.TokenSource) grpc.UnaryClientInterceptor {\n    return func(ctx context.Context, m string, req, reply interface{}, cc *grpc.ClientConn, inv grpc.UnaryInvoker, opts ...grpc.CallOption) error {\n        t, _ := token.Token()\n        ctx = metadata.AppendToOutgoingContext(ctx, \"authorization\", \"Bearer \"+t.AccessToken)\n        return inv(ctx, m, req, reply, cc, opts...)\n    }\n}",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-09-12",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}