public async Task <IActionResult> RefreshLogin() { try { var userName = Request.HttpContext.User.Claims.FirstOrDefault(s => s.Type == ClaimTypes.NameIdentifier)?.Value; int siteId = int.Parse(Request.HttpContext.User.Claims.FirstOrDefault(c => c.Type.ToLower() == "site").Value); CredentialModel credential = (this.Service as UsersService).GetCurrentCredential(userName, siteId); var token = await _loginHandler.LoginByContext(this.config["RESTTokenSettings:Audience"], credential.Site); if (token != null) { return(Ok(token)); } return(new ObjectResult(new ErrorModel { Message = $"User {credential.UserName} is not granted access to the API." }) { StatusCode = 403 }); } catch (Exception ex) { ErrorModel error = new ErrorModel(); this.Logger.LogError(ex, "ERROR {0} : {1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), ex.Message); error.Message = ex.ToString(); OkObjectResult result = new OkObjectResult(error); return(result); } }