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

- **ID:** `go/grpc-permission-denied-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.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.45+ | active | — | — |

## Workarounds

1. **** (92% success)
   ```
   md := metadata.Pairs("authorization", "Bearer "+token)
ctx = metadata.NewOutgoingContext(ctx, md)
resp, err := client.Get(ctx, req)
// or as a unary interceptor:
func auth(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, inv grpc.UnaryInvoker, opts ...grpc.CallOption) error {
    ctx = metadata.AppendToOutgoingContext(ctx, "authorization", "Bearer "+getToken())
    return inv(ctx, method, req, reply, cc, opts...)
}
   ```
2. **** (90% success)
   ```
   type tokenAuth struct{ token string }
func (t tokenAuth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
    return map[string]string{"authorization": "Bearer " + t.token}, nil
}
func (t tokenAuth) RequireTransportSecurity() bool { return true }
conn, _ := grpc.Dial(addr, grpc.WithPerRPCCredentials(tokenAuth{token: tok}))
   ```

## Dead Ends

- **** — An expired or malformed token is rejected deterministically on every attempt. (92% fail)
- **** — Removes the security boundary entirely and lets unauthenticated clients reach protected handlers. (95% fail)
