

Now that users can be admin users and expire after 7 days, the application requires a UI to manage this. Public class UserManagementController : Controller The admin policy is used in the UserManagementController. The policy can then be used for example in a MVC Controller using the Authorize attribute. Options.AddPolicy("dataEventRecordsUser", policyUser => PolicyAdmin.RequireClaim("role", "admin") Options.AddPolicy("admin", policyAdmin => PolicyAdmin.RequireClaim("role", "dataEventRecords.admin") Options.AddPolicy("dataEventRecordsAdmin", policyAdmin => The policies are added in the Startup class in the ConfigureServices method. Now this can be used by defining a policy and validating the policy in a controller. This was added to the token using the admin claim in the IProfileService. The IsAdmin property is used to define whether a logged on user has the admin role. Using the Identity properties validating a token Public async Task IsActiveAsync(IsActiveContext context) If (user.SecuredFilesRole = "securedFiles.admin")Ĭlaims.Add(new Claim(JwtClaimTypes.Role, "securedFiles.admin")) Ĭlaims.Add(new Claim(JwtClaimTypes.Role, "er")) Ĭlaims.Add(new Claim(JwtClaimTypes.Role, "securedFiles")) Ĭlaims.Add(new Claim(JwtClaimTypes.Scope, "securedFiles")) Ĭlaims.Add(new Claim(, user.Email))

If (user.DataEventRecordsRole = "dataEventRecords.admin")Ĭlaims.Add(new Claim(JwtClaimTypes.Role, "dataEventRecords.admin")) Ĭlaims.Add(new Claim(JwtClaimTypes.Role, "er")) Ĭlaims.Add(new Claim(JwtClaimTypes.Role, "dataEventRecords")) Ĭlaims.Add(new Claim(JwtClaimTypes.Scope, "dataEventRecords")) Var principal = await _claimsFactory.CreateAsync(user) Ĭlaims = claims.Where(claim => (claim.Type)).ToList() Ĭlaims.Add(new Claim(JwtClaimTypes.GivenName, user.UserName)) Ĭlaims.Add(new Claim(JwtClaimTypes.Role, "admin")) Ĭlaims.Add(new Claim(JwtClaimTypes.Role, "user")) Var user = await _userManager.FindByIdAsync(sub) Public async Task GetProfileDataAsync(ProfileDataRequestContext context) Public IdentityWithAdditionalClaimsProfileService(UserManager userManager, IUserClaimsPrincipalFactory claimsFactory) Private readonly UserManager _userManager Private readonly IUserClaimsPrincipalFactory _claimsFactory Public class IdentityWithAdditionalClaimsProfileService : IProfileService Namespace IdentityServerWithAspNetIdentitySqlite Using IdentityServerWithAspNetIdentity.Models Each custom ApplicationUser property is added as claims as required. In IdentityServer4, the IProfileService interface is used for this. The Identity properties need to be added to the claims so that the client SPA or whatever client it is can use the properties. Using Identity creating a token in IdentityServer4 If we got this far, something failed, redisplay form _logger.LogInformation(3, "User created a new account with password.") $"Please confirm your account by clicking this link: link") Īwait _signInManager.SignInAsync(user, isPersistent: false) await _emailSender.SendEmailAsync(model.Email, "Confirm your account", Public string DataEventRecordsRole, protocol: ) Public class ApplicationUser : IdentityUser Namespace IdentityServerWithAspNetIdentity.Models This requires the package which is included in the project as a NuGet package. You can add any extra required properties to this class. The package provides the IdentityUser class implemented by the ApplicationUser.
REMOVE IDENTITY API SCOPE APPROVAL UI FULL
REMOVE IDENTITY API SCOPE APPROVAL UI DOWNLOAD

: Updated ASP.NET Core 2.1, Angular 6.0.6, ASP.NET Core Identity 2.1 : Updated ASP.NET Core 3.0, Angular 8.2.6 The SPA application is implemented using Angular, Webpack 4 and Typescript 2. Identity is persisted using EFCore and SQLite. Extra properties are added to the Identity user model to support this. Any admin can activate or deactivate a user using a custom user management API. The application allows users to register and can access the application for 7 days. This article shows how Identity can be extended and used together with IdentityServer4 to implement application specific requirements.
