filebrowser/auth/proxy.go
Henrique Dias 7673678b50 🧼: types ---> lib
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
2019-01-04 08:42:42 +00:00

33 lines
706 B
Go

package auth
import (
"net/http"
"github.com/filebrowser/filebrowser/lib"
)
// MethodProxyAuth is used to identify no auth.
const MethodProxyAuth lib.AuthMethod = "proxy"
// ProxyAuth is a proxy implementation of an auther.
type ProxyAuth struct {
Header string
instance *lib.FileBrowser
}
// Auth authenticates the user via an HTTP header.
func (a *ProxyAuth) Auth(r *http.Request) (*lib.User, error) {
username := r.Header.Get(a.Header)
user, err := a.instance.GetUser(username)
if err == lib.ErrNotExist {
return nil, lib.ErrNoPermission
}
return user, err
}
// SetInstance attaches the instance to the auther.
func (a *ProxyAuth) SetInstance(i *lib.FileBrowser) {
a.instance = i
}