24 lines
701 B
Go
24 lines
701 B
Go
package httpapi
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"data-terminal-cloud/internal/onboarding"
|
||
|
|
"net/http"
|
||
|
|
"strings"
|
||
|
|
)
|
||
|
|
|
||
|
|
func onboardingCustomerAuth(service *onboarding.Service, bearer, next http.Handler) http.Handler {
|
||
|
|
if service == nil {
|
||
|
|
return bearer
|
||
|
|
}
|
||
|
|
cookie := service.CustomerAuth(next)
|
||
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||
|
|
path := r.URL.Path
|
||
|
|
allowed := path == "/api/v1/me" || path == "/api/v1/households" || strings.HasPrefix(path, "/api/v1/households/") || strings.HasPrefix(path, "/api/v1/subjects/") || strings.HasPrefix(path, "/api/v1/devices/")
|
||
|
|
if r.Header.Get("Authorization") == "" && allowed {
|
||
|
|
cookie.ServeHTTP(w, r)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
bearer.ServeHTTP(w, r)
|
||
|
|
})
|
||
|
|
}
|