asp.net-core-identity

How override ASP.NET Core Identity's password policy

寵の児 提交于 2019-12-03 03:29:12
问题 By default, ASP.NET Core Identity's password policy require at least one special character, one uppercase letter, one number, ... How can I change this restrictions ? There is nothing about that in the documentation (https://docs.asp.net/en/latest/security/authentication/identity.html) I try to override the Identity's User Manager but I don't see which method manages the password policy. public class ApplicationUserManager : UserManager<ApplicationUser> { public ApplicationUserManager(

How override ASP.NET Core Identity's password policy

两盒软妹~` 提交于 2019-12-02 17:00:26
By default, ASP.NET Core Identity's password policy require at least one special character, one uppercase letter, one number, ... How can I change this restrictions ? There is nothing about that in the documentation ( https://docs.asp.net/en/latest/security/authentication/identity.html ) I try to override the Identity's User Manager but I don't see which method manages the password policy. public class ApplicationUserManager : UserManager<ApplicationUser> { public ApplicationUserManager( DbContextOptions<SecurityDbContext> options, IServiceProvider services, IHttpContextAccessor

How to redirect after Azure AD authentication to different controller action in ASP Net Core MVC

家住魔仙堡 提交于 2019-12-02 01:30:19
I have setup my ASP Net Core 2.0 project to authenticate with Azure AD (using the standard Azure AD Identity Authentication template in VS2017 which uses OIDC). Everything is working fine and the app returns to the base url (/) and runs the HomeController.Index action after authentication is successful. However I now want to redirect to a different controller action (AccountController.CheckSignIn) after authentication so that I can check if the user already exists in my local database table and if not (ie it's a new user) create a local user record and then redirect to HomeController.Index

Asp Core 2.1 Jwt + Identity. userManager store does not implement IUserRoleStore

荒凉一梦 提交于 2019-12-02 01:17:35
I am trying to work with Jwt auth and Identity in ASP Net Core 2.1 In my Startup.cs I have: services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.RequireHttpsMetadata = false; options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidIssuer = AuthOptions.ISSUER, ValidateAudience = true, ValidAudience = AuthOptions.AUDIENCE, ValidateLifetime = true, IssuerSigningKey = AuthOptions.GetSymmetricSecurityKey(), ValidateIssuerSigningKey = true, }; }); var builder = services.AddIdentityCore<User>(options => { //

Custom UserManager always return null

穿精又带淫゛_ 提交于 2019-12-01 21:31:34
问题 I am trying to create my own UserManager extending from the original, and when I do a search by email, the user is not found. But if I do a search from the context, if I find the user (see the Get method). To verify that it is really well implemented, I overwrote the FindByEmailAsync method and it is really being called, but I do not know why the user can not find it. Some help? Thank you! public void ConfigureServices(IServiceCollection servicesCollection) { servicesCollection.AddDbContext

Why is ASP.NET Core Identity 2.0 Authorize filter causing me to get a 404?

六眼飞鱼酱① 提交于 2019-12-01 19:53:27
问题 I have a controller that I want to restrict only to a specific role, let's say admin . After setting a user with the admin role, I can validate that he's on that role using the IsInRoleAsync method (which returns true). When setting the attribute with [Authorize(Roles = "admin")] I get a 404 with that very same user . I'm using bearer tokens (I don't think that is relevant but anyway) and here's what I've done to try debugging: Controller w/o [Authorize] : the resource is returned. [OK]

Why is ASP.NET Core Identity 2.0 Authorize filter causing me to get a 404?

旧时模样 提交于 2019-12-01 18:05:27
I have a controller that I want to restrict only to a specific role, let's say admin . After setting a user with the admin role, I can validate that he's on that role using the IsInRoleAsync method (which returns true). When setting the attribute with [Authorize(Roles = "admin")] I get a 404 with that very same user . I'm using bearer tokens (I don't think that is relevant but anyway) and here's what I've done to try debugging: Controller w/o [Authorize] : the resource is returned. [OK] Controller with [Authorize] : the resource is returned only when I use the Authentication: Bearer [access

InvalidOperationException when registering a new user with ASP .NET Core Identity and EntityFrameworkCore

社会主义新天地 提交于 2019-12-01 17:41:13
问题 I'm following the documentation for using Identity and am trying register a new user (executing the register action), but it fails with the following error: InvalidOperationException: Cannot create a DbSet for 'ApplicationUser' because this type is not included in the model for the context. Startup: services.AddIdentity<ApplicationUser, IdentityRole>(options => { //password options options.Password.RequireDigit = false; // ... }) I am using a standard ApplicationUser: public class

How to mock UserManager in .Net Core testing?

a 夏天 提交于 2019-12-01 03:55:13
I have following code. Im trying to running a test case for create user.Following is what i have tried so far. public class CreateUserCommandHandlerTest { private Mock<UserManager<ApplicationUser>> _userManager; private CreateUserCommandHandler _systemUnderTest; public CreateUserCommandHandlerTest() { _userManager = MockUserManager.GetUserManager<ApplicationUser>(); var user = new ApplicationUser() { UserName = "ancon1", Email = "ancon@mail.com", RoleType = RoleTypes.Anonymous }; _userManager .Setup(u => u.CreateAsync(user, "ancon2")).ReturnsAsync(IdentityResult.Success); _systemUnderTest =

How to mock UserManager in .Net Core testing?

感情迁移 提交于 2019-12-01 01:29:39
问题 I have following code. Im trying to running a test case for create user.Following is what i have tried so far. public class CreateUserCommandHandlerTest { private Mock<UserManager<ApplicationUser>> _userManager; private CreateUserCommandHandler _systemUnderTest; public CreateUserCommandHandlerTest() { _userManager = MockUserManager.GetUserManager<ApplicationUser>(); var user = new ApplicationUser() { UserName = "ancon1", Email = "ancon@mail.com", RoleType = RoleTypes.Anonymous }; _userManager