Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT: Backend Auth Completed for HTTP #36

Merged
merged 19 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/services/accounts-api/cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (

connectrpcadapter "apps/services/accounts-api/internal/adapters/connectrpc"
"apps/services/accounts-api/internal/adapters/database/repositories"
"libs/backend/auth"
"libs/backend/boot"
"libs/backend/httpauth"
"libs/backend/proto-gen/go/accounts/accountsapi/v1/accountsapiv1connect"
)

Expand Down Expand Up @@ -49,7 +49,7 @@ func run() error {
}

// Custom interceptors
authInterceptor := auth.NewAuthInterceptor(logger)
authInterceptor := httpauth.NewAuthInterceptor(logger)

options := []connect.HandlerOption{
connect.WithInterceptors(
Expand Down
5 changes: 2 additions & 3 deletions apps/services/accounts-graphql/cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (
"apps/services/accounts-graphql/internal/graph/resolvers"
"context"
"errors"
"libs/backend/auth"
"libs/backend/boot"
"libs/backend/cache"
auth "libs/backend/httpauth"
"log"
"log/slog"
"os"
Expand All @@ -21,8 +22,6 @@ import (
"github.com/vektah/gqlparser/v2/ast"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"

"libs/backend/boot"
)

// serviceName is the name of the microservice
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions apps/services/apollo-router/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
APOLLO_KEY=""
APOLLO_REF=""
6 changes: 6 additions & 0 deletions apps/services/apollo-router/supergraph-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ subgraphs:
routing_url: http://accounts-graphql-prod.internal:8080/graphql # <- can be omitted if the same as introspection URL
schema:
subgraph_url: http://localhost:3003/graphql
include_subgraph_errors:
all: true
telemetry:
instrumentation:
spans:
mode: spec_compliant
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ services:
container_name: apollo-router
ports:
- '4000:4000'
env_file:
- ./apps/services/apollo-router/.env.local
volumes:
- ./graphql/supergraph-dev.yaml:/supergraph.yaml
- ./graphql/supergraph-dev.graphql:/supergraph.graphql
Expand Down
2 changes: 1 addition & 1 deletion go.work
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use (
./apps/services/accounts-graphql
./apps/services/accounts-worker
./apps/services/inbound-webhooks-api
./libs/backend/auth
./libs/backend/httpauth
./libs/backend/boot
./libs/backend/cache
./libs/backend/domain/user
Expand Down
6 changes: 6 additions & 0 deletions graphql/supergraph-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ subgraphs:
routing_url: http://accounts-graphql:3000/graphql # <- can be omitted if the same as introspection URL
schema:
subgraph_url: http://localhost:3003/graphql
include_subgraph_errors:
all: true
telemetry:
instrumentation:
spans:
mode: spec_compliant
11 changes: 0 additions & 11 deletions libs/backend/auth/go.mod

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package auth
package httpauth

import "context"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package auth
package httpauth

const (
// Used for headers to be sent and recieved via HTTP and ConnectRPC
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package auth
package httpauth

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package auth
package httpauth

import "errors"

Expand Down
15 changes: 15 additions & 0 deletions libs/backend/httpauth/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module libs/backend/httpauth

go 1.23

require (
connectrpc.com/connect v1.17.0
github.com/auth0/go-jwt-middleware/v2 v2.2.2
)

require (
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/sync v0.8.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/go-jose/go-jose.v2 v2.6.3 // indirect
)
8 changes: 8 additions & 0 deletions libs/backend/auth/go.sum → libs/backend/httpauth/go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
connectrpc.com/connect v1.17.0 h1:W0ZqMhtVzn9Zhn2yATuUokDLO5N+gIuBWMOnsQrfmZk=
connectrpc.com/connect v1.17.0/go.mod h1:0292hj1rnx8oFrStN7cB4jjVBeqs+Yx5yDIC2prWDO8=
github.com/auth0/go-jwt-middleware/v2 v2.2.2 h1:vrvkFZf72r3Qbt45KLjBG3/6Xq2r3NTixWKu2e8de9I=
github.com/auth0/go-jwt-middleware/v2 v2.2.2/go.mod h1:4vwxpVtu/Kl4c4HskT+gFLjq0dra8F1joxzamrje6J0=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand All @@ -10,8 +12,14 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/go-jose/go-jose.v2 v2.6.3 h1:nt80fvSDlhKWQgSWyHyy5CfmlQr+asih51R8PTWNKKs=
gopkg.in/go-jose/go-jose.v2 v2.6.3/go.mod h1:zzZDPkNNw/c9IE7Z9jr11mBZQhKQTMzoEEIoEdZlFBI=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package auth
package httpauth

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion libs/backend/auth/jwt.go → libs/backend/httpauth/jwt.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package auth
package httpauth

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package auth
package httpauth

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "auth",
"name": "httpauth",
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"sourceRoot": "libs/backend/auth",
"sourceRoot": "libs/backend/httpauth",
"tags": ["services", "api", "authentication"],
"targets": {
"test": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"libs/backend/boot"
"libs/backend/cache"
"libs/backend/httpauth"
)

// serviceName is the name of the microservice
Expand Down Expand Up @@ -108,7 +109,7 @@ func run() error {
})

params.Mux.Handle("/", playground.Handler("GraphQL playground", "/graphql"))
params.Mux.Handle("/graphql", srv)
params.Mux.Handle("/graphql", httpauth.AuthMiddleware(srv))

return nil
},
Expand Down
Loading