Skip to content

Commit

Permalink
update auth middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
olegfomenko committed Jan 24, 2024
1 parent a0e1b35 commit 0fa8e1f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/go-chi/chi v4.1.2+incompatible
github.com/go-ozzo/ozzo-validation/v4 v4.2.1
github.com/google/uuid v1.3.0
github.com/rarimo/rarime-auth-svc v0.0.1-rc8
github.com/rarimo/rarime-auth-svc v0.0.1-rc9
github.com/rarimo/xo v1.0.6-0.20231005111658-6ba1ce8f056a
github.com/rubenv/sql-migrate v1.5.2
gitlab.com/distributed_lab/ape v1.7.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ github.com/rarimo/rarime-auth-svc v0.0.1-rc7 h1:+ibnWRdc+fi27JrR3vOPLIXgOdePb29K
github.com/rarimo/rarime-auth-svc v0.0.1-rc7/go.mod h1:48c8FsJixnLeWx8F8MDy79FvhU1r0oTU11mwP3JPngQ=
github.com/rarimo/rarime-auth-svc v0.0.1-rc8 h1:MBx51/ynR8BaRz5HvcbatYe4hnB2ZDVwM7cmGEepg+Y=
github.com/rarimo/rarime-auth-svc v0.0.1-rc8/go.mod h1:48c8FsJixnLeWx8F8MDy79FvhU1r0oTU11mwP3JPngQ=
github.com/rarimo/rarime-auth-svc v0.0.1-rc9 h1:JZfq1q3WaaLwa8ICk8RHEx4+ojl/JBE8N5zJ/uHZUwM=
github.com/rarimo/rarime-auth-svc v0.0.1-rc9/go.mod h1:48c8FsJixnLeWx8F8MDy79FvhU1r0oTU11mwP3JPngQ=
github.com/rarimo/xo v1.0.6-0.20231005111658-6ba1ce8f056a h1:aqz/1mU+rK/xLqf2/NHu+0fUGbVNf+9DYFI70fQo0M0=
github.com/rarimo/xo v1.0.6-0.20231005111658-6ba1ce8f056a/go.mod h1:EYFR6RRqIlnpjcl/SgPgYn8Bmw4+5itRRbPCiSylCds=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
Expand Down
10 changes: 2 additions & 8 deletions internal/services/api/handlers/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,14 @@ import (
func AuthMiddleware(auth *auth.Client, log *logan.Entry) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
claims, status, err := auth.ValidateJWT(r.Header)
claims, err := auth.ValidateJWT(r.Header)
if err != nil {
if status == http.StatusUnauthorized {
ape.Render(w, problems.Unauthorized())
return
}

log.WithError(err).Error("failed to execute auth validate request")
ape.Render(w, problems.InternalError())
return
}

ctx := CtxUserClaim(claims)(r.Context())
next.ServeHTTP(w, r.WithContext(ctx))
next.ServeHTTP(w, r.WithContext(CtxUserClaim(claims)(r.Context())))
})
}
}

0 comments on commit 0fa8e1f

Please sign in to comment.