asp.net-core-identity

UserManager throws exception - Unable to track an entity because primary key property 'Id' is null - after upgrading from .Net Core 2.2 to 3.0

旧城冷巷雨未停 提交于 2019-12-22 14:52:37
问题 I've used the custom implementation of User which is derivated from IdentityUser using Asp.Net Core Identity : public class AppUser : IdentityUser { ... } If I call the method: var identityResult = await UserManager.CreateAsync(user); I get the error: System.InvalidOperationException: Unable to track an entity of type 'AppUser' because primary key property 'Id' is null. It works perfectly with version of Microsoft.AspNetCore.Identity.EntityFrameworkCore - 2.2.0 , but after upgrading to 3.0.0

Using AspNetUserTokens table to store refresh token in ASP.NET Core Web Api

那年仲夏 提交于 2019-12-21 07:38:48
问题 I'm working with ASP.NET Core Web API application. I'm trying to implement Jwt Token Based Authentication on top of ASP.NET Identity( built in with database tables). I have implemented all scenarios like register user, login etc but now trying to implement refresh token flow( where access token get expired, client need to get replaced access token using refresh token) . I have seen people are creating new table (refreshToken) to store refresh token so it can be validated with access token and

Using AspNetUserTokens table to store refresh token in ASP.NET Core Web Api

不打扰是莪最后的温柔 提交于 2019-12-21 07:38:42
问题 I'm working with ASP.NET Core Web API application. I'm trying to implement Jwt Token Based Authentication on top of ASP.NET Identity( built in with database tables). I have implemented all scenarios like register user, login etc but now trying to implement refresh token flow( where access token get expired, client need to get replaced access token using refresh token) . I have seen people are creating new table (refreshToken) to store refresh token so it can be validated with access token and

ASP.NET Core Identity Authorization using Parameter for Team Membership

做~自己de王妃 提交于 2019-12-20 14:20:49
问题 I have an application with tables like this: User (ASP.NET Core Identity) Team UserTeam (many-to-many join table) Users can be members of multiple teams, and can have different Roles within the teams. For example a User may be a TeamAdmin for TeamA but just a normal member of TeamB. Because of this, simple Role checks and Policies defined with static values won't work. I'm looking for a way to authorize Controller Actions for Users based on their Team and their role in the Team, which will

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

馋奶兔 提交于 2019-12-20 03:39:12
问题 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(),

How do I set password options in Aspnet Core 2.1

*爱你&永不变心* 提交于 2019-12-19 19:52:31
问题 I have followed the SO example code and the official documentation but however I change the password length in my Aspnet core 2.1 project nothing changes. I always get the message "The Password must be at least 6 and at max 100 characters long." In public void ConfigureServices(IServiceCollection services) I have tried services.Configure<IdentityOptions>(options => { options.Password.RequiredLength = 1; }); in various places, or adding it to AddDefaultIdentity<> services.AddDefaultIdentity

Authorize only controller allows anonymous access in .net core

我的梦境 提交于 2019-12-17 20:29:35
问题 I have setup identity in a .net core web app, and marked a certain controller as authorize like this.. [Authorize(Roles = "Partner")] public class ClaimsController : Controller { [Authorize(Roles = "Partner")] public IActionResult Index() { var authenticated = User.Identity.IsAuthenticated; //authenticated is false - but this view still loads?! return View(); } } So only users in the partner role should have access.. However someone not logged in at all can load and view the Index view on the

Asp.net core Identity successful login redirecting back to login page

此生再无相见时 提交于 2019-12-17 09:55:59
问题 I have a problem where the asp.net identity framework is redirecting the user back to the login page after they have logged in successfully. This is using the standard Asp.net Core Identity. It is the version 2.1.1. The scaffolding that generates the razor pages. Not sure if that is significant. I know the user is successfully logging in because I get the log message ...Areas.Identity.Pages.Account.LoginModel: Information: User logged in. But then it redirects straight back to the login page.

CustomRequestCultureProvider: context.User.Identity.IsAuthenticated is always false

谁说我不能喝 提交于 2019-12-13 00:37:30
问题 I'm trying to implement a CustomRequestCultureProvider in my localization pipeline, to retrieve the user culture from the database. To identify the user, I need the ClaimsPrincipal , but for some reason, even though the user is authenticated, context.User.Identity.IsAuthenticated is always false. Here's the relevant code (truncated to highlight my issue: authentication is already working; localization code is based on the localization tutorial). public class Startup { public void

ASP.NET Core 2.2 Create IdentityUser

故事扮演 提交于 2019-12-12 13:32:21
问题 Brand new to ASP.Net Core. Having to create an asp.net core 2.2 project with Identity (and have users seeded). I can't find any documentation on how to do this exactly. I was able to find the code to create Identity Roles (compiles anyway, haven't gotten to where I can run it yet: private static async Task CreateUserTypes(ApplicationDbContext authContext, IServiceProvider serviceProvider) { var RoleManager = serviceProvider.GetRequiredService<RoleManager<IdentityRole>>(); string[] roleNames =