2023-06-09 08:06:03 +00:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
2023-06-09 11:38:21 +00:00
|
|
|
"git.lumeweb.com/LumeWeb/portal/service/account"
|
2023-06-09 08:06:03 +00:00
|
|
|
"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
|
|
|
|
}
|
|
|
|
|
2023-06-09 11:38:21 +00:00
|
|
|
acct, err := auth.VerifyLoginToken(token)
|
|
|
|
|
|
|
|
if err != nil {
|
2023-06-09 08:06:03 +00:00
|
|
|
ctx.StopWithError(iris.StatusUnauthorized, auth.ErrInvalidToken)
|
|
|
|
return
|
|
|
|
}
|
2023-06-09 11:38:21 +00:00
|
|
|
|
|
|
|
err = ctx.SetUser(account.NewUser(acct))
|
|
|
|
if err != nil {
|
|
|
|
ctx.StopWithError(iris.StatusInternalServerError, err)
|
|
|
|
}
|
2023-06-09 08:06:03 +00:00
|
|
|
}
|