Skip to content

Commit

Permalink
Set headers before content
Browse files Browse the repository at this point in the history
  • Loading branch information
NHAS committed Jun 10, 2024
1 parent 019688c commit 6d05569
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 4 additions & 2 deletions internal/webserver/authenticators/pam.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,17 @@ func (t *Pam) AuthorisationAPI(w http.ResponseWriter, r *http.Request) {
challenge, err := user.Authenticate(clientTunnelIp.String(), t.Type(), t.AuthoriseFunc(w, r))

msg, status := resultMessage(err)
if err != nil {
w.Header().Set("WAG-CHALLENGE", challenge)
}

jsonResponse(w, msg, status)

if err != nil {
log.Println(user.Username, clientTunnelIp, "failed to authorise: ", err.Error())
return
}

w.Header().Set("WAG-CHALLENGE", challenge)

log.Println(user.Username, clientTunnelIp, "authorised")

}
Expand Down
5 changes: 3 additions & 2 deletions internal/webserver/authenticators/totp.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ func (t *Totp) AuthorisationAPI(w http.ResponseWriter, r *http.Request) {
}

challenge, err := user.Authenticate(clientTunnelIp.String(), t.Type(), t.AuthoriseFunc(w, r))
if err != nil {
w.Header().Set("WAG-CHALLENGE", challenge)
}

msg, status := resultMessage(err)
jsonResponse(w, msg, status)
Expand All @@ -186,8 +189,6 @@ func (t *Totp) AuthorisationAPI(w http.ResponseWriter, r *http.Request) {
return
}

w.Header().Set("WAG-CHALLENGE", challenge)

log.Println(user.Username, clientTunnelIp, "authorised")

}
Expand Down
7 changes: 5 additions & 2 deletions internal/webserver/authenticators/webauthn.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,18 @@ func (wa *Webauthn) RegistrationAPI(w http.ResponseWriter, r *http.Request) {
})

msg, status := resultMessage(err)

if err != nil {
w.Header().Set("WAG-CHALLENGE", challenge)
}

jsonResponse(w, msg, status) // Send back an error message before we do the server side of handling it

if err != nil {
log.Println(user.Username, clientTunnelIp, "failed to authorise: ", err.Error())
return
}

w.Header().Set("WAG-CHALLENGE", challenge)

log.Println(user.Username, clientTunnelIp, "authorised")

log.Println(user.Username, clientTunnelIp, "registered new webauthn key")
Expand Down

0 comments on commit 6d05569

Please sign in to comment.