Enable auto login via OIDC

This commit is contained in:
DESKTOP-GENO133\IvanPlex
2024-03-20 14:53:51 -06:00
parent 2e9821402f
commit 3d2117ddaf
3 changed files with 21 additions and 2 deletions

View File

@@ -29,6 +29,18 @@ namespace CarCareTracker.Controllers
}
public IActionResult Index(string redirectURL = "")
{
var remoteAuthConfig = _config.GetOpenIDConfig();
if (remoteAuthConfig.DisableRegularLogin && !string.IsNullOrWhiteSpace(remoteAuthConfig.LogOutURL))
{
var generatedState = Guid.NewGuid().ToString().Substring(0, 8);
remoteAuthConfig.State = generatedState;
if (remoteAuthConfig.ValidateState)
{
Response.Cookies.Append("OIDC_STATE", remoteAuthConfig.State, new CookieOptions { Expires = new DateTimeOffset(DateTime.Now.AddMinutes(5)) });
}
var remoteAuthURL = remoteAuthConfig.RemoteAuthURL;
return Redirect(remoteAuthURL);
}
return View(model: redirectURL);
}
public IActionResult Registration()
@@ -248,7 +260,12 @@ namespace CarCareTracker.Controllers
public IActionResult LogOut()
{
Response.Cookies.Delete("ACCESS_TOKEN");
return Json(true);
var remoteAuthConfig = _config.GetOpenIDConfig();
if (remoteAuthConfig.DisableRegularLogin && !string.IsNullOrWhiteSpace(remoteAuthConfig.LogOutURL))
{
return Json(remoteAuthConfig.LogOutURL);
}
return Json("/Login");
}
}
}

View File

@@ -11,6 +11,8 @@
public string Scope { get; set; }
public string State { get; set; }
public bool ValidateState { get; set; } = false;
public bool DisableRegularLogin { get; set; } = false;
public string LogOutURL { get; set; } = "";
public string RemoteAuthURL { get { return $"{AuthURL}?client_id={ClientId}&response_type=code&redirect_uri={RedirectURL}&scope={Scope}&state={State}"; } }
}
}

View File

@@ -167,7 +167,7 @@ function initCalendar() {
function performLogOut() {
$.post('/Login/LogOut', function (data) {
if (data) {
window.location.href = '/Login';
window.location.href = data;
}
})
}