# rpc error: code = Unauthenticated desc = 缺少授权元数据

- **ID:** `go/grpc-unauthenticated-missing-metadata`
- **领域:** go
- **类别:** auth_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

服务端的鉴权拦截器要求传入元数据中包含授权令牌，但客户端未附加（或使用了错误的键）。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.0+ | active | — | — |

## 解决方案

1. **** (93% 成功率)
   ```
   md := metadata.Pairs("authorization", "Bearer "+token)
ctx := metadata.NewOutgoingContext(ctx, md)
resp, err := client.Get(ctx, req)
   ```
2. **** (90% 成功率)
   ```
   func authUnary(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, inv grpc.UnaryInvoker, opts ...grpc.CallOption) error {
  ctx = metadata.AppendToOutgoingContext(ctx, "authorization", "Bearer "+getToken())
  return inv(ctx, method, req, reply, cc, opts...)
}
   ```

## 无效尝试

- **** — Disables authentication entirely, exposing protected endpoints (90% 失败率)
- **** — May still fail if the interceptor expects a specific metadata key like "authorization" with a "Bearer " prefix (60% 失败率)
