mirror of
https://github.com/mickael-kerjean/filestash
synced 2025-12-06 08:22:24 +01:00
cleanup (sso): cleanup sso related plugins
This commit is contained in:
parent
a2e137bb7a
commit
d56663e805
3 changed files with 59 additions and 33 deletions
|
|
@ -5,6 +5,7 @@ import (
|
|||
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_authenticate_admin"
|
||||
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_authenticate_ldap"
|
||||
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_authenticate_openid"
|
||||
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_authenticate_passthrough"
|
||||
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_authenticate_saml"
|
||||
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_backend_backblaze"
|
||||
_ "github.com/mickael-kerjean/filestash/server/plugin/plg_backend_dav"
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package plg_authenticate_admin
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gorilla/mux"
|
||||
. "github.com/mickael-kerjean/filestash/server/common"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"net/http"
|
||||
|
|
@ -10,7 +9,6 @@ import (
|
|||
|
||||
func init() {
|
||||
Hooks.Register.AuthenticationMiddleware("admin", Admin{})
|
||||
Hooks.Register.HttpEndpoint(LoginPage())
|
||||
}
|
||||
|
||||
type Admin struct{}
|
||||
|
|
@ -34,39 +32,26 @@ func (this Admin) Setup() Form {
|
|||
}
|
||||
|
||||
func (this Admin) EntryPoint(req *http.Request, res http.ResponseWriter) {
|
||||
http.Redirect(
|
||||
res, req,
|
||||
"/admin/plugin/authenticate_admin",
|
||||
http.StatusTemporaryRedirect,
|
||||
)
|
||||
}
|
||||
|
||||
func LoginPage() func(r *mux.Router, _ *App) error {
|
||||
return func(r *mux.Router, _ *App) error {
|
||||
r.HandleFunc("/admin/plugin/authenticate_admin", func(w http.ResponseWriter, r *http.Request) {
|
||||
getFlash := func() string {
|
||||
c, err := r.Cookie("flash")
|
||||
c, err := req.Cookie("flash")
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
http.SetCookie(w, &http.Cookie{
|
||||
http.SetCookie(res, &http.Cookie{
|
||||
Name: "flash",
|
||||
MaxAge: -1,
|
||||
Path: "/",
|
||||
})
|
||||
return fmt.Sprintf("<strong>%s</strong>", c.Value)
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(Page(`
|
||||
res.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
res.WriteHeader(http.StatusOK)
|
||||
res.Write([]byte(Page(`
|
||||
<form action="/api/session/auth/" method="post">
|
||||
<label> ` + getFlash() + `
|
||||
<input type="password" name="password" value="" placeholder="Admin Password" />
|
||||
</label>
|
||||
</form>`)))
|
||||
})
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (this Admin) Callback(formData map[string]string, idpParams map[string]string, res http.ResponseWriter) (map[string]string, error) {
|
||||
|
|
|
|||
40
server/plugin/plg_authenticate_passthrough/index.go
Normal file
40
server/plugin/plg_authenticate_passthrough/index.go
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
package plg_authenticate_passthrough
|
||||
|
||||
import (
|
||||
. "github.com/mickael-kerjean/filestash/server/common"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Hooks.Register.AuthenticationMiddleware("passthrough", Admin{})
|
||||
}
|
||||
|
||||
type Admin struct{}
|
||||
|
||||
func (this Admin) Setup() Form {
|
||||
return Form{
|
||||
Elmnts: []FormElement{
|
||||
{
|
||||
Name: "type",
|
||||
Type: "hidden",
|
||||
Value: "passthrough",
|
||||
},
|
||||
{
|
||||
Name: "hint",
|
||||
Type: "text",
|
||||
ReadOnly: true,
|
||||
Value: "You will be redirected to the selected backend",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (this Admin) EntryPoint(req *http.Request, res http.ResponseWriter) {
|
||||
res.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
res.WriteHeader(http.StatusOK)
|
||||
res.Write([]byte(Page(`<h2 style="display:none;">PASSTHROUGH</h2><script>location.href = "/api/session/auth/"</script>`)))
|
||||
}
|
||||
|
||||
func (this Admin) Callback(formData map[string]string, idpParams map[string]string, res http.ResponseWriter) (map[string]string, error) {
|
||||
return map[string]string{}, nil
|
||||
}
|
||||
Loading…
Reference in a new issue