go auth_error ai_generated true

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

Also available as: JSON · Markdown · 中文
80%Fix Rate
87%Confidence
0Evidence
2025-01-15First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.0 active
1.1 active

Root Cause

The authentication token used in the gRPC call has expired, requiring a new token.

generic

中文

gRPC调用中使用的身份验证令牌已过期,需要新令牌。

Workarounds

  1. 90% success 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}))
  2. 85% success 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...)
    }

Dead Ends

Common approaches that don't work:

  1. Use the same expired token and hope it works. 100% fail

    The server checks expiration; expired tokens are always rejected.

  2. Manually extend the token's expiration without re-authentication. 95% fail

    Token expiration is enforced by the auth server; manual changes are invalid.