From fa718e25768f094aa2d93ceec60fd9263d31f849 Mon Sep 17 00:00:00 2001 From: kolaente Date: Tue, 18 Aug 2020 16:55:44 +0200 Subject: [PATCH 1/2] Fix token renew for link shares Signed-off-by: kolaente --- pkg/routes/api/v1/login.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pkg/routes/api/v1/login.go b/pkg/routes/api/v1/login.go index 893328ab3..8a8b49dfe 100644 --- a/pkg/routes/api/v1/login.go +++ b/pkg/routes/api/v1/login.go @@ -88,13 +88,23 @@ func Login(c echo.Context) error { // @Success 200 {object} v1.Token // @Failure 400 {object} models.Message "Only user token are available for renew." // @Router /user/token [post] -func RenewToken(c echo.Context) error { +func RenewToken(c echo.Context) (err error) { jwtinf := c.Get("user").(*jwt.Token) claims := jwtinf.Claims.(jwt.MapClaims) typ := int(claims["type"].(float64)) - if typ != AuthTypeUser { - return echo.ErrBadRequest + if typ == AuthTypeLinkShare { + share := &models.LinkSharing{} + share.ID = int64(claims["id"].(float64)) + err := share.ReadOne() + if err != nil { + return handler.HandleHTTPError(err, c) + } + t, err := NewLinkShareJWTAuthtoken(share) + if err != nil { + return handler.HandleHTTPError(err, c) + } + return c.JSON(http.StatusOK, Token{Token: t}) } user, err := user2.GetUserFromClaims(claims) From a61ab0c5cf2378e6861f39e252888bcb372450a8 Mon Sep 17 00:00:00 2001 From: renovate Date: Tue, 18 Aug 2020 18:07:45 +0000 Subject: [PATCH 2/2] Update github.com/asaskevich/govalidator commit hash to 50839af (#637) Update github.com/asaskevich/govalidator commit hash to 50839af Reviewed-on: https://kolaente.dev/vikunja/api/pulls/637 --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 56e11f948..a434236af 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( code.vikunja.io/web v0.0.0-20200809154828-8767618f181f gitea.com/xorm/xorm-redis-cache v0.2.0 github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 - github.com/asaskevich/govalidator v0.0.0-20200817114649-df4adffc9d8c + github.com/asaskevich/govalidator v0.0.0-20200818142706-50839af6027e github.com/beevik/etree v1.1.0 // indirect github.com/c2h5oh/datasize v0.0.0-20200112174442-28bbd4740fee github.com/client9/misspell v0.3.4 diff --git a/go.sum b/go.sum index 94ce6675f..007d12c45 100644 --- a/go.sum +++ b/go.sum @@ -67,6 +67,8 @@ github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a h1:idn718Q4 github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= github.com/asaskevich/govalidator v0.0.0-20200817114649-df4adffc9d8c h1:W9P/cRMhwMMfrtInPTAn5rcNu/+vb3zKdGeAd+87tFs= github.com/asaskevich/govalidator v0.0.0-20200817114649-df4adffc9d8c/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= +github.com/asaskevich/govalidator v0.0.0-20200818142706-50839af6027e h1:6P0tOQaAiB0G+etsknZvSDjNpdYshZ7wFXTqJpl41h0= +github.com/asaskevich/govalidator v0.0.0-20200818142706-50839af6027e/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= github.com/beevik/etree v1.1.0 h1:T0xke/WvNtMoCqgzPhkX2r4rjY3GDZFi+FjpRZY2Jbs= github.com/beevik/etree v1.1.0/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A=