I have managed to change my .NET Core 6 Razor Pages app to login using Azure Active Directory by following this https://learn.microsoft.com/en-us/azure/active-directory/develop/scenario-web-app-sign-user-sign-in?tabs=aspnetcore
The trouble is that I need to add some custom claims to the login, the details of which are in the database (SQL Server), and I do not know how to go about that other than to store the claims in memory.
Previously, I used the following code in my login page.
public ActionResult OnPostLogin(string returnUrl = null)
{
returnUrl = returnUrl ?? Url.Content("~/");
if (ModelState.IsValid)
{
if (_userRepository.GetUserValid(Input.Username, Input.Password))
{
var claimsIdentity = new ClaimsIdentity(_loginClaimRepository.ClaimList(Input.Username), CookieAuthenticationDefaults.AuthenticationScheme);
var result = HttpContext.SignInAsync(
CookieAuthenticationDefaults.AuthenticationScheme,
new ClaimsPrincipal(claimsIdentity),
new AuthenticationProperties
{
IsPersistent = true,
ExpiresUtc = new DateTimeOffset(DateTime.UtcNow.AddHours(8)),
AllowRefresh = true
});
if (result.IsCompletedSuccessfully)
{
return LocalRedirect(returnUrl);
}
else
{
ModelState.AddModelError(string.Empty, "Invalid login attempt.");
}
}
else
{
ModelState.AddModelError(string.Empty, "Invalid login attempt.");
}
}
return Page();
}
I wonder if there is a standard way to intercept the login process and add some custom claims?




