mirror of
https://github.com/gtsteffaniak/filebrowser.git
synced 2026-11-26 16:39:41 -05:00
Co-authored-by: Markos <xmarkos@gmail.com> Co-authored-by: Zhiyuan Zheng <zhzy0077@hotmail.com> Co-authored-by: Kurami <kurami32_kbm@proton.me>
29 lines
650 B
Go
29 lines
650 B
Go
package auth
|
|
|
|
import (
|
|
"net/http"
|
|
"os"
|
|
|
|
"github.com/gtsteffaniak/filebrowser/backend/common/errors"
|
|
"github.com/gtsteffaniak/filebrowser/backend/database/users"
|
|
)
|
|
|
|
// MethodProxyAuth is used to identify no auth.
|
|
const MethodProxyAuth = "proxy"
|
|
|
|
// ProxyAuth is a proxy implementation of an auther.
|
|
type ProxyAuth struct {
|
|
Header string `json:"header"`
|
|
}
|
|
|
|
// Auth authenticates the user via an HTTP header.
|
|
func (a ProxyAuth) Auth(r *http.Request, usr *users.Storage) (*users.User, error) {
|
|
username := r.Header.Get(a.Header)
|
|
user, err := usr.Get(username)
|
|
if err == errors.ErrNotExist {
|
|
return nil, os.ErrPermission
|
|
}
|
|
|
|
return user, err
|
|
}
|