asp.net-core-identity

ABP 401 response from API instead of redirect

[亡魂溺海] 提交于 2019-12-12 04:19:12
问题 I have the same problem as this: https://forum.aspnetboilerplate.com/viewtopic.php?f=5&t=4865, but I have ABP v2.1 with module-zero-core-template. I'm using Web.Mvc project as my startup project and I want to make API calls. When I perform an unauthorized request to the API, I got a "200 OK" response instead of a "401". Where did I make a mistake? 回答1: ASP.NET Core 1.x ABP v2.x / module-zero-core-template v2.x Modify IdentityRegistrar in .Core project: // Before services.AddAbpIdentity<Tenant

How to prevent multiple & concurrent login in .Net Core 2.x?

流过昼夜 提交于 2019-12-11 15:54:24
问题 I'm trying to limit user login in a web application. Some sources [1] & [2] use same idea by using await _userManager.UpdateSecurityStampAsync (loginUser); This is the complete code of Login action in AccountController: [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task<IActionResult> Login (LoginViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if ( ModelState.IsValid ) { var loginUser = await _userManager.FindByEmailAsync(model.Email); if (

How can I use existing ASP.NET Membership data in a new .Net Core project?

为君一笑 提交于 2019-12-11 14:05:55
问题 I am starting a new .Net Core Web application. And I want to use the authentication tables (aspnet_Users, aspnet_Membership etc) that already exist in our database. But I am not sure how to do it. Upon creating the project, I select "Individual User Accounts" option for authentication. Then I need to choose between "Store user accounts in-app" and "Connect to existing store in the cloud". It seems like none of them suits my need. 来源: https://stackoverflow.com/questions/56275103/how-can-i-use

asp.net core identity does not redirect to correct logon pages

会有一股神秘感。 提交于 2019-12-11 10:59:22
问题 Configured this way it is not working. services .AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options => { options.ExpireTimeSpan = TimeSpan.FromMinutes(5); options.LoginPath = $"/logon"; options.LogoutPath = $"/logoff"; options.AccessDeniedPath = $"/accessdenied"; options.SlidingExpiration = true; }) configured this way it is working : services.ConfigureApplicationCookie(options => { options.Cookie.Name = "Caldr.Auth"; options.LoginPath = $"/logon"; options

How to override HandleUnauthorizedRequest in ASP.NET Core

一笑奈何 提交于 2019-12-11 06:54:40
问题 I'm migrating my project to asp.net core and I'm stuck in migrating my CustomAuthorization attribute for my controllers. Here is my code. public class CustomAuthorization : AuthorizeAttribute { public string Url { get; set; } protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext) { if (!filterContext.HttpContext.User.Identity.IsAuthenticated) { filterContext.Result = new RedirectResult(Url + "?returnUrl=" + filterContext.HttpContext.Request.Url.PathAndQuery); }

Asp.net Core Get User by User Id

会有一股神秘感。 提交于 2019-12-10 12:53:43
问题 Using Asp.net Core Identity and entity framework core, how can I get an asp.net user object by it's UserId property? I know it's possible to get the current logged in user from the HttpContext.User object using: UserManager.GetUserAsync(HttpContext.User) However when an admin is logged in, I want them to be able to access/modify any user's data in order to update user Emails and PhoneNumbers, which by default are part of the asp.net user object. Ideally I'd like to be able to do something

Rights-based authorization with ASP.NET Core 2.1 Identity

六月ゝ 毕业季﹏ 提交于 2019-12-08 00:55:47
问题 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

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

时光毁灭记忆、已成空白 提交于 2019-12-07 15:48:06
问题 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

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

隐身守侯 提交于 2019-12-07 13:40:11
问题 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

ASN.NET Core 2.0 Facebook authentication ExternalLoginSignInAsync Fails (IsNotAllowed)

岁酱吖の 提交于 2019-12-07 13:30:51
问题 I am creating a new application in ASP.NET Core 2.0 with Ddentity. I have enabled the Facebook Authentication according to the docs. The flow that is running right now is the following: When a new user authenticates from facebook the applicatiion asks for an email in order to be used for the application When the user provides the email a user is created in my dbo.AspNetUsers table with the email provided by the user and a new line is created in my dbo.AspNetUserLogins with the reference to