asp.net-core-identity

Multiple Identities in ASP.NET Core 2.0

梦想的初衷 提交于 2019-11-28 07:46:24
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>>() .AddRoleStore<CustomerRoleStore<CustomerRole>>(); This worked fine in ASP.NET Core 1.0 but fails with

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

99封情书 提交于 2019-11-28 07:03:16
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-b4e4-faceb0854bf6" }, { "key": "auth_time", "value": "1484611732" }, { "key": "idp", "value": "local" },

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

徘徊边缘 提交于 2019-11-28 06:54:03
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 the user's Gravatar icon, for which I need the email address. The Razor View base class has a User

ASP.NET Core Identity 2.0 SignoutAsync is not logging out user if the user signed in with Google

雨燕双飞 提交于 2019-11-28 04:09:51
问题 I have Asp.net Core Identity version 2.0 Set up and running. I am finding that _signinManager.SignoutAsync is not logging out user once they have signed in with Google. When I go back to my Login Method it just shows the User as logged in with their Claims object still intact. The code is really simple as below [AllowAnonymous] public ActionResult TestGoogle() { var redirectUrl = Url.Action(nameof(ExternalCallback), "Account", new { ReturnUrl = "" }); var properties = _signInManager

Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager` while attempting to activate 'AuthController'

本秂侑毒 提交于 2019-11-27 11:38:01
问题 I'm getting this error in Login Controller. InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager`1[Automobile.Models.Account]' while attempting to activate 'Automobile.Server.Controllers.AuthController'. here is Auth Controller constructor: private SignInManager<Automobile.Models.Account> _signManager; private UserManager<Automobile.Models.Account> _userManager; public AuthController(UserManager<Models.Account> userManager, SignInManager

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

放肆的年华 提交于 2019-11-27 09:37:32
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 string Password { get; set; } public int Salary { get; set; } } My custom class which implements

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

梦想的初衷 提交于 2019-11-27 09:19:54
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. If I use fiddler I can see that there is a cookie on the request so it all looks good from that

Identity UI no longer works after switching to .net core 3 endpoint routing

最后都变了- 提交于 2019-11-27 07:21:14
问题 After having a hard time getting my area to show with endpoint routing i managed to fix it in this self answered thread (albeit not in a very satisfactory way) : Issue after migrating from 2.2 to 3.0, default works but can't access area, is there anyway to debug the endpoint resolution? However Identity UI doesn't show at all for me, i get redirected on challenge to the proper url but the page is blank. I have the identity UI nugget package added and, changing from mvc routing to endpoint

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

拥有回忆 提交于 2019-11-27 03:58:37
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 . As of ASP.NET Core 2.x : services.ConfigureApplicationCookie(options => { options.Events.OnRedirectToLogin = context => { context.Response.StatusCode = 401; return Task.CompletedTask; }; }); If the request header contains X-Requested-With: XMLHttpRequest

ASP.NET Core 2.0 JWT Validation fails with `Authorization failed for user: (null)` error

感情迁移 提交于 2019-11-27 02:07:56
问题 I'm using ASP.NET Core 2.0 application (Web API) as a JWT issuer to generate a token consumable by a mobile app. Unfortunately, this token couldn't be validated by one controller while can be validated by another (using the same validation setting within the same asp.net core 2.0 app). So I have a token which is valid and could be decoded, has all the required claims and timestamps. But one endpoint accepts it, while another gives me 401 error and debug output: Microsoft.AspNetCore