Skip to content
This repository has been archived by the owner on Apr 13, 2020. It is now read-only.

Quick question to validate custom authentication using Microsoft.AspNetCore.Identity #12

Open
dienomb opened this issue Jan 8, 2019 · 0 comments

Comments

@dienomb
Copy link

dienomb commented Jan 8, 2019

Within my implementation of IAuthenticationProvider. I'm using Microsoft.AspNetCore.Identity to validate user and password.

And from what I know SignInManager and UserManager are registered as scope. But I agree that IAuthenticationProvider should be registered as Singleton as we don't need more than 1 instance of it.

So should I do: AddScoped<IAuthenticationProvider, CustomAuthenticationProvider>()

or what I think is a better solution, I will inject into CustomAuthenticationProvider, IServiceScopeFactory and do:

using (var scope = serviceScopeFactory.CreateScope()) { var signInManager = scope.ServiceProvider.GetService<SignInManager<ApplicationUser>>(); var userManager = scope.ServiceProvider.GetService<UserManager<ApplicationUser>>(); var findUser = await userManager.FindByNameAsync(user); var result = await signInManager.CheckPasswordSignInAsync(findUser, password, false); return result.Succeeded; }

Many thanks

@dienomb dienomb changed the title Quick question to validate the custom authentication using Microsoft.AspNetCore.Identity to do Quick question to validate the custom authentication using Microsoft.AspNetCore.Identity Jan 8, 2019
@dienomb dienomb changed the title Quick question to validate the custom authentication using Microsoft.AspNetCore.Identity Quick question to validate custom authentication using Microsoft.AspNetCore.Identity Jan 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant