asp.net-core-identity

Multiple Identities in ASP.NET Core 2.0

安稳与你 提交于 2019-11-27 01:56:10
问题 I am migrating an ASP.NET Core 1.0 application to ASP.NET Core 2.0. In my startup I am configuring two identities: services.AddIdentity<IdentityUser, IdentityRole>(configureIdentity) .AddDefaultTokenProviders() .AddUserStore<IdentityUserStore<IdentityUser>>() .AddRoleStore<IdentityRoleStore<IdentityRole>>(); services.AddIdentity<Customer, CustomerRole>(configureIdentity) .AddDefaultTokenProviders() .AddErrorDescriber<CustomerIdentityErrorDescriber>() .AddUserStore<CustomerStore<Customer>>()

How to load navigation properties on an IdentityUser with UserManager

。_饼干妹妹 提交于 2019-11-27 01:52:13
问题 I've extended IdentityUser to include a navigation property for the user's address, however when getting the user with UserManager.FindByEmailAsync , the navigation property isn't populated. Does ASP.NET Identity Core have some way to populate navigation properties like Entity Framework's Include() , or do I have to do it manually? I've set up the navigation property like this: public class MyUser : IdentityUser { public int? AddressId { get; set; } [ForeignKey(nameof(AddressId))] public

How to add additional claims to be included in the access_token using ASP.Net Identity with IdentityServer4

久未见 提交于 2019-11-27 01:46:33
问题 How to add additional claims to be included within the token? As soon as the API receives the bearer token, the User.Identity object gets populated with the following claims. [ { "key": "nbf", "value": "1484614344" }, { "key": "exp", "value": "1484615244" }, { "key": "iss", "value": "http://localhost:85" }, { "key": "aud", "value": "http://localhost:85/resources" }, { "key": "aud", "value": "WebAPI" }, { "key": "client_id", "value": "MyClient" }, { "key": "sub", "value": "d74c815a-7ed3-4671

How should I access my ApplicationUser properties from ASP.NET Core Views?

Deadly 提交于 2019-11-27 01:34:45
问题 I'm working on an ASP.Net vNext / MVC6 project. I'm getting to grips with ASP.Net Identity. The ApplicationUser class is apparently where I'm supposed to add any additional user properties, and this works with Entity Framework and my additional properties get stored in the database as expected. However, the problem comes when I want to access the details of the currently logged in user from within my views. Specifically, I have a _loginPartial.cshtml in which I want to retrieve and display

.NET Core 2.1 Identity get all users with their associated roles

空扰寡人 提交于 2019-11-26 22:34:08
I'm trying to pull out all my Identity users and their associated roles for a user management admin page. I thought this would be reasonably easy but apparently not. I've tried following the following solution: https://stackoverflow.com/a/43562544/5392786 but it hasn't worked out so far. Here is what I have so far: ApplicationUser: public class ApplicationUser : IdentityUser { public List<IdentityUserRole<string>> Roles { get; set; } } DBContext public class ApplicationDbContext : IdentityDbContext<ApplicationUser> { public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) :

Change routing in ASP.NET Core Identity UI?

不想你离开。 提交于 2019-11-26 20:53:54
问题 I am using the new Identity UI package available since ASP.NET Core 2.1 was released. Using a newly generated MVC project, here are some page URLs that are available: /Home/About /Home/Contact /Identity/Account/Login /Identity/Account/Register How can I configure routing to remove the /Identity/ part from the URLs? 回答1: It looks like this is not yet possible. Looking at the source code, it's clear that the Area name is hardcoded in IdentityDefaultUIConfigureOptions<TUser>: private const

How to give custom implementation of UpdateAsync method of asp.net identity?

倾然丶 夕夏残阳落幕 提交于 2019-11-26 14:47:07
问题 I am doing custom asp.net identity and not using asp.net inbuilt tables.I have successfully created user with implementing custom CreateAsync Now i want to update user with new encrypted password and so i am not getting how to provide custom implementation of UpdateAsync method . This is my table: User : Id,Name,EmailId,Password,Statistics,Salary Model : public class UserModel : IUser { public string Id { get; set; } public string Name { get; set; } public string EmailId { get; set; } public

How to return 401 instead of 302 in ASP.NET Core?

回眸只為那壹抹淺笑 提交于 2019-11-26 12:41:22
问题 I\'m trying to get ASP.NET Core Identity to return 401 when a user isn\'t logged in. I\'ve added an [Authorize] attribute to my method and instead of returning 401 it returns 302. I\'ve tried a ton of suggestions but nothing seems to work, including services.Configure and app.UseCookieAuthentication setting LoginPath to null or PathString.Empty . 回答1: As of ASP.NET Core 2.x : services.ConfigureApplicationCookie(options => { options.Events.OnRedirectToLogin = context => { context.Response

.NET Core 2.1 Identity get all users with their associated roles

[亡魂溺海] 提交于 2019-11-26 06:39:32
问题 I\'m trying to pull out all my Identity users and their associated roles for a user management admin page. I thought this would be reasonably easy but apparently not. I\'ve tried following the following solution: https://stackoverflow.com/a/43562544/5392786 but it hasn\'t worked out so far. Here is what I have so far: ApplicationUser: public class ApplicationUser : IdentityUser { public List<IdentityUserRole<string>> Roles { get; set; } } DBContext public class ApplicationDbContext :