# rpc error: code = Unauthenticated desc = missing or invalid authorization token

- **ID:** `go/grpc-unauthenticated-token`
- **Domain:** go
- **Category:** auth_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The server's auth interceptor rejected the request because the metadata did not contain a valid bearer token, or the token was expired/malformed. Common when the client forgets to attach metadata or uses the wrong metadata key.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.x | active | — | — |

## Workarounds

1. **** (90% success)
   ```
   Attach the token via outgoing metadata with a lowercase key and the Bearer scheme:

md := metadata.Pairs("authorization", "Bearer "+token)
ctx := metadata.NewOutgoingContext(context.Background(), md)
resp, err := client.Do(ctx, req)
   ```
2. **** (88% success)
   ```
   Use a client interceptor to inject a freshly refreshed token on every call:

func authInterceptor(token *oauth2.TokenSource) grpc.UnaryClientInterceptor {
    return func(ctx context.Context, m string, req, reply interface{}, cc *grpc.ClientConn, inv grpc.UnaryInvoker, opts ...grpc.CallOption) error {
        t, _ := token.Token()
        ctx = metadata.AppendToOutgoingContext(ctx, "authorization", "Bearer "+t.AccessToken)
        return inv(ctx, m, req, reply, cc, opts...)
    }
}
   ```

## Dead Ends

- **** — gRPC metadata keys are lowercased; an uppercase key like "Authorization" is not recognized by the server's lookup for "authorization". (70% fail)
- **** — An expired or missing token never becomes valid on retry; the server rejects each attempt identically. (95% fail)
