Fix token renew for link shares

Signed-off-by: kolaente <k@knt.li>
This commit is contained in:
kolaente 2020-08-18 16:55:44 +02:00
parent c517a87b85
commit fa718e2576
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B

View file

@ -88,13 +88,23 @@ func Login(c echo.Context) error {
// @Success 200 {object} v1.Token // @Success 200 {object} v1.Token
// @Failure 400 {object} models.Message "Only user token are available for renew." // @Failure 400 {object} models.Message "Only user token are available for renew."
// @Router /user/token [post] // @Router /user/token [post]
func RenewToken(c echo.Context) error { func RenewToken(c echo.Context) (err error) {
jwtinf := c.Get("user").(*jwt.Token) jwtinf := c.Get("user").(*jwt.Token)
claims := jwtinf.Claims.(jwt.MapClaims) claims := jwtinf.Claims.(jwt.MapClaims)
typ := int(claims["type"].(float64)) typ := int(claims["type"].(float64))
if typ != AuthTypeUser { if typ == AuthTypeLinkShare {
return echo.ErrBadRequest 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) user, err := user2.GetUserFromClaims(claims)