asp.net-core-identity

IdentityServer4: Add Custom default Claim to Client Principal for Client_Credential Granttype

女生的网名这么多〃 提交于 2019-12-01 00:51:26
问题 I am using IdentityServer4 and I am trying to add a custom default claim to my CLIENT when the token is created. This is possible if i use the implicit flow and IProfileService like shown below. public class MyProfileService : IProfileService { public MyProfileService() { } public Task GetProfileDataAsync(ProfileDataRequestContext context) { var claims = new List<Claim> { new Claim("DemoClaimType", "DemoClaimValue") }; context.IssuedClaims = claims; return Task.FromResult(0); } public Task

ASP.NET Core Identity & Cookies

感情迁移 提交于 2019-12-01 00:47:44
I have an ASP.NET Core site using AspNetCore.Identity.EntityFrameworkCore 1.1.1 and cookies to authorize/authenticate my users. No matter what I choose as my setting in the code below, the cookie expires after about 20 minutes and I can't figure why. The website will then no longer work unless you close the browser and clear the history/cookies. Any ideas? services.AddIdentity<ApplicationUser, IdentityRole>(config => { // Require a confirmed email in order to log in config.SignIn.RequireConfirmedEmail = true; }) .AddEntityFrameworkStores<ApplicationDbContext>() .AddDefaultTokenProviders(); app

.net core identity 2.1 role authorize not working

我的梦境 提交于 2019-11-30 19:25:00
I've implemented role based auth several times pre 2.1. Followed the steps to scaffold the new 2.1 identities. I extended the IdentityUser model to add additional fields, login works fine, new fields are present. startup.cs configure services contains services.AddDefaultIdentity<AppUser>() .AddRoles<IdentityRole>() .AddEntityFrameworkStores<ApplicationDbContext>(); I seeded the roles IdentityRole role = new IdentityRole(); role.Name = "Administrator"; IdentityResult roleResult = roleManager. CreateAsync(role).Result; Then created a user and added to the role AppUser user = new AppUser(); user

Disable Not Authorized Redirect to Account/Login in ASP.NET Core

别来无恙 提交于 2019-11-29 14:20:56
I have a set of WebAPI services in a shared library. These are used in an ASP.NET Core MVC Web Site and dedicated server only hosting the WebAPI Services without the MVC component. Everything works as expected on the MVC Web Site with Unauthorized Requests, I get the 304 redirect to the login page (Account/Login). However when I make an unauthorized request to the WebAPI services, I receive the same 304 redirect to /Account/Login in this case I would like to return the Http 401 Unauthorized result code. I would prefer to not handle this in a custom AuthorizeAttribute but would rather handle at

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

北城以北 提交于 2019-11-29 10:53:06
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.ConfigureExternalAuthenticationProperties("Google", redirectUrl); return Challenge(properties, "Google"); }

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

眉间皱痕 提交于 2019-11-29 00:57:11
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.Authorization.DefaultAuthorizationService:Information: Authorization failed for user: (null). [40m[32minfo[39m

How to sign out other user in ASP.NET Core Identity

夙愿已清 提交于 2019-11-28 21:14:20
问题 How can i sign out another user (not the currently logged one) in ASP.NET Core Identity. I know there is a SignOutAsync() method in SignInManager , but there seems to be no override accepting user as argument. I'm looking for something like: signInManager.SignOutAsync(user); 回答1: First update the security stamp of that user: await userManager.UpdateSecurityStampAsync(user) Then that user won't be noticed the changes until the arrival of the SecurityStampValidationInterval . So set it to Zero

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

走远了吗. 提交于 2019-11-28 19:05:47
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<Automobile.Models.Account> signManager) { this._userManager = userManager; this._signManager = signManager

How to load navigation properties on an IdentityUser with UserManager

左心房为你撑大大i 提交于 2019-11-28 08:12:32
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 virtual Address Address { get; set; } } public class Address { [Key] public int Id { get; set; } public

Disable Not Authorized Redirect to Account/Login in ASP.NET Core

旧街凉风 提交于 2019-11-28 07:51:07
问题 I have a set of WebAPI services in a shared library. These are used in an ASP.NET Core MVC Web Site and dedicated server only hosting the WebAPI Services without the MVC component. Everything works as expected on the MVC Web Site with Unauthorized Requests, I get the 304 redirect to the login page (Account/Login). However when I make an unauthorized request to the WebAPI services, I receive the same 304 redirect to /Account/Login in this case I would like to return the Http 401 Unauthorized