Exemplo n.º 1
0
        public IActionResult RefreshToken([FromBody] JWModel parameters)
        {
            if (parameters == null)
            {
                return(Json(new ResponseModel <Office365Model>
                {
                    status = false,
                    message = "null of parameters",
                    Data = null
                }));
            }
            // if (parameters.GrantType == "refresh_token")
            // {
            var result = JwtAuthentication.DoRefreshToken(parameters);

            if (result.status)
            {
                return(Ok(new { Token = result.Data.Token, RefreshToken = result.Data.RefreshToken, ExpiresIn = result.Data.ExpiresIn, Email = result.Data.Email }));
            }
            else
            {
                return(Json(result));
            }
            //}
            //else
            //{
            //    return Json(new ResponseModel<Office365Model>
            //    {
            //        status = false,
            //        message = "bad request",
            //        Data = null
            //    });
            //}
        }
Exemplo n.º 2
0
        public ResponseModel <Office365Model> DoRefreshToken(JWModel parameters)
        {
            var token = RToken.GetToken(parameters.RefreshToken, parameters.Email);

            if (token == null)
            {
                return(new ResponseModel <Office365Model>
                {
                    status = false,
                    message = "can not refresh token",
                    Data = null
                });
            }

            if (token.IsStop == 1)
            {
                return(new ResponseModel <Office365Model>
                {
                    status = false,
                    message = "refresh token has expired",
                    Data = null
                });
            }

            var refresh_token = Guid.NewGuid().ToString().Replace("-", "");

            token.IsStop = 1;
            //expire the old refresh_token and add a new refresh_token
            var updateFlag = RToken.ExpireToken(token);

            var addFlag = RToken.AddToken(new RToken
            {
                Email        = parameters.Email,
                RefreshToken = refresh_token,
                Id           = Guid.NewGuid().ToString(),
                IsStop       = 0
            });

            if (updateFlag && addFlag)
            {
                return(new ResponseModel <Office365Model>
                {
                    status = true,
                    message = "OK",
                    Data = GetJwt(parameters.Email, refresh_token)
                });
            }
            else
            {
                return(new ResponseModel <Office365Model>
                {
                    status = false,
                    message = "can not expire token or a new token",
                    Data = null
                });
            }
        }