asp.net-core-identity

How to use ASP.NET Core Identity without roles?

半世苍凉 提交于 2019-12-07 11:07:28
问题 Is it feasible to implement identity in asp.net core 2 without roles implementation? I have tried to implement the following: services.AddIdentityCore<TUser>(); but that does not seem to work as well. 回答1: I got it! I have upload a repo in github: https://github.com/tolemac/IdentityWithoutRoles You have to create your custom ApplicationDbContext with corrects DbSets : public class ApplicationDbContext : DbContext { public ApplicationDbContext(DbContextOptions options) : base(options) { } ///

AspNetCore 2.0 Identity - Issues with injecting RoleManager

核能气质少年 提交于 2019-12-07 06:24:44
问题 I need to create CRUD operations for ROLES. I'm getting the following error: "Unable to resolve service for type 'Microsoft.AspNetCore.Identity.RoleManager`" So, how can i inject roleManager? I'm using asp net core 2.0 + identity 2.2.1 Class ApplicationUser public class ApplicationUser : IdentityUser { [Key] public override string Id { get; set; } public bool Type { get; set; } } Now in Startup.cs services.AddIdentity<ApplicationUser, IdentityRole<int>>() .AddUserStore<UserStore

.Net Core Identity 2 Provider login Cancel leads to unhandled exception

╄→гoц情女王★ 提交于 2019-12-07 04:06:44
问题 I've added LinkedIn as a provider. I have implemented the login and register with LinkedIn without any issue. In the use case where the user CANCELS from within the provider Pages (either linkedIn login or cancels the authorization of the app) the identity middleware seems to throw an unhandled exception: An unhandled exception occurred while processing the request. Exception: user_cancelled_login;Description=The user cancelled LinkedIn login Unknown location Exception: An error was

Temporary Session Based Claims in ASP.NET Core Identity

北慕城南 提交于 2019-12-07 00:26:44
问题 Adding claims in ASP.NET Core Identity is straight forward enough, but I'm having trouble finding how to add a temporary session based claim. My use case is such that a logged in user with their own custom claims needs to periodically have a new claim added, but only for the current session, and not persisted to the database. After they close their browser or sign out, the temporary claim should go away. This is to satisfy a mechanism that temporarily changes the organization to which a user

NormalizedUserName VS Username in DotNet Core

喜欢而已 提交于 2019-12-06 17:12:45
问题 I'm trying to create a custom implementation of IUserLoginStore for MongoDB and I noticed when using UserManager<ApplicationUser> with the method var userResult = await _userManager.CreateAsync(user); it goes through the implementation of GetUserNameAsync FindByNameAsync SetNormalizedUserNameAsync GetUserIdAsync I would like to clarify two questions: what's the purpose of having a NormalizedUsername and a UserName? the only difference that I could notice id that the normalizedUserName is in

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-06 14:33:47
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 - it doesn't work. I get same error during testing of the creation of user as well, there I use

Rights-based authorization with ASP.NET Core 2.1 Identity

回眸只為那壹抹淺笑 提交于 2019-12-06 05:35:17
In the past, with ASP.NET MVC on .NET Framework, I always implemented a Rights-based authorization layer on top of the Roles-based authorization that was built-in. By "Rights-based", what I mean is that a list of enumerated Rights are assigned to each Role, and at runtime, each call checked for a Right, not a Role. e.g. say the Post method on the OrdersController required the AddOrEditOrder Right. That would look like [MyAuthorize(MyRights.AddOrEditOrder)] on the Post action. Then somewhere else you'd be able to configure that only the Manager and CustomerRep Roles had that Right. I always

ASP.NET Core Custom Policy Based Authorization - unclear

南笙酒味 提交于 2019-12-06 03:57:48
问题 OK, Custom Policy Based Authorization in ASP.NET Core. I kinda of understood the idea of this new identity framework, but still not 100% clear what you can achieve with this. Assuming we have an Action in HomeController called List. This action will query and display a list of products from the database. The users that must access this list must be part of the Marketing division. Therefore in our policy we check if user has a claim called Division and the value of that is Marketing. If yes

ASP Net Core - Mixing External Identity Provider with Individual User Accounts for Audit Tracking

China☆狼群 提交于 2019-12-06 01:54:32
I have created a default ASP Net Core MVC web app with Individual User Accounts. I added a custom UserID INT field to the AspNetUsers table and linked this as a foreign key to all my other custom tables so I can track what users inserted/updated records in my database. I did this as I prefer using INT fields for primary keys. In this scenario everything is working fine. I am now thinking of using an external identity provider such as Azure Active Directory however I cannot work out how I would link a user in Azure AD (or any other identity provider) to my local database tables to maintain the

Error in Service IUserStore being created in Identity Asp.net core 3 MVC

℡╲_俬逩灬. 提交于 2019-12-05 20:40:28
Update See Update below. I have asked a previous stackoverflow question very recently, but I face an issue after implementing the suggested solutions from the following 2 places Identity model customization in ASP.NET Core and Custom storage providers for ASP.NET Core Identity . I am just not able to get the solution to work. I have implemented the extension of IdentityUser as recommended and the extension of IdentityRole . I have implemented IUserPasswordStore and IUserRoleStore and IUserStore for UserStore and I have implemented IRoleStore for RoleStore . I have also implemented the new