# rpc 错误：代码 = Unauthenticated 描述 = 缺少或无效的身份验证令牌

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

## 根因

gRPC 请求未包含所需的身份验证元数据（例如授权令牌），或者令牌无效。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.x | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   md := metadata.Pairs("authorization", "Bearer "+token); ctx := metadata.NewOutgoingContext(context.Background(), md); resp, err := client.Call(ctx, ...)
   ```
2. **** (85% 成功率)
   ```
   Implement a token provider that obtains and caches valid tokens.
   ```

## 无效尝试

- **** — This weakens security and is not advisable in production. (80% 失败率)
- **** — The server will still reject it. (90% 失败率)
