-
Notifications
You must be signed in to change notification settings - Fork 0
/
oas_security_gen.go
45 lines (40 loc) · 1.04 KB
/
oas_security_gen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Code generated by ogen, DO NOT EDIT.
package api
import (
"context"
"net/http"
"strings"
)
// SecurityHandler is handler for security parameters.
type SecurityHandler interface {
// HandleHeaderAuth handles HeaderAuth security.
HandleHeaderAuth(ctx context.Context, operationName string, t HeaderAuth) (context.Context, error)
}
func findAuthorization(h http.Header, prefix string) (string, bool) {
v, ok := h["Authorization"]
if !ok {
return "", false
}
for _, vv := range v {
scheme, value, ok := strings.Cut(vv, " ")
if !ok || !strings.EqualFold(scheme, prefix) {
continue
}
return value, true
}
return "", false
}
func (s *Server) securityHeaderAuth(ctx context.Context, operationName string, req *http.Request) (context.Context, bool, error) {
var t HeaderAuth
const parameterName = "X-Api-Key"
value := req.Header.Get(parameterName)
if value == "" {
return ctx, false, nil
}
t.APIKey = value
rctx, err := s.sec.HandleHeaderAuth(ctx, operationName, t)
if err != nil {
return nil, false, err
}
return rctx, true, err
}