refactor: add jwt auth middleware to files controller

This commit is contained in:
Derrick Hammer 2023-06-09 04:06:03 -04:00
parent 34be432af7
commit e98e2d0c89
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 27 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import (
"git.lumeweb.com/LumeWeb/portal/cid"
"git.lumeweb.com/LumeWeb/portal/controller/response"
"git.lumeweb.com/LumeWeb/portal/logger"
"git.lumeweb.com/LumeWeb/portal/middleware"
"git.lumeweb.com/LumeWeb/portal/service/files"
"github.com/kataras/iris/v12"
"go.uber.org/zap"
@ -15,6 +16,10 @@ type FilesController struct {
Controller
}
func (f *FilesController) BeginRequest(ctx iris.Context) {
ctx.AddHandler(middleware.VerifyJwt)
}
func (f *FilesController) PostUpload() {
ctx := f.Ctx

22
middleware/jwt.go Normal file
View File

@ -0,0 +1,22 @@
package middleware
import (
"git.lumeweb.com/LumeWeb/portal/service/auth"
"github.com/kataras/iris/v12"
)
func VerifyJwt(ctx iris.Context) {
token := auth.GetRequestAuthCode(ctx)
if len(token) == 0 {
ctx.StopWithError(iris.StatusUnauthorized, auth.ErrInvalidToken)
return
}
if err := auth.VerifyLoginToken(token); err != nil {
ctx.StopWithError(iris.StatusUnauthorized, auth.ErrInvalidToken)
return
}
ctx.Next()
}