// Copyright Epic Games, Inc. All Rights Reserved. // Copyright Epic Games, Inc. All Rights Reserved. using HordeServer.Authentication; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System.Threading.Tasks; /// /// Dashboard authorization challenge controller /// [ApiController] [Route("[controller]")] public class DashboardChallengeController : Controller { const string DefaultAuthenticationScheme = OktaDefaults.AuthenticationScheme; /// /// Challenge endpoint for the dashboard, using cookie authentication scheme /// /// Ok on authorized, otherwise will 401 [HttpGet] [Authorize] [Route("/api/v1/dashboard/challenge")] public StatusCodeResult GetChallenge() { return Ok(); } /// /// Login to server, redirecting to the specified URL on success /// /// /// [HttpGet] [Route("/api/v1/dashboard/login")] public IActionResult Login([FromQuery] string? Redirect) { return new ChallengeResult(DefaultAuthenticationScheme, new AuthenticationProperties { RedirectUri = Redirect ?? "/" }); } /// /// Logout of the current account /// /// [HttpGet] [Route("/api/v1/dashboard/logout")] public async Task Logout() { await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); try { await HttpContext.SignOutAsync(DefaultAuthenticationScheme); } #pragma warning disable CA1031 // Do not catch general exception types catch #pragma warning restore CA1031 { } return Ok(); } }