Skip to content

feat: Add native gRPC integration support#377

Open
developerkunal wants to merge 4 commits intomasterfrom
feature/grpc-integration
Open

feat: Add native gRPC integration support#377
developerkunal wants to merge 4 commits intomasterfrom
feature/grpc-integration

Conversation

@developerkunal
Copy link
Copy Markdown
Contributor

@developerkunal developerkunal commented Jan 28, 2026

Description

This PR adds native gRPC support to the JWT middleware SDK, providing out-of-the-box integration for both unary and streaming gRPC methods.

Changes

  • Added gRPC interceptors for unary and streaming methods in integrations/grpc/
  • Implemented metadata-based token extraction following gRPC conventions
  • Added comprehensive test coverage including unit and integration tests
  • Created working example with proto definitions and server implementation
  • Updated main README with gRPC usage documentation
  • Added detailed integration README with examples and API reference

Usage Example

import (
    "google.golang.org/grpc"
    "github.com/auth0/go-jwt-middleware/v3/validator"
    jwtgrpc "github.com/auth0/go-jwt-middleware/v3/integrations/grpc"
)

// Create validator
jwtValidator, err := validator.New(
    keyFunc,
    validator.HS256,
    "https://your-issuer.com/",
    []string{"your-audience"},
)

// Create gRPC interceptor
interceptor, err := jwtgrpc.New(
    jwtgrpc.WithValidator(jwtValidator),
    jwtgrpc.WithExcludedMethods("/grpc.health.v1.Health/Check"),
)

// Create gRPC server with interceptors
grpcServer := grpc.NewServer(
    grpc.UnaryInterceptor(interceptor.UnaryServerInterceptor()),
    grpc.StreamInterceptor(interceptor.StreamServerInterceptor()),
)

// In your handlers, access claims:
func (s *server) GetUser(ctx context.Context, req *pb.GetUserRequest) (*pb.User, error) {
    claims, err := jwtgrpc.GetValidatedClaims(ctx)
    if err != nil {
        return nil, status.Error(codes.Unauthenticated, "invalid token")
    }
    
    // Use claims...
    userID := claims.RegisteredClaims.Subject
    return &pb.User{Id: userID}, nil
}

References

#181

Testing

  • Unit tests pass
  • Integration tests pass
  • Example server runs successfully
  • Test coverage maintained

     Add out-of-the-box gRPC support with unary and streaming interceptors:

     - New integrations/grpc package with interceptor implementation
     - Token extraction from gRPC metadata (authorization header)
     - Custom error handler mapping validation errors to gRPC status codes
     - Helper functions for claims retrieval from context
     - Support for excluded methods/patterns
     - Comprehensive unit tests with 100% coverage
     - Complete gRPC example with client/server implementation
     - Integration tests for the example
     - Updated README with gRPC usage documentation
@developerkunal developerkunal requested a review from a team as a code owner January 28, 2026 14:35
Copilot AI review requested due to automatic review settings January 28, 2026 14:35
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jan 28, 2026

Codecov Report

❌ Patch coverage is 96.09756% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.49%. Comparing base (3b2a7f3) to head (2370a44).

Files with missing lines Patch % Lines
integrations/grpc/interceptor.go 95.87% 2 Missing and 2 partials ⚠️
integrations/grpc/option.go 89.74% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #377      +/-   ##
==========================================
- Coverage   96.55%   96.49%   -0.06%     
==========================================
  Files          18       23       +5     
  Lines        1508     1713     +205     
==========================================
+ Hits         1456     1653     +197     
- Misses         34       39       +5     
- Partials       18       21       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds comprehensive native gRPC support to the JWT middleware SDK, enabling seamless JWT authentication for gRPC services through interceptors for both unary and streaming methods.

Changes:

  • Introduced gRPC-specific interceptors in integrations/grpc/ package with metadata-based token extraction
  • Implemented comprehensive error mapping from JWT validation errors to appropriate gRPC status codes
  • Added complete test coverage including unit tests, integration tests, and a fully functional example application

Reviewed changes

Copilot reviewed 19 out of 21 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
integrations/grpc/interceptor.go Core JWT interceptor implementation for unary and streaming gRPC methods
integrations/grpc/option.go Configuration options with builder pattern for interceptor setup
integrations/grpc/extractor.go Token extraction from gRPC metadata following Bearer token conventions
integrations/grpc/error_handler.go Maps JWT validation errors to appropriate gRPC status codes
integrations/grpc/claims.go Type-safe claims retrieval helpers using generics
integrations/grpc/doc.go Comprehensive package documentation with usage examples
integrations/grpc/*_test.go Extensive unit tests for all components
examples/grpc-example/ Complete working example with server, client, and integration tests
examples/grpc-example/proto/ Protocol Buffer definitions and generated code
go.mod, go.sum Added gRPC dependencies (v1.78.0)
README.md Updated main documentation with gRPC usage examples

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

developerkunal and others added 2 commits January 28, 2026 20:13
@developerkunal developerkunal linked an issue Jan 28, 2026 that may be closed by this pull request
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow middleware to be used in a gRPC environment

3 participants