Created
March 10, 2021 01:49
-
-
Save xximjasonxx/c41e946be11bf039402538e345b404b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ProcessApiResultFilter : IActionFilter | |
{ | |
private readonly JwtTokenService _jwtTokenService; | |
public ProcessApiResultFilter(JwtTokenService jwtTokenService) | |
{ | |
_jwtTokenService = jwtTokenService; | |
} | |
public void OnActionExecuting(ActionExecutingContext context) | |
{ | |
// no action | |
} | |
public void OnActionExecuted(ActionExecutedContext context) | |
{ | |
if ((context.Result as OkObjectResult)?.Value is ApiResult result) | |
{ | |
if (result.TokensChanged) | |
{ | |
var newTokenString = _jwtTokenService.CreateJwtTokenString( | |
result.NewAccessToken, result.NewRefreshToken).Result; | |
context.HttpContext.Response.Headers.Add("X-NewToken", newTokenString); | |
} | |
context.Result = new ObjectResult(result.Result); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment