Skip to content

Commit f0cf5fe

Browse files
committed
hookd: improve user-facing error message for expired jwt
1 parent b89805c commit f0cf5fe

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

pkg/grpc/interceptor/auth/server.go

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package auth_interceptor
33
import (
44
"context"
55
"encoding/hex"
6+
"errors"
67
"fmt"
78
"math"
89
"time"
@@ -75,6 +76,10 @@ func (s *ServerInterceptor) UnaryServerInterceptor(ctx context.Context, req inte
7576
if err != nil {
7677
log.WithError(err).Infof("validating token")
7778
metrics.InterceptorRequest(requestTypeJWT, "invalid_jwt")
79+
80+
if errors.Is(err, jwt.ErrTokenExpired()) {
81+
return nil, status.Errorf(codes.Unauthenticated, "authentication token has expired")
82+
}
7883
return nil, status.Errorf(codes.Unauthenticated, err.Error())
7984
}
8085

@@ -179,6 +184,9 @@ func (s *ServerInterceptor) StreamServerInterceptor(srv interface{}, ss grpc.Ser
179184
if jwtToken != "" {
180185
t, err := s.TokenValidator.Validate(ss.Context(), jwtToken)
181186
if err != nil {
187+
if errors.Is(err, jwt.ErrTokenExpired()) {
188+
return status.Errorf(codes.Unauthenticated, "authentication token has expired")
189+
}
182190
return status.Errorf(codes.Unauthenticated, err.Error())
183191
}
184192

0 commit comments

Comments
 (0)