Fix authorization (real)

main
Charlotte Som 2023-02-23 16:55:06 +00:00
parent 57a75ef495
commit 8f8fbef32b
2 changed files with 7 additions and 3 deletions

View File

@ -1 +1,2 @@
/streams.db
/wish-server

View File

@ -133,10 +133,13 @@ func HandleWHIP(res http.ResponseWriter, req *http.Request) {
logHTTPError(res, "Authorization was not set", http.StatusBadRequest)
return
}
streamName, streamPassword, _ := strings.Cut(authorization, ":")
if err := db.QueryRow("SELECT * FROM streams WHERE stream = ? AND password = ?", streamName, streamPassword).Scan(); err != nil {
logHTTPError(res, "Invalid stream authorization", http.StatusUnauthorized)
streamName, _ = strings.CutPrefix(strings.ToLower(streamName), "bearer ")
var qN string
var qP string
if err := db.QueryRow("SELECT * FROM streams WHERE stream = ? AND password = ?", streamName, streamPassword).Scan(&qN, &qP); err != nil {
logHTTPError(res, "Invalid stream authorization for: "+streamName+" - "+err.Error(), http.StatusUnauthorized)
return
}