File tree Expand file tree Collapse file tree 2 files changed +8
-11
lines changed Expand file tree Collapse file tree 2 files changed +8
-11
lines changed Original file line number Diff line number Diff line change @@ -7,12 +7,12 @@ import (
7
7
"context"
8
8
"strings"
9
9
10
- "github.com/grpc-ecosystem/go-grpc-middleware/v2/metadata"
11
10
"google.golang.org/grpc/codes"
11
+ "google.golang.org/grpc/metadata"
12
12
"google.golang.org/grpc/status"
13
13
)
14
14
15
- var (
15
+ const (
16
16
headerAuthorize = "authorization"
17
17
)
18
18
@@ -22,11 +22,11 @@ var (
22
22
// case-insensitive format (see rfc2617, sec 1.2). If no such authorization is found, or the token
23
23
// is of wrong scheme, an error with gRPC status `Unauthenticated` is returned.
24
24
func AuthFromMD (ctx context.Context , expectedScheme string ) (string , error ) {
25
- val := metadata .ExtractIncoming (ctx ). Get ( headerAuthorize )
26
- if val == "" {
25
+ vals := metadata .ValueFromIncomingContext (ctx , headerAuthorize )
26
+ if len ( vals ) == 0 {
27
27
return "" , status .Error (codes .Unauthenticated , "Request unauthenticated with " + expectedScheme )
28
28
}
29
- scheme , token , found := strings .Cut (val , " " )
29
+ scheme , token , found := strings .Cut (vals [ 0 ] , " " )
30
30
if ! found {
31
31
return "" , status .Error (codes .Unauthenticated , "Bad authorization string" )
32
32
}
Original file line number Diff line number Diff line change @@ -53,16 +53,13 @@ func ipInNets(ip netip.Addr, nets []netip.Prefix) bool {
53
53
}
54
54
55
55
func getHeader (ctx context.Context , key string ) string {
56
- md , ok := metadata .FromIncomingContext (ctx )
57
- if ! ok {
58
- return ""
59
- }
56
+ vals := metadata .ValueFromIncomingContext (ctx , key )
60
57
61
- if md [ strings . ToLower ( key )] == nil {
58
+ if len ( vals ) == 0 {
62
59
return ""
63
60
}
64
61
65
- return md [ strings . ToLower ( key )] [0 ]
62
+ return vals [0 ]
66
63
}
67
64
68
65
func ipFromXForwardedFoR (trustedProxies []netip.Prefix , ips []string , idx int ) netip.Addr {
You can’t perform that action at this time.
0 commit comments