mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-01-24 04:59:36 -06:00
28 lines
699 B
Go
28 lines
699 B
Go
package auth
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/shroff/phylum/server/internal/core"
|
|
)
|
|
|
|
func CreateBasicAuthHandler(a *core.App) func(c *gin.Context) {
|
|
return func(c *gin.Context) {
|
|
authSuccess := false
|
|
if username, pass, ok := c.Request.BasicAuth(); ok {
|
|
if user, err := a.VerifyUserPassword(c.Request.Context(), username, pass); err == nil {
|
|
c.Set(keyUser, user)
|
|
c.Set(keyFileSystem, a.OpenFileSystem(c.Request.Context(), user))
|
|
authSuccess = true
|
|
} else if !errors.Is(err, core.ErrCredentialsInvalid) {
|
|
panic(err)
|
|
}
|
|
}
|
|
if !authSuccess {
|
|
c.Header("WWW-Authenticate", "Basic realm=\"Phylum WebDAV\"")
|
|
panic(errAuthRequired)
|
|
}
|
|
}
|
|
}
|