refactor: split findAuthToken to parseAuthTokenHeader

This commit is contained in:
Derrick Hammer 2024-01-20 08:03:26 -05:00
parent 1d1c552a0a
commit a56fa20b6d
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 17 additions and 7 deletions

View File

@ -17,12 +17,7 @@ const (
)
func findAuthToken(r *http.Request) string {
authHeader := r.Header.Get("Authorization")
if authHeader == "" {
return ""
}
authHeader = strings.TrimPrefix(authHeader, "Bearer ")
authHeader := parseAuthTokenHeader(r.Header)
if authHeader != "" {
return authHeader
@ -37,6 +32,17 @@ func findAuthToken(r *http.Request) string {
return r.FormValue(S5AuthQueryParam)
}
func parseAuthTokenHeader(headers http.Header) string {
authHeader := headers.Get("Authorization")
if authHeader == "" {
return ""
}
authHeader = strings.TrimPrefix(authHeader, "Bearer ")
return authHeader
}
func AuthMiddleware(handler jape.Handler, portal interfaces.Portal) jape.Handler {
return jape.Adapt(func(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@ -108,7 +114,11 @@ type tusJwtResponseWriter struct {
func (w *tusJwtResponseWriter) WriteHeader(statusCode int) {
// Check if this is the specific route and status
if statusCode == http.StatusCreated {
// Modify the response or add query arguments as needed
location := w.Header().Get("Location")
if location != "" {
w.
authHeader := w.Header().Get("Authorization")
}
}
w.ResponseWriter.WriteHeader(statusCode)
}