Skip to content

Commit

Permalink
Improving logging when authentication fails
Browse files Browse the repository at this point in the history
This change logs the complete response from the frontend when
authentication fails.
  • Loading branch information
lhchavez committed Jul 2, 2020
1 parent 94dc275 commit e2a3a91
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions cmd/omegaup-gitserver/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import (
"encoding/json"
stderrors "errors"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"strings"
"time"

_ "github.com/go-sql-driver/mysql"
"github.com/inconshreveable/log15"
_ "github.com/mattn/go-sqlite3"
Expand All @@ -17,10 +23,6 @@ import (
"github.com/pkg/errors"
"golang.org/x/crypto/argon2"
"golang.org/x/crypto/ed25519"
"net/http"
"net/url"
"strings"
"time"
)

var (
Expand Down Expand Up @@ -228,6 +230,23 @@ func (a *omegaupAuthorization) getAuthorizationFromFrontend(
}
defer response.Body.Close()

if response.StatusCode != http.StatusOK {
responseBody, err := ioutil.ReadAll(response.Body)
if err != nil {
return nil, errors.Wrap(
errors.Wrap(
err,
"failed to read response from server",
),
"failed to request permissions from the frontend",
)
}
return nil, errors.Errorf(
"failed to request permissions from the frontend: %q",
responseBody,
)
}

var msg authorizationProblemResponse
decoder := json.NewDecoder(response.Body)
if err := decoder.Decode(&msg); err != nil {
Expand Down

0 comments on commit e2a3a91

Please sign in to comment.