MCPcopy Create free account
hub / github.com/diillson/chatcli / NewTokenAuthInterceptor

Function NewTokenAuthInterceptor

server/auth.go:42–59  ·  view source on GitHub ↗

NewTokenAuthInterceptor creates a new auth interceptor. If token is empty and no JWT config is set, authentication is disabled. JWT is configured via CHATCLI_JWT_SECRET environment variable.

(token string, logger *zap.Logger)

Source from the content-addressed store, hash-verified

40// If token is empty and no JWT config is set, authentication is disabled.
41// JWT is configured via CHATCLI_JWT_SECRET environment variable.
42func NewTokenAuthInterceptor(token string, logger *zap.Logger) *TokenAuthInterceptor {
43 ai := &TokenAuthInterceptor{
44 token: token,
45 logger: logger,
46 failureLimiters: make(map[string]*rate.Limiter),
47 }
48
49 // Load JWT secret from environment if available
50 if secret := os.Getenv("CHATCLI_JWT_SECRET"); secret != "" {
51 ai.jwtSecret = []byte(secret)
52 logger.Info("JWT authentication enabled (HS256)")
53 }
54
55 // Start background cleanup to prevent memory leak from auth failure limiters
56 ai.startFailureLimiterCleanup()
57
58 return ai
59}
60
61// Unary returns a grpc.UnaryServerInterceptor that validates credentials and
62// injects UserInfo into the context for downstream access control.

Calls 2

InfoMethod · 0.65