Skip to content

Commit e4b083b

Browse files
committed
refactor: modified ParseAuthorizationMetadataAsCookie function for gRPC to receive the metadata directly, instead of a context
1 parent 398b235 commit e4b083b

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.25.1
44

55
require (
66
github.com/ralvarezdev/go-flags v0.3.8
7-
github.com/ralvarezdev/go-grpc v0.5.15
7+
github.com/ralvarezdev/go-grpc v0.6.1
88
github.com/ralvarezdev/go-json v0.2.3
99
github.com/ralvarezdev/go-jwt v0.7.4
1010
github.com/ralvarezdev/go-rate-limiter v0.1.11

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ github.com/ralvarezdev/go-databases v0.8.2 h1:rcQOvhzy5vFpTGDo/O7ar3EuxSxbgu8CFc
2222
github.com/ralvarezdev/go-databases v0.8.2/go.mod h1:f5HsXMi89hSenuZM88IKmfqdTv2gI1JBxizKukz/Y9A=
2323
github.com/ralvarezdev/go-flags v0.3.8 h1:b/doNRr2HsniEpz8NjbH2vxJH5WMeymIx0LAzDIOnOc=
2424
github.com/ralvarezdev/go-flags v0.3.8/go.mod h1:R3yVBYvzwqfOp26LidaiJ/zftVAnPC3pKunVpV/vosE=
25-
github.com/ralvarezdev/go-grpc v0.5.15 h1:ONyaMXDsa2D20oMUyqSUa0+vkPyN/yBjpdpQROkJNCU=
26-
github.com/ralvarezdev/go-grpc v0.5.15/go.mod h1:sWWaPkhXCJq5xQhTvBkfrbrZrdiZx6H8j4sAk/kk0so=
25+
github.com/ralvarezdev/go-grpc v0.6.1 h1:z5MS+tqEWcmMSTJENNLOSByHFH43Tvjq/knBV8yenUM=
26+
github.com/ralvarezdev/go-grpc v0.6.1/go.mod h1:sWWaPkhXCJq5xQhTvBkfrbrZrdiZx6H8j4sAk/kk0so=
2727
github.com/ralvarezdev/go-json v0.2.3 h1:9WOY49UN5mTjylRJ7t+6Ak9CqywQoZQ4AbNaHXF1O5U=
2828
github.com/ralvarezdev/go-json v0.2.3/go.mod h1:85+1W7iK7NNEwgph/X7up69bqY5ug3Psqykjz+Mnq1I=
2929
github.com/ralvarezdev/go-jwt v0.7.4 h1:f9ovJubB/X1xL1cxeW+QNQ8y79Jh/YN9v74SiyYBYXY=

http/grpc/types.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"time"
77

88
gogrpcmd "github.com/ralvarezdev/go-grpc/metadata"
9+
"google.golang.org/grpc/metadata"
910

1011
gonethttp "github.com/ralvarezdev/go-net/http"
1112
gonethttpcookie "github.com/ralvarezdev/go-net/http/cookie"
@@ -70,7 +71,7 @@ func (d DefaultAuthenticationParser) ParseAuthorizationMetadataAsHeader(
7071
w http.ResponseWriter,
7172
) error {
7273
// Get the metadata from the context
73-
md, err := gogrpcmd.GetCtxMetadata(ctx)
74+
md, err := gogrpcmd.GetIncomingCtxMetadata(ctx)
7475
if err != nil {
7576
return gonethttpresponse.NewDebugError(
7677
err,
@@ -118,15 +119,9 @@ func (d DefaultAuthenticationParser) ParseAuthorizationMetadataAsHeader(
118119
//
119120
// - error: error if something goes wrong
120121
func (d DefaultAuthenticationParser) ParseAuthorizationMetadataAsCookie(
121-
ctx context.Context,
122+
md metadata.MD,
122123
w http.ResponseWriter,
123124
) error {
124-
// Get the metadata from the context
125-
md, err := gogrpcmd.GetCtxMetadata(ctx)
126-
if err != nil {
127-
return err
128-
}
129-
130125
// Iterate over the metadata keys to cookies attributes
131126
for metadataKey, cookieAttributes := range d.options.MetadataKeysToCookiesAttributes {
132127
// Get the metadata value
@@ -139,7 +134,10 @@ func (d DefaultAuthenticationParser) ParseAuthorizationMetadataAsCookie(
139134
metadataValue := metadataValueSlice[0]
140135

141136
// Get the expiration time if the function is set
142-
var expiresAt time.Time
137+
var (
138+
expiresAt time.Time
139+
err error
140+
)
143141
if d.options.GetExpiresAtFn != nil {
144142
expiresAt, err = d.options.GetExpiresAtFn(metadataValue)
145143
if err != nil {

0 commit comments

Comments
 (0)