public async Task <IActionResult> RefreshToken([FromBody] Request request) { var Res = new ServiceResultList <object>(); Res.IsFailed("无效的token"); //将访问令牌解密 并且返回Claims实体 var principal = _CommonEven.GetPrincipalFromAccessToken(request.AccessToken); if (principal is null) { return(Ok(Res)); } var id = principal.Claims.First(c => c.Type == JwtClaimTypes.Name)?.Value; if (string.IsNullOrEmpty(id)) { return(Ok(Res)); } Res.IsFailed("刷新Token 过期"); var refreshToken = _CommonEven.GenerateRefreshToken(); var claims = await _userAppService.RefreshToken(id, request.RefreshToken, refreshToken); if (claims == null) { return(Ok(Res)); } ; return(Ok(new { AccessToken = _CommonEven.GenerateAccessToken(claims as IEnumerable <Claim>), RefreshToken = refreshToken })); }
public IActionResult GetMenuTreeData() { var Res = new ServiceResultList <List <MenuDto> >(); try { Res.IsSuccess(); Res.Data = _menuAppService.GetAllList(); } catch (Exception) { Res.IsFailed(); } return(Ok(Res)); }
public IActionResult GetNavigation() { var headers = HttpContext.Request.Headers["Authorization"].ToString(); var Res = new ServiceResultList <List <MenuDto> >(); Res.IsFailed(); if (string.IsNullOrEmpty(headers)) { return(Ok(Res)); } headers = headers.Replace("Bearer ", ""); var principal = _commonEven.GetPrincipalFromAccessToken(headers); var id = principal.Claims.First(c => c.Type == JwtClaimTypes.Id)?.Value; Res.Data = _menuAppService.GetMenusByUser(Guid.Parse(id)); return(Ok(Res)); }