Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/windows auth #559

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public interface IUserDto : IBaseUserDto
bool TwoFactorEnabled { get; set; }
int AccessFailedCount { get; set; }
DateTimeOffset? LockoutEnd { get; set; }
string PhotoUrl { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@ public class UserDto<TKey> : BaseUserDto<TKey>, IUserDto
public int AccessFailedCount { get; set; }

public DateTimeOffset? LockoutEnd { get; set; }

public string PhotoUrl { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public virtual async Task<TUsersDto> GetRoleUsersAsync(string roleId, string sea
await AuditEventLogger.LogEventAsync(new RoleUsersRequestedEvent<TUsersDto>(usersDto));

return usersDto;
}
}

public virtual async Task<TUsersDto> GetClaimUsersAsync(string claimType, string claimValue, int page = 1, int pageSize = 10)
{
var pagedList = await IdentityRepository.GetClaimUsersAsync(claimType, claimValue, page, pageSize);
Expand Down Expand Up @@ -426,19 +426,19 @@ public virtual async Task<TRoleClaimsDto> GetRoleClaimsAsync(string roleId, int
await AuditEventLogger.LogEventAsync(new RoleClaimsRequestedEvent<TRoleClaimsDto>(roleClaimDtos));

return roleClaimDtos;
}
public virtual async Task<TRoleClaimsDto> GetUserRoleClaimsAsync(string userId, string claimSearchText, int page = 1, int pageSize = 10)
{
var userExists = await IdentityRepository.ExistsUserAsync(userId);
if (!userExists) throw new UserFriendlyErrorPageException(string.Format(IdentityServiceResources.UserDoesNotExist().Description, userId), IdentityServiceResources.UserDoesNotExist().Description);
var identityRoleClaims = await IdentityRepository.GetUserRoleClaimsAsync(userId, claimSearchText, page, pageSize);
var roleClaimDtos = Mapper.Map<TRoleClaimsDto>(identityRoleClaims);
return roleClaimDtos;
}
}

public virtual async Task<TRoleClaimsDto> GetUserRoleClaimsAsync(string userId, string claimSearchText, int page = 1, int pageSize = 10)
{
var userExists = await IdentityRepository.ExistsUserAsync(userId);
if (!userExists) throw new UserFriendlyErrorPageException(string.Format(IdentityServiceResources.UserDoesNotExist().Description, userId), IdentityServiceResources.UserDoesNotExist().Description);

var identityRoleClaims = await IdentityRepository.GetUserRoleClaimsAsync(userId, claimSearchText, page, pageSize);
var roleClaimDtos = Mapper.Map<TRoleClaimsDto>(identityRoleClaims);

return roleClaimDtos;
}

public virtual async Task<TRoleClaimsDto> GetRoleClaimAsync(string roleId, int claimId)
{
var roleExists = await IdentityRepository.ExistsRoleAsync(roleId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ public virtual async Task<PagedList<TUser>> GetRoleUsersAsync(string roleId, str
pagedList.PageSize = pageSize;

return pagedList;
}
}

public virtual async Task<PagedList<TUser>> GetClaimUsersAsync(string claimType, string claimValue, int page = 1, int pageSize = 10)
{
var pagedList = new PagedList<TUser>();
Expand Down Expand Up @@ -262,26 +262,26 @@ public virtual async Task<PagedList<TRoleClaim>> GetRoleClaimsAsync(string roleI
pagedList.PageSize = pageSize;

return pagedList;
}
public virtual async Task<PagedList<TRoleClaim>> GetUserRoleClaimsAsync(string userId, string claimSearchText, int page = 1, int pageSize = 10)
{
var id = ConvertKeyFromString(userId);
Expression<Func<TRoleClaim, bool>> searchCondition = x => x.ClaimType.Contains(claimSearchText);
var claimsQ = DbContext.Set<TUserRole>().Where(x => x.UserId.Equals(id))
.Join(DbContext.Set<TRoleClaim>().WhereIf(!string.IsNullOrEmpty(claimSearchText), searchCondition), ur => ur.RoleId, rc => rc.RoleId, (ur, rc) => rc);
var claims= await claimsQ.PageBy(x => x.Id, page, pageSize)
.ToListAsync();
var pagedList = new PagedList<TRoleClaim>();
pagedList.Data.AddRange(claims);
pagedList.TotalCount = await claimsQ.CountAsync();
pagedList.PageSize = pageSize;
return pagedList;
}
}

public virtual async Task<PagedList<TRoleClaim>> GetUserRoleClaimsAsync(string userId, string claimSearchText, int page = 1, int pageSize = 10)
{
var id = ConvertKeyFromString(userId);
Expression<Func<TRoleClaim, bool>> searchCondition = x => x.ClaimType.Contains(claimSearchText);
var claimsQ = DbContext.Set<TUserRole>().Where(x => x.UserId.Equals(id))
.Join(DbContext.Set<TRoleClaim>().WhereIf(!string.IsNullOrEmpty(claimSearchText), searchCondition), ur => ur.RoleId, rc => rc.RoleId, (ur, rc) => rc);

var claims= await claimsQ.PageBy(x => x.Id, page, pageSize)
.ToListAsync();

var pagedList = new PagedList<TRoleClaim>();
pagedList.Data.AddRange(claims);
pagedList.TotalCount = await claimsQ.CountAsync();
pagedList.PageSize = pageSize;

return pagedList;
}

public virtual Task<TUserClaim> GetUserClaimAsync(string userId, int claimId)
{
var userIdConverted = ConvertKeyFromString(userId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,85 +1,85 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using Skoruba.IdentityServer4.Admin.EntityFramework.Extensions.Common;

namespace Skoruba.IdentityServer4.Admin.EntityFramework.Identity.Repositories.Interfaces
{
public interface IIdentityRepository<TUser, TRole, TKey, TUserClaim, TUserRole, TUserLogin, TRoleClaim, TUserToken>
where TUser : IdentityUser<TKey>
where TRole : IdentityRole<TKey>
where TKey : IEquatable<TKey>
where TUserClaim : IdentityUserClaim<TKey>
where TUserRole : IdentityUserRole<TKey>
where TUserLogin : IdentityUserLogin<TKey>
where TRoleClaim : IdentityRoleClaim<TKey>
where TUserToken : IdentityUserToken<TKey>
{
Task<bool> ExistsUserAsync(string userId);

Task<bool> ExistsRoleAsync(string roleId);

Task<PagedList<TUser>> GetUsersAsync(string search, int page = 1, int pageSize = 10);

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using Skoruba.IdentityServer4.Admin.EntityFramework.Extensions.Common;
namespace Skoruba.IdentityServer4.Admin.EntityFramework.Identity.Repositories.Interfaces
{
public interface IIdentityRepository<TUser, TRole, TKey, TUserClaim, TUserRole, TUserLogin, TRoleClaim, TUserToken>
where TUser : IdentityUser<TKey>
where TRole : IdentityRole<TKey>
where TKey : IEquatable<TKey>
where TUserClaim : IdentityUserClaim<TKey>
where TUserRole : IdentityUserRole<TKey>
where TUserLogin : IdentityUserLogin<TKey>
where TRoleClaim : IdentityRoleClaim<TKey>
where TUserToken : IdentityUserToken<TKey>
{
Task<bool> ExistsUserAsync(string userId);
Task<bool> ExistsRoleAsync(string roleId);
Task<PagedList<TUser>> GetUsersAsync(string search, int page = 1, int pageSize = 10);
Task<PagedList<TUser>> GetRoleUsersAsync(string roleId, string search, int page = 1, int pageSize = 10);

Task<PagedList<TUser>> GetClaimUsersAsync(string claimType, string claimValue, int page = 1, int pageSize = 10);

Task<PagedList<TRole>> GetRolesAsync(string search, int page = 1, int pageSize = 10);

Task<(IdentityResult identityResult, TKey roleId)> CreateRoleAsync(TRole role);

Task<TRole> GetRoleAsync(TKey roleId);

Task<List<TRole>> GetRolesAsync();

Task<(IdentityResult identityResult, TKey roleId)> UpdateRoleAsync(TRole role);

Task<TUser> GetUserAsync(string userId);

Task<(IdentityResult identityResult, TKey userId)> CreateUserAsync(TUser user);

Task<(IdentityResult identityResult, TKey userId)> UpdateUserAsync(TUser user);

Task<IdentityResult> DeleteUserAsync(string userId);

Task<IdentityResult> CreateUserRoleAsync(string userId, string roleId);

Task<PagedList<TRole>> GetUserRolesAsync(string userId, int page = 1, int pageSize = 10);

Task<IdentityResult> DeleteUserRoleAsync(string userId, string roleId);

Task<PagedList<TUserClaim>> GetUserClaimsAsync(string userId, int page = 1, int pageSize = 10);

Task<TUserClaim> GetUserClaimAsync(string userId, int claimId);

Task<IdentityResult> CreateUserClaimsAsync(TUserClaim claims);

Task<IdentityResult> DeleteUserClaimAsync(string userId, int claimId);

Task<List<UserLoginInfo>> GetUserProvidersAsync(string userId);

Task<IdentityResult> DeleteUserProvidersAsync(string userId, string providerKey, string loginProvider);

Task<TUserLogin> GetUserProviderAsync(string userId, string providerKey);

Task<IdentityResult> UserChangePasswordAsync(string userId, string password);

Task<IdentityResult> CreateRoleClaimsAsync(TRoleClaim claims);

Task<PagedList<TRoleClaim>> GetRoleClaimsAsync(string roleId, int page = 1, int pageSize = 10);

Task<PagedList<TRoleClaim>> GetUserRoleClaimsAsync(string userId, string claimSearchText, int page = 1, int pageSize = 10);

Task<TRoleClaim> GetRoleClaimAsync(string roleId, int claimId);

Task<IdentityResult> DeleteRoleClaimAsync(string roleId, int claimId);

Task<IdentityResult> DeleteRoleAsync(TRole role);

bool AutoSaveChanges { get; set; }

Task<int> SaveAllChangesAsync();
}
Task<PagedList<TUser>> GetClaimUsersAsync(string claimType, string claimValue, int page = 1, int pageSize = 10);
Task<PagedList<TRole>> GetRolesAsync(string search, int page = 1, int pageSize = 10);
Task<(IdentityResult identityResult, TKey roleId)> CreateRoleAsync(TRole role);
Task<TRole> GetRoleAsync(TKey roleId);
Task<List<TRole>> GetRolesAsync();
Task<(IdentityResult identityResult, TKey roleId)> UpdateRoleAsync(TRole role);
Task<TUser> GetUserAsync(string userId);
Task<(IdentityResult identityResult, TKey userId)> CreateUserAsync(TUser user);
Task<(IdentityResult identityResult, TKey userId)> UpdateUserAsync(TUser user);
Task<IdentityResult> DeleteUserAsync(string userId);
Task<IdentityResult> CreateUserRoleAsync(string userId, string roleId);
Task<PagedList<TRole>> GetUserRolesAsync(string userId, int page = 1, int pageSize = 10);
Task<IdentityResult> DeleteUserRoleAsync(string userId, string roleId);
Task<PagedList<TUserClaim>> GetUserClaimsAsync(string userId, int page = 1, int pageSize = 10);
Task<TUserClaim> GetUserClaimAsync(string userId, int claimId);
Task<IdentityResult> CreateUserClaimsAsync(TUserClaim claims);
Task<IdentityResult> DeleteUserClaimAsync(string userId, int claimId);
Task<List<UserLoginInfo>> GetUserProvidersAsync(string userId);
Task<IdentityResult> DeleteUserProvidersAsync(string userId, string providerKey, string loginProvider);
Task<TUserLogin> GetUserProviderAsync(string userId, string providerKey);
Task<IdentityResult> UserChangePasswordAsync(string userId, string password);
Task<IdentityResult> CreateRoleClaimsAsync(TRoleClaim claims);
Task<PagedList<TRoleClaim>> GetRoleClaimsAsync(string roleId, int page = 1, int pageSize = 10);
Task<PagedList<TRoleClaim>> GetUserRoleClaimsAsync(string userId, string claimSearchText, int page = 1, int pageSize = 10);

Task<TRoleClaim> GetRoleClaimAsync(string roleId, int claimId);
Task<IdentityResult> DeleteRoleClaimAsync(string roleId, int claimId);
Task<IdentityResult> DeleteRoleAsync(TRole role);
bool AutoSaveChanges { get; set; }
Task<int> SaveAllChangesAsync();
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;

namespace Skoruba.IdentityServer4.Admin.EntityFramework.PostgreSQL.Migrations.DataProtection
{
public partial class DbInit : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "DataProtectionKeys",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
FriendlyName = table.Column<string>(nullable: true),
Xml = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_DataProtectionKeys", x => x.Id);
});
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "DataProtectionKeys");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"iisSettings": {
"windowsAuthentication": false,
"windowsAuthentication": true,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "https://localhost:44303",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@

<div class="row">
<div class="col-lg-2 mb-3">
<img-gravatar email="@Model.Email" class="img-thumbnail" size="150" />
@if (!string.IsNullOrEmpty(Model.PhotoUrl))
{
<img class="img-thumbnail" size="150" src="@Model.PhotoUrl" />
}
else
{
<img-gravatar email="@Model.Email" class="img-thumbnail" size="150" />
}
</div>
<div class="col-sm-10">
<!--Input - text -->
Expand Down
Loading