public ResponseModel <Office365Model> GenerateToken(string email) { var refresh_token = Guid.NewGuid().ToString().Replace("-", ""); var rToken = new RToken { Email = email, RefreshToken = refresh_token, Id = Guid.NewGuid().ToString(), IsStop = 0 }; //store the refresh_token if (RToken.AddToken(rToken)) { return(new ResponseModel <Office365Model> { status = true, message = "OK", Data = GetJwt(email, refresh_token) }); } else { return(new ResponseModel <Office365Model> { status = false, message = "can not add token to database", Data = null }); } }
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 }); } }