go
auth_error
ai_generated
true
rpc错误:代码=未认证 描述=令牌已过期:当前时间2025-01-15T10:00:00Z晚于到期时间2025-01-15T09:00:00Z
rpc error: code = Unauthenticated desc = token expired: current time 2025-01-15T10:00:00Z is after exp 2025-01-15T09:00:00Z
ID: go/grpc-unauthenticated-token-expired
80%修复率
87%置信度
0证据数
2025-01-15首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.0 | active | — | — | — |
| 1.1 | active | — | — | — |
根因分析
gRPC调用中使用的身份验证令牌已过期,需要新令牌。
English
The authentication token used in the gRPC call has expired, requiring a new token.
解决方案
-
90% 成功率 Refresh the token before making the RPC call.
token, err := refreshToken() if err != nil { log.Fatal(err) } conn, err := grpc.Dial("localhost:8080", grpc.WithInsecure(), grpc.WithPerRPCCredentials(&tokenCreds{token: token})) -
85% 成功率 Implement automatic token refresh in an interceptor.
func refreshInterceptor(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { token, err := getValidToken() if err != nil { return err } md := metadata.Pairs("authorization", "Bearer "+token) ctx = metadata.NewOutgoingContext(ctx, md) return invoker(ctx, method, req, reply, cc, opts...) }
无效尝试
常见但无效的做法:
-
Use the same expired token and hope it works.
100% 失败
The server checks expiration; expired tokens are always rejected.
-
Manually extend the token's expiration without re-authentication.
95% 失败
Token expiration is enforced by the auth server; manual changes are invalid.