go
auth_error
ai_generated
true
rpc 错误:代码 = Unauthenticated 描述 = 缺少凭据
rpc error: code = Unauthenticated desc = missing credentials
ID: go/grpc-unauthenticated-missing-credentials
80%修复率
85%置信度
0证据数
2024-11-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.56.x | active | — | — | — |
| 1.57.x | active | — | — | — |
根因分析
客户端未在请求元数据中提供任何身份验证凭据。
English
The client did not provide any authentication credentials in the request metadata.
解决方案
-
100% 成功率
md := metadata.Pairs("authorization", "Bearer mytoken"); ctx := metadata.NewOutgoingContext(context.Background(), md) -
90% 成功率
creds := credentials.NewClientTLSFromCert(nil, ""); conn, err := grpc.Dial(address, grpc.WithTransportCredentials(creds))
-
85% 成功率
interceptor := func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { ctx = metadata.AppendToOutgoingContext(ctx, "authorization", "Bearer mytoken"); return invoker(ctx, method, req, reply, cc, opts...) }
无效尝试
常见但无效的做法:
-
Sending an empty token or user/pass.
90% 失败
Server still sees no valid credentials.
-
Removing auth checks.
80% 失败
Security risk.
-
Not adding any metadata.
100% 失败
Same error will occur.