Skip to content

Commit

Permalink
fix: access token being sent for all resolvers
Browse files Browse the repository at this point in the history
  • Loading branch information
ericzorn93 committed Jan 6, 2025
1 parent 6650d30 commit 10e3791
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.

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

8 changes: 4 additions & 4 deletions libs/backend/auth/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ type authMiddlewareContextKey struct{}
// AuthMiddlewareContextKey will be used to obtain and set context auth
var AuthMiddlewareContextKey authMiddlewareContextKey = authMiddlewareContextKey{}

// SetClaims will assign the custom claims to the conext
func SetClaims(ctx context.Context, claims *validator.ValidatedClaims) context.Context {
// SetClaimsToContext will assign the custom claims to the conext
func SetClaimsToContext(ctx context.Context, claims *validator.ValidatedClaims) context.Context {
return context.WithValue(ctx, ClaimsKey, claims.CustomClaims.(*CustomClaims))
}

// GetClaims will pull the custom claims out of the context
func GetClaims(ctx context.Context) (*CustomClaims, error) {
// GetClaimsFromContext will pull the custom claims out of the context
func GetClaimsFromContext(ctx context.Context) (*CustomClaims, error) {
claims := ctx.Value(ClaimsKey)
customClaimsValidated, ok := claims.(*CustomClaims)

Expand Down
3 changes: 2 additions & 1 deletion libs/backend/auth/interceptors.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ func (a AuthInerceptor) Incoming() connect.UnaryInterceptorFunc {
)
}

ctx = SetClaims(ctx, claims.(*validator.ValidatedClaims))
// Set the validated custom claims to the context
ctx = SetClaimsToContext(ctx, claims.(*validator.ValidatedClaims))

return next(ctx, req)
})
Expand Down

0 comments on commit 10e3791

Please sign in to comment.