Fix token renew for link shares
Signed-off-by: kolaente <k@knt.li>
This commit is contained in:
parent
c517a87b85
commit
fa718e2576
1 changed files with 13 additions and 3 deletions
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue