public async Task <IActionResult> LoginWithAD() { var loggedInUsername = User.Identity.Name; var user = await authenticationModule.FindUserAsync(loggedInUsername); var authenticationResult = user != null ? authenticationModule.BuildSecurityTokenForUser(user) : AuthenticationResult.Failed(AuthenticationErrorType.UserNotFound); if (authenticationResult.IsAuthenticated) { apiEventLogger.Log(LogLevel.Info, $"User '{loggedInUsername}' successfully logged in"); } else { apiEventLogger.Log(LogLevel.Warning, $"User '{loggedInUsername}' was rejected"); } return(new ContentResult { ContentType = Conventions.JsonContentType, Content = JsonConvert.SerializeObject(authenticationResult), StatusCode = authenticationResult.IsAuthenticated ? (int)HttpStatusCode.OK : (int)HttpStatusCode.Unauthorized }); }