Improvements
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing
ci/woodpecker/push/woodpecker Pipeline failed
ci/woodpecker/pr/woodpecker Pipeline failed

This commit is contained in:
2022-02-20 21:33:18 +00:00
parent 22ec0433bf
commit 2423bdd3ee
4 changed files with 86 additions and 62 deletions

View File

@ -14,8 +14,18 @@ import (
const (
HeaderName = "Authorization"
Bearer = "Bearer "
ParamName = "token"
)
func MustGetToken(c *gin.Context) budgeteer.Token { //nolint:ireturn
token := c.MustGet(ParamName)
if token, ok := token.(budgeteer.Token); !ok {
return token
}
panic("Token is not a valid Token")
}
func (h *Handler) verifyLogin(c *gin.Context) (budgeteer.Token, *ErrorResponse) { //nolint:ireturn
tokenString := c.GetHeader(HeaderName)
if len(tokenString) <= len(Bearer) {
@ -39,7 +49,7 @@ func (h *Handler) verifyLoginWithForbidden(c *gin.Context) {
return
}
c.Set("token", token)
c.Set(ParamName, token)
c.Next()
}
@ -51,7 +61,7 @@ func (h *Handler) verifyLoginWithRedirect(c *gin.Context) {
return
}
c.Set("token", token)
c.Set(ParamName, token)
c.Next()
}