Example #1
0
        public ActionResult RefreshToken([FromBody] AuthResponse token)
        {
            try
            {
                var claim           = _jwtMananager.GetPrincipalFromExpiredToken(token.Token, _configManager[AppConstants.JwtKey]);
                var refreshToken    = _repo.GetRefreshToken(claim.Identity.Name);
                var newJwt          = _jwtMananager.RefreshJwt(claim.Identity.Name, token.RefreshToken, refreshToken);
                var newRefreshToken = _repo.ResetRefreshToken(claim.Identity.Name);

                return(StatusCode(200, new ResponseDto <AuthResponse>
                {
                    status = 200,
                    message = "code refresh successfull",
                    data = new AuthResponse {
                        RefreshToken = newRefreshToken,
                        Token = newJwt
                    }
                }));
            }
            catch (SecurityTokenException)
            {
                return(StatusCode(400, new ResponseDto <string> {
                    status = 400, message = "invalid refresh token"
                }));
            }
            catch
            {
                return(StatusCode(500, new ResponseDto <string> {
                    status = 500, message = "internal server error"
                }));
            }
        }