Skip to content

Commit 84377b3

Browse files
feat: add support for custom security schemes
1 parent ad3ee24 commit 84377b3

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

cmd/server/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func main() {
3232
_, _ = w.Write([]byte("pong"))
3333
}).Methods(http.MethodGet)
3434
r.HandleFunc("/auth", auth.HandleAuth).Methods(http.MethodPost)
35+
r.HandleFunc("/auth/customsecurity/{customSchemeType}", auth.HandleCustomAuth).Methods(http.MethodGet)
3536
r.HandleFunc("/requestbody", requestbody.HandleRequestBody).Methods(http.MethodPost)
3637
r.HandleFunc("/vendorjson", responseHeaders.HandleVendorJsonResponseHeaders).Methods(http.MethodGet)
3738
r.HandleFunc("/pagination/limitoffset/page", pagination.HandleLimitOffsetPage).Methods(http.MethodGet, http.MethodPut)

internal/auth/service.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package auth
22

33
import (
44
"encoding/json"
5+
"fmt"
56
"io"
67
"net/http"
78

@@ -28,3 +29,22 @@ func HandleAuth(w http.ResponseWriter, r *http.Request) {
2829
return
2930
}
3031
}
32+
33+
func HandleCustomAuth(w http.ResponseWriter, r *http.Request) {
34+
switch r.URL.Path {
35+
case "/auth/customsecurity/customSchemeAppId":
36+
appID := r.Header.Get("X-Security-App-Id")
37+
if appID != "testAppID" {
38+
utils.HandleError(w, fmt.Errorf("invalid app id: %w", authError))
39+
return
40+
}
41+
secret := r.Header.Get("X-Security-Secret")
42+
if secret != "testSecret" {
43+
utils.HandleError(w, fmt.Errorf("invalid secret: %w", authError))
44+
return
45+
}
46+
default:
47+
utils.HandleError(w, fmt.Errorf("invalid path"))
48+
return
49+
}
50+
}

0 commit comments

Comments
 (0)