Search code examples
authenticationaspnetboilerplate

How to use External Authentication for ASP.NET Boilerplate?


I want to use External Authentication for my project. Can anyone tell me how to use External Authentication for ASP.NET Boilerplate?


Solution

  • From the documentation on External Authentication:

    UserManager defines an extension point named 'external authentication source'. We can create a class derived from IExternalAuthenticationSource and register to the configuration. There is DefaultExternalAuthenticationSource class to simplify implementation of IExternalAuthenticationSource. Let's see an example:

    public class MyExternalAuthSource : DefaultExternalAuthenticationSource<Tenant, User>
    {
        public override string Name => "MyCustomSource";
    
        public override Task<bool> TryAuthenticateAsync(string userNameOrEmailAddress, string plainPassword, Tenant tenant)
        {
            // Authenticate user and return true or false
        }
    }