Skip to content

Commit

Permalink
Merge pull request #7 from BeniceSoft/dev/feat-sso-clientapp
Browse files Browse the repository at this point in the history
Dev/feat sso clientapp
  • Loading branch information
zengande authored Apr 28, 2024
2 parents d75aaa2 + a1c38a9 commit e560230
Show file tree
Hide file tree
Showing 17 changed files with 97 additions and 12 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "AdminUI"]
path = AdminUI
url = https://github.com/BeniceSoft/OpenAuthing-AdminUI.git
1 change: 0 additions & 1 deletion AdminUI
Submodule AdminUI deleted from a6e324
12 changes: 8 additions & 4 deletions src/BeniceSoft.OpenAuthing.AdminApi/AuthingAdminApiModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,14 @@ public override void ConfigureServices(ServiceConfigurationContext context)
Configure<IdentityOptions>(options => { options.User.AllowedUserNameCharacters = ""; });

context.Services
.AddJsonFormatResponse().AddDesensitizeResponse()
.AddJsonFormatResponse()
.AddDesensitizeResponse();

context.Services
.ConfigureSwaggerServices()
.ConfigureAuthentication()
.AddDetection();
.ConfigureAuthentication();

context.Services.AddDetection();
}

public override void OnApplicationInitialization(ApplicationInitializationContext context)
Expand All @@ -80,7 +84,7 @@ public override void OnApplicationInitialization(ApplicationInitializationContex
app.UseAuthorization();

app.UseAuditing();

app.UseSwagger();
app.UseSwaggerUI(options => { options.SwaggerEndpoint("/swagger/v1.0/swagger.json", "OpenAuthing API"); });

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using BeniceSoft.Abp.Core.Models;
using BeniceSoft.OpenAuthing.Commands.Applications;
using BeniceSoft.OpenAuthing.Dtos.OpenIddict.Requests;
using BeniceSoft.OpenAuthing.Dtos.OpenIddict.Responses;
Expand All @@ -24,6 +25,7 @@ public ApplicationsController(IApplicationQueries applicationQueries)
/// <param name="searchKey"></param>
/// <returns></returns>
[HttpGet]
[ProducesResponseType<ResponseResult<List<QueryApplicationRes>>>(StatusCodes.Status200OK)]
public async Task<List<QueryApplicationRes>> GetAsync(string? searchKey = null)
{
return await _applicationQueries.ListQueryAsync(searchKey);
Expand All @@ -35,6 +37,7 @@ public async Task<List<QueryApplicationRes>> GetAsync(string? searchKey = null)
/// <param name="req"></param>
/// <returns></returns>
[HttpPost]
[ProducesResponseType<ResponseResult<Guid>>(StatusCodes.Status200OK)]
public async Task<Guid> PostAsync([FromBody] CreateApplicationReq req)
{
var command = new CreateApplicationCommand(req.ClientId, req.DisplayName, req.ClientType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace BeniceSoft.OpenAuthing.Controllers;
[ApiController]
[Route("api/admin/[controller]")]
[Authorize(Roles = AuthingConstants.AdminRoleName)]
[Produces("application/json")]
public abstract class AuthingApiControllerBase : AbpController
{
protected IAsyncQueryableExecuter AsyncExecuter => LazyServiceProvider.LazyGetRequiredService<IAsyncQueryableExecuter>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using BeniceSoft.Abp.Core.Models;
using BeniceSoft.OpenAuthing.Commands.DepartmentMembers;
using BeniceSoft.OpenAuthing.Dtos.DepartmentMembers;
using BeniceSoft.OpenAuthing.Queries;
Expand All @@ -19,6 +20,7 @@ public partial class DepartmentsController
/// <param name="pageSize"></param>
/// <returns></returns>
[HttpGet("{departmentId}/members")]
[ProducesResponseType<ResponseResult<PagedResultDto<QueryDepartmentMembersRes>>>(StatusCodes.Status200OK)]
public async Task<PagedResultDto<QueryDepartmentMembersRes>> GetMemberAsync(Guid departmentId, bool onlyDirectUsers = false, int pageIndex = 1,
int pageSize = 20)
{
Expand All @@ -37,6 +39,7 @@ public async Task<PagedResultDto<QueryDepartmentMembersRes>> GetMemberAsync(Guid
/// <param name="req"></param>
/// <returns></returns>
[HttpPost("{departmentId}/members")]
[ProducesResponseType<ResponseResult<int>>(StatusCodes.Status200OK)]
public async Task<int> PostMemberAsync(Guid departmentId, [FromBody] AddDepartmentMembersReq req)
{
var command = new AddDepartmentMembersCommand
Expand All @@ -55,6 +58,7 @@ public async Task<int> PostMemberAsync(Guid departmentId, [FromBody] AddDepartme
/// <param name="isLeader"></param>
/// <returns></returns>
[HttpPut("{departmentId}/members/{userId}/leader")]
[ProducesResponseType<ResponseResult<bool>>(StatusCodes.Status200OK)]
public async Task<bool> SetLeaderAsync(Guid departmentId, Guid userId, [FromQuery] bool isLeader)
{
var command = new SetLeaderCommand
Expand All @@ -74,6 +78,7 @@ public async Task<bool> SetLeaderAsync(Guid departmentId, Guid userId, [FromQuer
/// <param name="isMain"></param>
/// <returns></returns>
[HttpPut("{departmentId}/members/{userId}/main")]
[ProducesResponseType<ResponseResult<bool>>(StatusCodes.Status200OK)]
public async Task<bool> SetMainAsync(Guid departmentId, Guid userId, [FromQuery] bool isMain)
{
var command = new SetMainDepartmentCommand
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public async Task<bool> PutAsync(Guid id, [FromBody] UpdateDepartmentReq req)
[Authorize(AuthingPermissions.DeleteDepartment)]
public async Task<bool> DeleteAsync(Guid id)
{
throw new NotImplementedException();
var command = new DeleteDepartmentCommand(id);
return await Mediator.Send(command);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using BeniceSoft.Abp.Core.Models;
using BeniceSoft.OpenAuthing.Models.GeneralResources;
using Microsoft.AspNetCore.Mvc;

Expand All @@ -13,6 +14,7 @@ public class GeneralResourcesController : AuthingApiControllerBase
/// </summary>
/// <returns></returns>
[HttpPost]
[ProducesResponseType<ResponseResult<Guid>>(StatusCodes.Status200OK)]
public async Task<Guid> PostAsync(CreateGeneralResourceReq req)
{
return Guid.Empty;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using BeniceSoft.Abp.Core.Models;
using BeniceSoft.OpenAuthing.Commands.Roles;
using BeniceSoft.OpenAuthing.Dtos.Roles;
using BeniceSoft.OpenAuthing.Models.Roles;
Expand All @@ -13,6 +14,7 @@ public partial class RolesController
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("{id}/subjects")]
[ProducesResponseType<ResponseResult<List<RoleSubjectRes>>>(StatusCodes.Status200OK)]
public async Task<List<RoleSubjectRes>> GetSubjectsAsync(Guid id)
{
return await _roleQueries.ListRoleSubjectsAsync(id);
Expand All @@ -25,6 +27,7 @@ public async Task<List<RoleSubjectRes>> GetSubjectsAsync(Guid id)
/// <param name="req"></param>
/// <returns></returns>
[HttpPut("{id}/subjects")]
[ProducesResponseType<ResponseResult<bool>>(StatusCodes.Status200OK)]
public async Task<bool> SaveSubjectsAsync(Guid id, [FromBody] SaveRoleSubjectsReq req)
{
var command = new SaveRoleSubjectsCommand(id, req.Subjects);
Expand All @@ -38,6 +41,7 @@ public async Task<bool> SaveSubjectsAsync(Guid id, [FromBody] SaveRoleSubjectsRe
/// <param name="roleSubjectId"></param>
/// <returns></returns>
[HttpDelete("{id}/subjects/{roleSubjectId}")]
[ProducesResponseType<ResponseResult<bool>>(StatusCodes.Status200OK)]
public async Task<bool> RemoveSubjectAsync(Guid id, Guid roleSubjectId)
{
var command = new RemoveRoleSubjectCommand(id, roleSubjectId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using BeniceSoft.Abp.Core.Models;
using BeniceSoft.OpenAuthing.Commands.Roles;
using BeniceSoft.OpenAuthing.Dtos.Roles;
using BeniceSoft.OpenAuthing.Models.Roles;
Expand Down Expand Up @@ -27,6 +28,7 @@ public RolesController(IRoleQueries roleQueries)
/// <param name="pageSize"></param>
/// <returns></returns>
[HttpGet]
[ProducesResponseType<ResponseResult<PagedResultDto<RoleSimpleRes>>>(StatusCodes.Status200OK)]
public async Task<PagedResultDto<RoleSimpleRes>> GetAsync(string? searchKey = null, int pageIndex = 1, int pageSize = 20)
{
var req = new RolePageQueryReq
Expand All @@ -44,6 +46,7 @@ public async Task<PagedResultDto<RoleSimpleRes>> GetAsync(string? searchKey = nu
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("{id}")]
[ProducesResponseType<ResponseResult<PagedResultDto<RoleDetailRes>>>(StatusCodes.Status200OK)]
public async Task<RoleDetailRes> GetAsync(Guid id)
{
return await _roleQueries.GetDetailAsync(id);
Expand All @@ -55,6 +58,7 @@ public async Task<RoleDetailRes> GetAsync(Guid id)
/// <param name="req"></param>
/// <returns></returns>
[HttpPost]
[ProducesResponseType<ResponseResult<Guid>>(StatusCodes.Status200OK)]
public async Task<Guid> PostAsync([FromBody] InputRoleReq req)
{
var command = new CreateRoleCommand(req.Name, req.DisplayName, req.Description ?? string.Empty, req.PermissionSpaceId);
Expand All @@ -68,6 +72,7 @@ public async Task<Guid> PostAsync([FromBody] InputRoleReq req)
/// <param name="req"></param>
/// <returns></returns>
[HttpPut("{id}")]
[ProducesResponseType<ResponseResult<bool>>(StatusCodes.Status200OK)]
public async Task<bool> PusAsync(Guid id, [FromBody] InputRoleReq req)
{
var command = new UpdateRoleCommand(id, req.Name, req.DisplayName, req.Description);
Expand All @@ -80,6 +85,7 @@ public async Task<bool> PusAsync(Guid id, [FromBody] InputRoleReq req)
/// <param name="id"></param>
/// <returns></returns>
[HttpDelete("{id}")]
[ProducesResponseType<ResponseResult<bool>>(StatusCodes.Status200OK)]
public async Task<bool> DeleteAsync(Guid id)
{
var command = new DeleteRoleCommand(id);
Expand All @@ -93,6 +99,7 @@ public async Task<bool> DeleteAsync(Guid id)
/// <param name="enabled"></param>
/// <returns></returns>
[HttpPut("{id}/toggle-enabled")]
[ProducesResponseType<ResponseResult<bool>>(StatusCodes.Status200OK)]
public async Task<bool> ToggleEnabled(Guid id, bool enabled)
{
var command = new ToggleRoleEnabledCommand(id, enabled);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using BeniceSoft.Abp.Core.Models;
using BeniceSoft.OpenAuthing.Dtos.UserGroups;
using BeniceSoft.OpenAuthing.Queries;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -25,6 +26,7 @@ public UserGroupsController(IUserGroupQueries userGroupQueries)
/// <param name="pageSize"></param>
/// <returns></returns>
[HttpGet]
[ProducesResponseType<ResponseResult<PagedResultDto<UserGroupPagedRes>>>(StatusCodes.Status200OK)]
public async Task<PagedResultDto<UserGroupPagedRes>> GetAsync(string? searchKey = null, int pageIndex = 1, int pageSize = 20)
{
var req = new UserGroupPagedReq
Expand All @@ -42,6 +44,7 @@ public async Task<PagedResultDto<UserGroupPagedRes>> GetAsync(string? searchKey
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("{id}")]
[ProducesResponseType<ResponseResult<GetUserGroupRes>>(StatusCodes.Status200OK)]
public async Task<GetUserGroupRes> GetAsync(Guid id)
{
return await _userGroupQueries.GetDetailAsync(id);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BeniceSoft.OpenAuthing.Commands.Users;
using BeniceSoft.Abp.Core.Models;
using BeniceSoft.OpenAuthing.Commands.Users;
using BeniceSoft.OpenAuthing.Dtos.DepartmentMembers;
using BeniceSoft.OpenAuthing.Dtos.Users;
using BeniceSoft.OpenAuthing.Models.Users;
Expand Down Expand Up @@ -30,6 +31,7 @@ public UsersController(IUserQueries userQueries)
/// <param name="onlyEnabled"></param>
/// <returns></returns>
[HttpGet]
[ProducesResponseType<ResponseResult<PagedResultDto<UserPagedRes>>>(StatusCodes.Status200OK)]
public async Task<PagedResultDto<UserPagedRes>> GetAsync(string? searchKey = null, int pageIndex = 1, int pageSize = 20,
Guid? excludeDepartmentId = null, bool onlyEnabled = false)
{
Expand All @@ -50,6 +52,7 @@ public async Task<PagedResultDto<UserPagedRes>> GetAsync(string? searchKey = nul
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("{id}")]
[ProducesResponseType<ResponseResult<UserDetailRes>>(StatusCodes.Status200OK)]
public async Task<UserDetailRes> GetAsync(Guid id)
{
return await _userQueries.GetDetailAsync(id);
Expand All @@ -61,6 +64,7 @@ public async Task<UserDetailRes> GetAsync(Guid id)
/// <param name="req"></param>
/// <returns></returns>
[HttpPost]
[ProducesResponseType<ResponseResult<Guid>>(StatusCodes.Status200OK)]
public async Task<Guid> PostAsync([FromBody] CreateUserReq req)
{
var command = new CreateUserCommand(req.UserName, req.PhoneNumber, req.Password, req.PhoneNumberConfirmed);
Expand All @@ -74,6 +78,7 @@ public async Task<Guid> PostAsync([FromBody] CreateUserReq req)
/// <param name="req"></param>
/// <returns></returns>
[HttpPut("{id}/avatar")]
[ProducesResponseType<ResponseResult<bool>>(StatusCodes.Status200OK)]
public async Task<bool> UploadUserAvatarAsync(Guid id, [FromForm] UpdateUserAvatarReq req)
{
await using var stream = req.File.OpenReadStream();
Expand All @@ -93,6 +98,7 @@ public async Task<bool> UploadUserAvatarAsync(Guid id, [FromForm] UpdateUserAvat
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("{id}/departments")]
[ProducesResponseType<ResponseResult<List<UserDepartmentDto>>>(StatusCodes.Status200OK)]
public async Task<List<UserDepartmentDto>> GetUserDepartmentsAsync(Guid id)
{
return await _userQueries.ListUserDepartmentsAsync(id);
Expand All @@ -104,6 +110,7 @@ public async Task<List<UserDepartmentDto>> GetUserDepartmentsAsync(Guid id)
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("{id}/roles")]
[ProducesResponseType<ResponseResult<List<UserRoleRes>>>(StatusCodes.Status200OK)]
public async Task<List<UserRoleRes>> GetUserRolesAsync(Guid id)
{
throw new NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static IServiceCollection ConfigureSwaggerServices(this IServiceCollectio
return services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1.0", new OpenApiInfo { Title = "OpenAuthing API", Version = "1.0" });
options.DocInclusionPredicate((doc, description) => true);
// options.DocInclusionPredicate((doc, description) => true);
options.CustomSchemaIds(type => type.FullName);
foreach (var item in GetXmlCommentsFilePath())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"ApiHost": "http://localhost:5130/"
},
"ConnectionStrings": {
"Default": "Data Source=localhost;Initial Catalog=openauthing2;Persist Security Info=True;User ID=root;Password=123456;SslMode=none;Pooling=true;"
"Default": "Data Source=localhost;Initial Catalog=openauthing2;Persist Security Info=True;User ID=root;Password=123456;SslMode=none;Pooling=true;AllowPublicKeyRetrieval=True"
},
"DingTalk": {
"AppKey": "dingluvrzm3p1hh8i0kg",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using MediatR;

namespace BeniceSoft.OpenAuthing.Commands.Departments;

public class DeleteDepartmentCommand : IRequest<bool>
{
public DeleteDepartmentCommand(Guid departmentId)
{
DepartmentId = departmentId;
}

public Guid DepartmentId { get; private set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using BeniceSoft.OpenAuthing.Entities.Departments;
using MediatR;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories;

namespace BeniceSoft.OpenAuthing.Commands.Departments;

public class DeleteDepartmentCommandHandler : IRequestHandler<DeleteDepartmentCommand, bool>, ITransientDependency
{
private readonly IRepository<Department,Guid> _departmentRepository;

public DeleteDepartmentCommandHandler(IRepository<Department, Guid> departmentRepository)
{
_departmentRepository = departmentRepository;
}

public async Task<bool> Handle(DeleteDepartmentCommand request, CancellationToken cancellationToken)
{
// 删除部门及子部门
var department = await _departmentRepository.GetAsync(request.DepartmentId, cancellationToken: cancellationToken);
if (department == null)
{
throw new EntityNotFoundException(typeof(Department), request.DepartmentId);
}
// 删除当前部门
await _departmentRepository.DeleteAsync(department, cancellationToken: cancellationToken);
// 删除当前部门下的子部门,使用部门上的 path 字段判断
var children = await _departmentRepository.GetListAsync(x => x.Path.StartsWith(department.Path), cancellationToken: cancellationToken);
foreach (var child in children)
{
await _departmentRepository.DeleteAsync(child, cancellationToken: cancellationToken);
}

return true;
}
}
2 changes: 2 additions & 0 deletions src/BeniceSoft.OpenAuthing.SSO/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using BeniceSoft.Abp.Auth.Core;
using BeniceSoft.OpenAuthing.Entities.Roles;
using BeniceSoft.OpenAuthing.Entities.Users;
// ReSharper disable once RedundantUsingDirective
using BeniceSoft.OpenAuthing.Extensions;
using BeniceSoft.OpenAuthing.Identity;
using BeniceSoft.OpenAuthing.OpenIddictExtensions;
using BeniceSoft.OpenAuthing.OpenIddictExtensions.ClaimDestinations;
Expand Down

0 comments on commit e560230

Please sign in to comment.