Identity provider

Relatude Core has a new custom Identity provider that you can use in your .Net 6 projects if you want.

Configuration

In Program.cs, you can add one line to activate the Identity provider. Add it after the call to AddWAFAuthenticationAndAuthorization

builder.AddWAFAuthenticationAndAuthorization(configWAF);
builder.AddWAFIdentity(configWAF);

Using Identity provider for login

Login with Identity provider is very simple, and not tied directly to Relatude except for one thing. You have to specify the User  class to the SignInManager. Use WAFIdentityUser. If you want to use the Role functionality, use WAFIdentityRole.

The Identity provider authenticates against users stored in Relatude. 

This is an example of how to login and logout using the custom Identity provider:

public class LoginController : Controller {
        
        private readonly SignInManager<WAFIdentityUser> _signInManager;

        public LoginController(SignInManager<WAFIdentityUser> signInManager) {
            _signInManager = signInManager;            
        }
        [HttpGet]
        public IActionResult Index() {
            return View();
        }

        [HttpPost]
        public async Task<IActionResult> Index(LoginModel model) {
            if (ModelState.IsValid) {
                var result = await _signInManager.PasswordSignInAsync(model.UserName, model.Password, true, false);
                if (result.Succeeded) {
                    return Redirect("/");                
                } else
                    ModelState.AddModelError("LoginError", "Invalid username or password");
            }    
            return View(model);
        }

        public async Task<IActionResult> Logout() {
            await _signInManager.SignOutAsync();
            return Redirect("/");
        }         
    }