Clean web authentication

This commit is contained in:
Emile Vauge 2016-09-19 17:00:12 +02:00
parent be09ff8e43
commit 1b6af2045e
No known key found for this signature in database
GPG key ID: D808B4C167352E59

21
web.go
View file

@ -107,14 +107,15 @@ func (provider *WebProvider) Provide(configurationChan chan<- types.ConfigMessag
} }
go func() { go func() {
var err error
var negroni = negroni.New()
if provider.Auth != nil { if provider.Auth != nil {
authMiddleware, err := middlewares.NewAuthenticator(provider.Auth) authMiddleware, err := middlewares.NewAuthenticator(provider.Auth)
if err != nil { if err != nil {
log.Fatal("Error creating Auth: ", err) log.Fatal("Error creating Auth: ", err)
} }
var negroni = negroni.New()
negroni.Use(authMiddleware) negroni.Use(authMiddleware)
}
negroni.UseHandler(systemRouter) negroni.UseHandler(systemRouter)
if len(provider.CertFile) > 0 && len(provider.KeyFile) > 0 { if len(provider.CertFile) > 0 && len(provider.KeyFile) > 0 {
@ -124,21 +125,7 @@ func (provider *WebProvider) Provide(configurationChan chan<- types.ConfigMessag
} }
if err != nil { if err != nil {
log.Fatal("Error creating server with Auth: ", err) log.Fatal("Error creating server: ", err)
}
} else {
var err error
if len(provider.CertFile) > 0 && len(provider.KeyFile) > 0 {
err = http.ListenAndServeTLS(provider.Address, provider.CertFile, provider.KeyFile, systemRouter)
} else {
err = http.ListenAndServe(provider.Address, systemRouter)
}
if err != nil {
log.Fatal("Error creating server without Auth: ", err)
}
} }
}() }()
return nil return nil