Skip to content

Commit

Permalink
Merge pull request #1 from Parkour-Vienna/fix-linter-issues
Browse files Browse the repository at this point in the history
chore: fix linter issues
  • Loading branch information
theSuess authored Jun 22, 2021
2 parents 429271b + 6ff770a commit 931d437
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func NewOIDC(path string, disc discourse.SSOConfig, clients map[string]fosite.Cl
if oopts.secret == nil {
log.Warn().Msg("no secret specified in oidc provider. When running multiple instances, make sure this secret is the same on all instances")
var secret = make([]byte, 32)
rand.Read(secret)
_, _ = rand.Read(secret)
oopts.secret = secret
}
if oopts.privateKey == nil {
Expand Down
11 changes: 5 additions & 6 deletions auth/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,20 @@ func (o *OIDCProvider) authEndpoint(rw http.ResponseWriter, req *http.Request) {
delete(o.inflight, sessionId)
}()
http.Redirect(rw, req, url, http.StatusTemporaryRedirect)
return
}

func (o *OIDCProvider) callbackEndpoint(rw http.ResponseWriter, req *http.Request) {
log.Trace().Msg("got a discourse callback")
cookie, err := req.Cookie("oidc_session")
if err != nil {
log.Warn().Err(err).Msg("fetching cookie")
json.NewEncoder(rw).Encode(map[string]string{"error": "invalid session, please try again"})
_ = json.NewEncoder(rw).Encode(map[string]string{"error": "invalid session, please try again"})
return
}

session, ok := o.inflight[uuid.MustParse(cookie.Value)]
if !ok {
json.NewEncoder(rw).Encode(map[string]string{"error": "invalid session, please try again"})
_ = json.NewEncoder(rw).Encode(map[string]string{"error": "invalid session, please try again"})
return
}
delete(o.inflight, uuid.MustParse(cookie.Value))
Expand Down Expand Up @@ -171,7 +170,7 @@ func (o *OIDCProvider) tokenEndpoint(rw http.ResponseWriter, req *http.Request)
return
}

log.Info().Str("username", accessRequest.GetSession().(*openid.DefaultSession).Claims.Subject).Msg("user successfuly authenticated")
log.Info().Str("username", accessRequest.GetSession().(*openid.DefaultSession).Claims.Subject).Msg("user successfully authenticated")

// All done, send the response.
o.oauth2.WriteAccessResponse(rw, accessRequest, response)
Expand All @@ -184,7 +183,7 @@ func (o *OIDCProvider) informationEndpoint(rw http.ResponseWriter, req *http.Req

aroot := o.getAuthRoot(req)

json.NewEncoder(rw).Encode(map[string]interface{}{
_ = json.NewEncoder(rw).Encode(map[string]interface{}{
"issuer": "distrust",
"authorization_endpoint": aroot + "/auth",
"token_endpoint": aroot + "/token",
Expand Down Expand Up @@ -214,7 +213,7 @@ func (o *OIDCProvider) certsEndpoint(rw http.ResponseWriter, req *http.Request)
},
}
rw.Header().Add("Content-Type", "application/json")
json.NewEncoder(rw).Encode(jwks)
_ = json.NewEncoder(rw).Encode(jwks)
}

func (o *OIDCProvider) getAuthRoot(req *http.Request) string {
Expand Down
2 changes: 1 addition & 1 deletion discourse/discourse.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func ValidateResponse(sso, sig, key string, nonce int) (url.Values, error) {
return nil, errors.Wrap(err, "decoding signature")
}

if bytes.Compare(h.Sum(nil), rsig) != 0 {
if !bytes.Equal(h.Sum(nil), rsig) {
return nil, errors.New("wrong signature from discourse")
}

Expand Down
4 changes: 2 additions & 2 deletions genkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ func genkey() {
log.Fatal(err)
}
out := x509.MarshalPKCS1PrivateKey(priv)
pem.Encode(os.Stdout, &pem.Block{
log.Fatal(pem.Encode(os.Stdout, &pem.Block{
Type: "RSA PRIVATE KEY",
Bytes: out,
})
}))
}
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ func main() {

// oauth2 setup
clients := map[string]clientConfig{}
viper.UnmarshalKey("clients", &clients)
err = viper.UnmarshalKey("clients", &clients)
if err != nil {
log.Fatal().Err(err).Msg("failed to parse clients")
}
log.Info().Int("numClients", len(clients)).Msg("clients loaded")
options := []auth.OIDCOption{}
if viper.GetString("oidc.privatekey") != "" {
Expand Down

0 comments on commit 931d437

Please sign in to comment.