smaller bugfixes for external authentication

This commit is contained in:
Steffen Vogel 2021-02-04 17:49:14 +01:00
parent 47b094b68d
commit c81c1bb04f
2 changed files with 9 additions and 5 deletions

View file

@ -77,13 +77,13 @@ func authenticated(c *gin.Context) {
"user": user.User,
})
} else {
externalAuth, err := configuration.GlobalConfig.Bool("external-auth")
authExternal, err := configuration.GlobalConfig.Bool("auth-external")
if err != nil {
helper.UnauthorizedError(c, "Backend configuration error")
return
}
if externalAuth {
if authExternal {
c.JSON(http.StatusOK, gin.H{
"success": true,
"authenticated": false,
@ -112,18 +112,22 @@ func authenticated(c *gin.Context) {
func authenticate(c *gin.Context) {
var user *User
externalAuth, err := configuration.GlobalConfig.Bool("auth.external")
authExternal, err := configuration.GlobalConfig.Bool("auth.external")
if err != nil {
helper.UnauthorizedError(c, "Backend configuration error")
return
}
if err != nil || !externalAuth {
if err != nil || !authExternal {
user = authenticateStandard(c)
} else {
user = authenticateExternal(c)
}
if user == nil {
return
}
expiresStr, err := configuration.GlobalConfig.String("jwt.expires-after")
if err != nil {
helper.UnauthorizedError(c, "Backend configuration error")

View file

@ -42,7 +42,7 @@ func NewUser(username, password, mail, role string, active bool) (*User, error)
// Check that the username is NOT taken
err := newUser.ByUsername(username)
if err != nil {
if err == nil {
return nil, fmt.Errorf("Username is already taken")
}