reload auth token
License: MIT Signed-off-by: Henrique Dias <hacdias@gmail.com>
This commit is contained in:
parent
2c06e95577
commit
709c87799c
2
frontend
2
frontend
@ -1 +1 @@
|
||||
Subproject commit 14a936a2932d342b9dbc162de1cde9a38036b3d2
|
||||
Subproject commit eb33671e572daddf57a3bbdf47e3f09865e27837
|
||||
16
http/auth.go
16
http/auth.go
@ -129,10 +129,24 @@ func (e *Env) auth(next http.HandlerFunc) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
if !tk.VerifyExpiresAt(time.Now().Add(time.Hour).Unix(), true) {
|
||||
// TODO: chek if user info was modified
|
||||
w.Header().Add("X-Renew-Token", "true")
|
||||
}
|
||||
|
||||
nextWithUser(w, r, tk.User.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Env) renew(w http.ResponseWriter, r *http.Request) {
|
||||
user, ok := e.getUser(w, r)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
e.printToken(w, r, user)
|
||||
}
|
||||
|
||||
func (e *Env) printToken(w http.ResponseWriter, r *http.Request, user *types.User) {
|
||||
claims := &authToken{
|
||||
User: userInfo{
|
||||
@ -144,7 +158,7 @@ func (e *Env) printToken(w http.ResponseWriter, r *http.Request, user *types.Use
|
||||
Commands: user.Commands,
|
||||
},
|
||||
StandardClaims: jwt.StandardClaims{
|
||||
ExpiresAt: time.Now().Add(time.Hour * 24).Unix(),
|
||||
ExpiresAt: time.Now().Add(time.Hour * 2).Unix(),
|
||||
Issuer: "File Browser",
|
||||
},
|
||||
}
|
||||
|
||||
@ -45,6 +45,7 @@ func Handler(e *Env) http.Handler {
|
||||
api := r.PathPrefix("/api").Subrouter()
|
||||
api.HandleFunc("/login", e.loginHandler)
|
||||
api.HandleFunc("/signup", e.signupHandler)
|
||||
api.HandleFunc("/renew", e.auth(e.renew))
|
||||
|
||||
users := api.PathPrefix("/users").Subrouter()
|
||||
users.HandleFunc("", e.auth(e.usersGetHandler)).Methods("GET")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user