token-validator: wg tunnel API interface
This commit is contained in:
parent
38902bee8d
commit
ab40917285
4 changed files with 241 additions and 14 deletions
|
|
@ -3,27 +3,18 @@ package main
|
|||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
||||
func init() {
|
||||
router.GET("/auth", authHandler(apiHandler(validateAuthToken, printStudent)))
|
||||
router.POST("/auth", apiHandler(checkAuth))
|
||||
router.GET("/api/auth", apiAuthHandler(validateAuthToken))
|
||||
router.POST("/api/auth", apiHandler(checkAuth))
|
||||
}
|
||||
|
||||
func printStudent(std *Student, r *http.Request) error {
|
||||
if std != nil {
|
||||
return errors.New(fmt.Sprintf("%s", *std))
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func validateAuthToken(_ httprouter.Params, _ []byte) (interface{}, error) {
|
||||
return false, nil
|
||||
func validateAuthToken(s Student, _ httprouter.Params, _ []byte) (interface{}, error) {
|
||||
return s, nil
|
||||
}
|
||||
|
||||
type loginForm struct {
|
||||
|
|
@ -37,7 +28,7 @@ func checkAuth(_ httprouter.Params, body []byte) (interface{}, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if r, err := http.NewRequest("GET", "https://owncloud.srs.epita.fr/remote.php/webdav/", nil); err != nil {
|
||||
if r, err := http.NewRequest("GET", "https://fic.srs.epita.fr/2020/", nil); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
r.SetBasicAuth(lf.Username, lf.Password)
|
||||
|
|
|
|||
Reference in a new issue