Skip to content

Commit

Permalink
feat: add support for custom security schemes
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanSpeakEasy committed Aug 29, 2024
1 parent ad3ee24 commit 84377b3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func main() {
_, _ = w.Write([]byte("pong"))
}).Methods(http.MethodGet)
r.HandleFunc("/auth", auth.HandleAuth).Methods(http.MethodPost)
r.HandleFunc("/auth/customsecurity/{customSchemeType}", auth.HandleCustomAuth).Methods(http.MethodGet)
r.HandleFunc("/requestbody", requestbody.HandleRequestBody).Methods(http.MethodPost)
r.HandleFunc("/vendorjson", responseHeaders.HandleVendorJsonResponseHeaders).Methods(http.MethodGet)
r.HandleFunc("/pagination/limitoffset/page", pagination.HandleLimitOffsetPage).Methods(http.MethodGet, http.MethodPut)
Expand Down
20 changes: 20 additions & 0 deletions internal/auth/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package auth

import (
"encoding/json"
"fmt"
"io"
"net/http"

Expand All @@ -28,3 +29,22 @@ func HandleAuth(w http.ResponseWriter, r *http.Request) {
return
}
}

func HandleCustomAuth(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/auth/customsecurity/customSchemeAppId":
appID := r.Header.Get("X-Security-App-Id")
if appID != "testAppID" {
utils.HandleError(w, fmt.Errorf("invalid app id: %w", authError))
return
}
secret := r.Header.Get("X-Security-Secret")
if secret != "testSecret" {
utils.HandleError(w, fmt.Errorf("invalid secret: %w", authError))
return
}
default:
utils.HandleError(w, fmt.Errorf("invalid path"))
return
}
}

0 comments on commit 84377b3

Please sign in to comment.