Skip to content

Commit 98fb888

Browse files
committed
refactor(middleware): update context usage in StoreWebToken
• Replace context package with pmcontext to avoid conflict with stdlib
1 parent e0f78c2 commit 98fb888

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

middleware/token.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,28 @@ import (
66

77
"github.com/go-http-utils/headers"
88
"github.com/go-jose/go-jose/v4"
9-
"github.com/platform-mesh/golang-commons/context"
9+
10+
pmcontext "github.com/platform-mesh/golang-commons/context"
1011
)
1112

1213
const tokenAuthPrefix = "BEARER"
1314

1415
var SignatureAlgorithms = []jose.SignatureAlgorithm{jose.RS256}
1516

1617
// StoreWebToken returns middleware that extracts a JWT from the HTTP `Authorization` header
17-
// and stores it in the request context for downstream handlers.
18+
// and stores it in the request pmcontext for downstream handlers.
1819
//
1920
// The middleware looks for an Authorization header of the form `Bearer <token>` (scheme match is
20-
// case-insensitive). When present, the token is added to the context via
21+
// case-insensitive). When present, the token is added to the pmcontext via
2122
// context.AddWebTokenToContext using the package's SignatureAlgorithms. If the header is absent,
22-
// malformed, or not a Bearer token, the request context is left unchanged.
23+
// malformed, or not a Bearer token, the request pmcontext is left unchanged.
2324
func StoreWebToken() func(http.Handler) http.Handler {
2425
return func(next http.Handler) http.Handler {
2526
return http.HandlerFunc(func(responseWriter http.ResponseWriter, request *http.Request) {
2627
ctx := request.Context()
2728
auth := strings.Split(request.Header.Get(headers.Authorization), " ")
2829
if len(auth) > 1 && strings.ToUpper(auth[0]) == tokenAuthPrefix {
29-
ctx = context.AddWebTokenToContext(ctx, auth[1], SignatureAlgorithms)
30+
ctx = pmcontext.AddWebTokenToContext(ctx, auth[1], SignatureAlgorithms)
3031
}
3132

3233
next.ServeHTTP(responseWriter, request.WithContext(ctx))

0 commit comments

Comments
 (0)