public override void OnActionExecuting(ActionExecutingContext context) { CustomToken token = _sessionService.GetToken(); if (token == null) { token = _tokenCookieService.Get(); if (!string.IsNullOrEmpty(token.AccessToken) && token.tokenCredentialType == TokenCredentialType.Auth) { _sessionService.SetToken(token.ToCustomToken(token.tokenCredentialType)); } } if (token == null || (string.IsNullOrEmpty(token.AccessToken) && !string.IsNullOrEmpty(token.RefreshToken))) { token = RefreshToken(token.RefreshToken, Settings.ClientSecret); if (token == null || string.IsNullOrEmpty(token.AccessToken)) { //Just Die } else { _tokenCookieService.SetToken(token); _sessionService.SetToken(token); } } var controller = context.Controller as Controller; if (controller != null) { if (token.tokenCredentialType != TokenCredentialType.Auth) { controller.ViewBag.Token = null; } else { controller.ViewBag.Token = token; } } base.OnActionExecuting(context); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { CustomToken token = _sessionService.GetToken(); if (token == null) { token = _tokenCookieService.Get(); if (!string.IsNullOrEmpty(token.AccessToken)) { _sessionService.SetToken(token.ToCustomToken(token.tokenCredentialType)); } } if (token == null || (string.IsNullOrEmpty(token.AccessToken) && !string.IsNullOrEmpty(token.RefreshToken))) { token = RefreshToken(token.RefreshToken, Constants.ClientSecret); } if (token == null || string.IsNullOrEmpty(token.AccessToken)) { token = GetClientToken(); if (token == null || string.IsNullOrEmpty(token.AccessToken)) { //Just Die } else { _tokenCookieService.SetToken(token); _sessionService.SetToken(token); } } filterContext.Controller.ViewBag.Token = token; base.OnActionExecuting(filterContext); }