38 changed files with 2625 additions and 13 deletions
@ -0,0 +1,27 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace CompanyName.ProjectName.IdentityServers.Dtos |
|||
{ |
|||
public class ApiResourceOutput |
|||
{ |
|||
public string Name { get; set; } |
|||
|
|||
public string DisplayName { get; set; } |
|||
|
|||
public string Description { get; set; } |
|||
|
|||
public bool Enabled { get; set; } |
|||
|
|||
public string AllowedAccessTokenSigningAlgorithms { get; set; } |
|||
|
|||
public bool ShowInDiscoveryDocument { get; set; } = true; |
|||
|
|||
public List<ApiResourceSecretOutput> Secrets { get; set; } |
|||
|
|||
public List<ApiResourceScopeOutput> Scopes { get; set; } |
|||
|
|||
public List<ApiResourceClaimOutput> UserClaims { get; set; } |
|||
|
|||
public List<ApiResourcePropertyOutput> Properties { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace CompanyName.ProjectName.IdentityServers.Dtos |
|||
{ |
|||
public class CreateApiResourceInput |
|||
{ |
|||
public string Name { get; set; } |
|||
|
|||
public string DisplayName { get; set; } |
|||
|
|||
public string Description { get; set; } |
|||
|
|||
public bool Enabled { get; set; } |
|||
|
|||
public string AllowedAccessTokenSigningAlgorithms { get; set; } |
|||
|
|||
public bool ShowInDiscoveryDocument { get; set; } = true; |
|||
|
|||
public List<ApiResourceSecretOutput> Secrets { get; set; } |
|||
|
|||
public List<ApiResourceScopeOutput> Scopes { get; set; } |
|||
|
|||
public List<ApiResourceClaimOutput> UserClaims { get; set; } |
|||
|
|||
public List<ApiResourcePropertyOutput> Properties { get; set; } |
|||
|
|||
public CreateApiResourceInput() |
|||
{ |
|||
Secrets = new List<ApiResourceSecretOutput>(); |
|||
Scopes = new List<ApiResourceScopeOutput>(); |
|||
UserClaims = new List<ApiResourceClaimOutput>(); |
|||
Properties = new List<ApiResourcePropertyOutput>(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using CompanyName.ProjectName.Extensions.Customs; |
|||
|
|||
namespace CompanyName.ProjectName.IdentityServers.Dtos |
|||
{ |
|||
public class PagingApiRseourceListInput : PagingBase |
|||
{ |
|||
public string Filter { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace CompanyName.ProjectName.IdentityServers.Dtos |
|||
{ |
|||
public class UpdateApiResourceInput |
|||
{ |
|||
public string Name { get; set; } |
|||
|
|||
public string DisplayName { get; set; } |
|||
|
|||
public string Description { get; set; } |
|||
|
|||
public bool Enabled { get; set; } |
|||
|
|||
public string AllowedAccessTokenSigningAlgorithms { get; set; } |
|||
|
|||
public bool ShowInDiscoveryDocument { get; set; } = true; |
|||
|
|||
public List<ApiResourceSecretOutput> Secrets { get; set; } |
|||
|
|||
public List<ApiResourceScopeOutput> Scopes { get; set; } |
|||
|
|||
public List<ApiResourceClaimOutput> UserClaims { get; set; } |
|||
|
|||
public List<ApiResourcePropertyOutput> Properties { get; set; } |
|||
|
|||
public UpdateApiResourceInput() |
|||
{ |
|||
Secrets = new List<ApiResourceSecretOutput>(); |
|||
Scopes = new List<ApiResourceScopeOutput>(); |
|||
UserClaims = new List<ApiResourceClaimOutput>(); |
|||
Properties = new List<ApiResourcePropertyOutput>(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using CompanyName.ProjectName.IdentityServers.Dtos; |
|||
using CompanyName.ProjectName.Publics.Dtos; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.Application.Services; |
|||
|
|||
namespace CompanyName.ProjectName.IdentityServers |
|||
{ |
|||
public interface IApiResourceAppService : IApplicationService |
|||
{ |
|||
Task<PagedResultDto<ApiResourceOutput>> GetListAsync(PagingApiRseourceListInput input); |
|||
|
|||
/// <summary>
|
|||
/// 获取所有api resource
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
Task<List<ApiResourceOutput>> GetApiResources(); |
|||
|
|||
/// <summary>
|
|||
/// 新增 ApiResource
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
Task CreateAsync(CreateApiResourceInput input); |
|||
|
|||
/// <summary>
|
|||
/// 删除 ApiResource
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
Task DeleteAsync(IdInput input); |
|||
|
|||
/// <summary>
|
|||
/// 更新 ApiResource
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
Task UpdateAsync(UpdateApiResourceInput input); |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace CompanyName.ProjectName.IdentityServers.Clients |
|||
{ |
|||
public class AddCorsInput |
|||
{ |
|||
[Required] |
|||
public string ClientId { get; set; } |
|||
|
|||
[Required] |
|||
public string Origin { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using System.Collections.Generic; |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace CompanyName.ProjectName.IdentityServers.Clients |
|||
{ |
|||
public class AddRedirectUriInput |
|||
{ |
|||
[Required] |
|||
public string ClientId { get; set; } |
|||
[Required] |
|||
public string Uri { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using System; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace CompanyName.ProjectName.IdentityServers.Clients |
|||
{ |
|||
public class ClientClaimOutput |
|||
{ |
|||
public Guid ClientId { get; set; } |
|||
|
|||
public string Type { get; set; } |
|||
|
|||
public string Value { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
using System; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace CompanyName.ProjectName.IdentityServers.Clients |
|||
{ |
|||
public class ClientCorsOriginOutput |
|||
{ |
|||
public Guid ClientId { get; set; } |
|||
|
|||
public string Origin { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using System; |
|||
|
|||
namespace CompanyName.ProjectName.IdentityServers.Clients |
|||
{ |
|||
public class ClientGrantTypeOutput |
|||
{ |
|||
public Guid ClientId { get; set; } |
|||
|
|||
public string GrantType { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
using System; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace CompanyName.ProjectName.IdentityServers.Clients |
|||
{ |
|||
public class ClientIdPRestrictionOutput |
|||
{ |
|||
public Guid ClientId { get; set; } |
|||
|
|||
public string Provider { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,105 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace CompanyName.ProjectName.IdentityServers.Clients |
|||
{ |
|||
public class ClientOutput : EntityDto<Guid> |
|||
{ |
|||
public string ClientId { get; set; } |
|||
|
|||
public string ClientName { get; set; } |
|||
|
|||
public string Description { get; set; } |
|||
|
|||
public string ClientUri { get; set; } |
|||
|
|||
public string LogoUri { get; set; } |
|||
|
|||
public bool Enabled { get; set; } |
|||
|
|||
public string ProtocolType { get; set; } |
|||
|
|||
public bool RequireClientSecret { get; set; } |
|||
|
|||
public bool RequireConsent { get; set; } |
|||
|
|||
public bool AllowRememberConsent { get; set; } |
|||
|
|||
public bool AlwaysIncludeUserClaimsInIdToken { get; set; } |
|||
|
|||
public bool RequirePkce { get; set; } |
|||
|
|||
public bool AllowPlainTextPkce { get; set; } |
|||
|
|||
public bool RequireRequestObject { get; set; } |
|||
|
|||
public bool AllowAccessTokensViaBrowser { get; set; } |
|||
|
|||
public string FrontChannelLogoutUri { get; set; } |
|||
|
|||
public bool FrontChannelLogoutSessionRequired { get; set; } |
|||
|
|||
public string BackChannelLogoutUri { get; set; } |
|||
|
|||
public bool BackChannelLogoutSessionRequired { get; set; } |
|||
|
|||
public bool AllowOfflineAccess { get; set; } |
|||
|
|||
public int IdentityTokenLifetime { get; set; } |
|||
|
|||
public string AllowedIdentityTokenSigningAlgorithms { get; set; } |
|||
|
|||
public int AccessTokenLifetime { get; set; } |
|||
|
|||
public int AuthorizationCodeLifetime { get; set; } |
|||
|
|||
public int? ConsentLifetime { get; set; } |
|||
|
|||
public int AbsoluteRefreshTokenLifetime { get; set; } |
|||
|
|||
public int SlidingRefreshTokenLifetime { get; set; } |
|||
|
|||
public int RefreshTokenUsage { get; set; } |
|||
|
|||
public bool UpdateAccessTokenClaimsOnRefresh { get; set; } |
|||
|
|||
public int RefreshTokenExpiration { get; set; } |
|||
|
|||
public int AccessTokenType { get; set; } |
|||
|
|||
public bool EnableLocalLogin { get; set; } |
|||
|
|||
public bool IncludeJwtId { get; set; } |
|||
|
|||
public bool AlwaysSendClientClaims { get; set; } |
|||
|
|||
public string ClientClaimsPrefix { get; set; } |
|||
|
|||
public string PairWiseSubjectSalt { get; set; } |
|||
|
|||
public int? UserSsoLifetime { get; set; } |
|||
|
|||
public string UserCodeType { get; set; } |
|||
|
|||
public int DeviceCodeLifetime { get; set; } |
|||
|
|||
public List<ClientScopeOutput> AllowedScopes { get; set; } |
|||
|
|||
public List<ClientSecretOutput> ClientSecrets { get; set; } |
|||
|
|||
public List<ClientGrantTypeOutput> AllowedGrantTypes { get; set; } |
|||
|
|||
public List<ClientCorsOriginOutput> AllowedCorsOrigins { get; set; } |
|||
|
|||
public List<ClientRedirectUriOutput> RedirectUris { get; set; } |
|||
|
|||
public List<ClientPostLogoutRedirectUriOutput> PostLogoutRedirectUris { get; set; } |
|||
|
|||
public List<ClientIdPRestrictionOutput> IdentityProviderRestrictions { get; set; } |
|||
|
|||
public List<ClientClaimOutput> Claims { get; set; } |
|||
|
|||
public List<ClientPropertyOutput> Properties { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
using System; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace CompanyName.ProjectName.IdentityServers.Clients |
|||
{ |
|||
public class ClientPostLogoutRedirectUriOutput |
|||
{ |
|||
public Guid ClientId { get; set; } |
|||
|
|||
public string PostLogoutRedirectUri { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using System; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace CompanyName.ProjectName.IdentityServers.Clients |
|||
{ |
|||
public class ClientPropertyOutput |
|||
{ |
|||
public Guid ClientId { get; set; } |
|||
|
|||
public string Key { get; set; } |
|||
|
|||
public string Value { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using System; |
|||
using Volo.Abp.Application.Dtos; |
|||
namespace CompanyName.ProjectName.IdentityServers.Clients |
|||
{ |
|||
public class ClientRedirectUriOutput |
|||
{ |
|||
public virtual Guid ClientId { get; set; } |
|||
|
|||
public virtual string RedirectUri { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using System; |
|||
|
|||
namespace CompanyName.ProjectName.IdentityServers.Clients |
|||
{ |
|||
public class ClientScopeOutput |
|||
{ |
|||
public Guid ClientId { get; set; } |
|||
|
|||
public string Scope { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
using System; |
|||
|
|||
namespace CompanyName.ProjectName.IdentityServers.Clients |
|||
{ |
|||
public class ClientSecretOutput |
|||
{ |
|||
public string Type { get; set; } |
|||
|
|||
public string Value { get; set; } |
|||
|
|||
public string Description { get; set; } |
|||
|
|||
public DateTime? Expiration { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace CompanyName.ProjectName.IdentityServers.Clients |
|||
{ |
|||
public class CreateClientInput |
|||
{ |
|||
[Required] public string ClientId { get; set; } |
|||
|
|||
[Required] public string ClientName { get; set; } |
|||
|
|||
public string Description { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using CompanyName.ProjectName.Extensions.Customs; |
|||
|
|||
namespace CompanyName.ProjectName.IdentityServers.Clients |
|||
{ |
|||
public class PagingClientListInput:PagingBase |
|||
{ |
|||
public string Filter { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace CompanyName.ProjectName.IdentityServers.Clients |
|||
{ |
|||
public class RemoveCorsInput |
|||
{ |
|||
[Required] |
|||
public string ClientId { get; set; } |
|||
|
|||
[Required] |
|||
public string Origin { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace CompanyName.ProjectName.IdentityServers.Clients |
|||
{ |
|||
public class RemoveRedirectUriInput |
|||
{ |
|||
[Required] |
|||
public string ClientId { get; set; } |
|||
|
|||
[Required] |
|||
public string Uri { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,83 @@ |
|||
namespace CompanyName.ProjectName.IdentityServers.Clients |
|||
{ |
|||
public class UpdataBasicDataInput |
|||
{ |
|||
public string ClientId { get; set; } |
|||
|
|||
public string ClientName { get; set; } |
|||
|
|||
public string Description { get; set; } |
|||
|
|||
public string ClientUri { get; set; } |
|||
|
|||
public string LogoUri { get; set; } |
|||
|
|||
public bool Enabled { get; set; } = true; |
|||
|
|||
public string ProtocolType { get; set; } |
|||
|
|||
public bool RequireClientSecret { get; set; } |
|||
|
|||
public bool RequireConsent { get; set; } |
|||
|
|||
public bool AllowRememberConsent { get; set; } |
|||
|
|||
public bool AlwaysIncludeUserClaimsInIdToken { get; set; } |
|||
|
|||
public bool RequirePkce { get; set; } |
|||
|
|||
public bool AllowPlainTextPkce { get; set; } |
|||
|
|||
public bool RequireRequestObject { get; set; } |
|||
|
|||
public bool AllowAccessTokensViaBrowser { get; set; } |
|||
|
|||
public string FrontChannelLogoutUri { get; set; } |
|||
|
|||
public bool FrontChannelLogoutSessionRequired { get; set; } |
|||
|
|||
public string BackChannelLogoutUri { get; set; } |
|||
|
|||
public bool BackChannelLogoutSessionRequired { get; set; } |
|||
|
|||
public bool AllowOfflineAccess { get; set; } |
|||
|
|||
public int IdentityTokenLifetime { get; set; } |
|||
|
|||
public string AllowedIdentityTokenSigningAlgorithms { get; set; } |
|||
|
|||
public int AccessTokenLifetime { get; set; } |
|||
|
|||
public int AuthorizationCodeLifetime { get; set; } |
|||
|
|||
public int? ConsentLifetime { get; set; } |
|||
|
|||
public int AbsoluteRefreshTokenLifetime { get; set; } |
|||
|
|||
public int SlidingRefreshTokenLifetime { get; set; } |
|||
|
|||
public int RefreshTokenUsage { get; set; } |
|||
|
|||
public bool UpdateAccessTokenClaimsOnRefresh { get; set; } |
|||
|
|||
public int RefreshTokenExpiration { get; set; } |
|||
|
|||
public int AccessTokenType { get; set; } |
|||
|
|||
public bool EnableLocalLogin { get; set; } |
|||
|
|||
public bool IncludeJwtId { get; set; } |
|||
|
|||
public bool AlwaysSendClientClaims { get; set; } |
|||
|
|||
public string ClientClaimsPrefix { get; set; } |
|||
|
|||
public string PairWiseSubjectSalt { get; set; } |
|||
|
|||
public int? UserSsoLifetime { get; set; } |
|||
|
|||
public string UserCodeType { get; set; } |
|||
|
|||
public int DeviceCodeLifetime { get; set; } = 300; |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
using System.Collections.Generic; |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace CompanyName.ProjectName.IdentityServers.Clients |
|||
{ |
|||
public class UpdateScopeInput |
|||
{ |
|||
[Required] |
|||
public string ClientId { get; set; } |
|||
|
|||
public List<string> Scopes { get; set; } |
|||
|
|||
public UpdateScopeInput() |
|||
{ |
|||
Scopes = new List<string>(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,71 @@ |
|||
using System.Threading.Tasks; |
|||
using CompanyName.ProjectName.Publics.Dtos; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.Application.Services; |
|||
|
|||
namespace CompanyName.ProjectName.IdentityServers.Clients |
|||
{ |
|||
public interface IIdentityServerClientAppService : IApplicationService |
|||
{ |
|||
/// <summary>
|
|||
/// 分页查询Client
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
Task<PagedResultDto<ClientOutput>> GetListAsync(PagingClientListInput input); |
|||
|
|||
/// <summary>
|
|||
/// 创建Client
|
|||
/// </summary>
|
|||
/// <param name="input"></param>
|
|||
/// <returns></returns>
|
|||
Task CreateAsync(CreateClientInput input); |
|||
|
|||
/// <summary>
|
|||
/// 删除client
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
Task DeleteAsync(IdInput input); |
|||
|
|||
/// <summary>
|
|||
/// 更新基本信息
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
Task UpdateBasicDataAsync(UpdataBasicDataInput input); |
|||
|
|||
/// <summary>
|
|||
/// 更新client scopes
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
Task UpdateScopesAsync(UpdateScopeInput input); |
|||
|
|||
/// <summary>
|
|||
/// 新增回调地址
|
|||
/// </summary>
|
|||
Task AddRedirectUriAsync(AddRedirectUriInput input); |
|||
|
|||
/// <summary>
|
|||
/// 删除回调地址
|
|||
/// </summary>
|
|||
Task RemoveRedirectUriAsync(RemoveRedirectUriInput input); |
|||
|
|||
/// <summary>
|
|||
/// 新增Logout回调地址
|
|||
/// </summary>
|
|||
Task AddLogoutRedirectUriAsync(AddRedirectUriInput input); |
|||
|
|||
/// <summary>
|
|||
/// 删除Logout回调地址
|
|||
/// </summary>
|
|||
Task RemoveLogoutRedirectUriAsync(RemoveRedirectUriInput input); |
|||
|
|||
/// <summary>
|
|||
/// 添加cors
|
|||
/// </summary>
|
|||
Task AddCorsAsync(AddCorsInput input); |
|||
|
|||
/// <summary>
|
|||
/// 删除cors
|
|||
/// </summary>
|
|||
Task RemoveCorsAsync(RemoveCorsInput input); |
|||
} |
|||
} |
|||
@ -0,0 +1,92 @@ |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using CompanyName.ProjectName.IdentityServer; |
|||
using CompanyName.ProjectName.IdentityServers.Dtos; |
|||
using CompanyName.ProjectName.Publics.Dtos; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.IdentityServer.ApiResources; |
|||
|
|||
namespace CompanyName.ProjectName.IdentityServers.ApiResources |
|||
{ |
|||
public class ApiResourceAppService : ProjectNameAppService, IApiResourceAppService |
|||
{ |
|||
private readonly IdenityServerApiResourceManager _idenityServerApiResourceManager; |
|||
|
|||
public ApiResourceAppService(IdenityServerApiResourceManager idenityServerApiResourceManager) |
|||
{ |
|||
_idenityServerApiResourceManager = idenityServerApiResourceManager; |
|||
} |
|||
|
|||
public async Task<PagedResultDto<ApiResourceOutput>> GetListAsync(PagingApiRseourceListInput input) |
|||
{ |
|||
var list = await _idenityServerApiResourceManager.GetListAsync( |
|||
input.SkipCount, |
|||
input.PageSize, |
|||
input.Filter, |
|||
true); |
|||
var totalCount = await _idenityServerApiResourceManager.GetCountAsync(input.Filter); |
|||
return new PagedResultDto<ApiResourceOutput>(totalCount, |
|||
ObjectMapper.Map<List<ApiResource>, List<ApiResourceOutput>>(list)); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 获取所有api resource
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
public async Task<List<ApiResourceOutput>> GetApiResources() |
|||
{ |
|||
var list = await _idenityServerApiResourceManager.GetResources(false); |
|||
return ObjectMapper.Map<List<ApiResource>, List<ApiResourceOutput>>(list); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 新增 ApiResource
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
public Task CreateAsync(CreateApiResourceInput input) |
|||
{ |
|||
return _idenityServerApiResourceManager.CreateAsync( |
|||
GuidGenerator.Create(), |
|||
input.Name, |
|||
input.DisplayName, |
|||
input.Description, |
|||
input.Enabled, |
|||
input.AllowedAccessTokenSigningAlgorithms, |
|||
input.ShowInDiscoveryDocument, |
|||
input.Secrets, |
|||
input.Scopes, |
|||
input.UserClaims, |
|||
input.Properties |
|||
); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 删除 ApiResource
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
public async Task DeleteAsync(IdInput input) |
|||
{ |
|||
await _idenityServerApiResourceManager.DeleteAsync(input.Id); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 更新 ApiResource
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
public Task UpdateAsync(UpdateApiResourceInput input) |
|||
{ |
|||
return _idenityServerApiResourceManager.UpdateAsync( |
|||
input.Name, |
|||
input.DisplayName, |
|||
input.Description, |
|||
input.Enabled, |
|||
input.AllowedAccessTokenSigningAlgorithms, |
|||
input.ShowInDiscoveryDocument, |
|||
input.Secrets, |
|||
input.Scopes, |
|||
input.UserClaims, |
|||
input.Properties |
|||
); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,157 @@ |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using CompanyName.ProjectName.IdentityServer; |
|||
using CompanyName.ProjectName.Publics.Dtos; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.IdentityServer.Clients; |
|||
|
|||
namespace CompanyName.ProjectName.IdentityServers.Clients |
|||
{ |
|||
public class IdentityServerClientAppService : ProjectNameAppService, IIdentityServerClientAppService |
|||
{ |
|||
private readonly IdenityServerClientManager _idenityServerClientManager; |
|||
|
|||
public IdentityServerClientAppService(IdenityServerClientManager idenityServerClientManager) |
|||
{ |
|||
_idenityServerClientManager = idenityServerClientManager; |
|||
} |
|||
|
|||
|
|||
public async Task<PagedResultDto<ClientOutput>> GetListAsync(PagingClientListInput input) |
|||
{ |
|||
var list = await _idenityServerClientManager.GetListAsync( |
|||
input.SkipCount, |
|||
input.PageSize, |
|||
input.Filter, |
|||
true); |
|||
var totalCount = await _idenityServerClientManager.GetCountAsync(input.Filter); |
|||
return new PagedResultDto<ClientOutput>(totalCount, |
|||
ObjectMapper.Map<List<Client>, List<ClientOutput>>(list)); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 创建Client
|
|||
/// </summary>
|
|||
/// <param name="input"></param>
|
|||
/// <returns></returns>
|
|||
public Task CreateAsync(CreateClientInput input) |
|||
{ |
|||
return _idenityServerClientManager.CreateAsync(input.ClientId, input.ClientName, input.Description); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 删除client
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
public Task DeleteAsync(IdInput input) |
|||
{ |
|||
return _idenityServerClientManager.DeleteAsync(input.Id); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 更新基本信息
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
public Task UpdateBasicDataAsync(UpdataBasicDataInput input) |
|||
{ |
|||
return _idenityServerClientManager.UpdateBasicDataAsync( |
|||
input.ClientId, |
|||
input.ClientName, |
|||
input.Description, |
|||
input.ClientUri, |
|||
input.LogoUri, |
|||
input.Enabled, |
|||
input.ProtocolType, |
|||
input.RequireClientSecret, |
|||
input.RequireConsent, |
|||
input.AllowRememberConsent, |
|||
input.AlwaysIncludeUserClaimsInIdToken, |
|||
input.RequirePkce, |
|||
input.AllowPlainTextPkce, |
|||
input.RequireRequestObject, |
|||
input.AllowAccessTokensViaBrowser, |
|||
input.FrontChannelLogoutUri, |
|||
input.FrontChannelLogoutSessionRequired, |
|||
input.BackChannelLogoutUri, |
|||
input.BackChannelLogoutSessionRequired, |
|||
input.AllowOfflineAccess, |
|||
input.IdentityTokenLifetime, |
|||
input.AllowedIdentityTokenSigningAlgorithms, |
|||
input.AccessTokenLifetime, |
|||
input.AuthorizationCodeLifetime, |
|||
input.ConsentLifetime, |
|||
input.AbsoluteRefreshTokenLifetime, |
|||
input.RefreshTokenUsage, |
|||
input.UpdateAccessTokenClaimsOnRefresh, |
|||
input.RefreshTokenExpiration, |
|||
input.AccessTokenType, |
|||
input.EnableLocalLogin, |
|||
input.IncludeJwtId, |
|||
input.AlwaysSendClientClaims, |
|||
input.ClientClaimsPrefix, |
|||
input.PairWiseSubjectSalt, |
|||
input.UserSsoLifetime, |
|||
input.UserCodeType, |
|||
input.DeviceCodeLifetime, |
|||
input.SlidingRefreshTokenLifetime |
|||
); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 更新client scopes
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
public Task UpdateScopesAsync(UpdateScopeInput input) |
|||
{ |
|||
return _idenityServerClientManager.UpdateScopesAsync(input.ClientId, input.Scopes); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 新增回调地址
|
|||
/// </summary>
|
|||
public Task AddRedirectUriAsync(AddRedirectUriInput input) |
|||
{ |
|||
return _idenityServerClientManager.AddRedirectUriAsync(input.ClientId, input.Uri); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 删除回调地址
|
|||
/// </summary>
|
|||
public Task RemoveRedirectUriAsync(RemoveRedirectUriInput input) |
|||
{ |
|||
return _idenityServerClientManager.RemoveRedirectUriAsync(input.ClientId, input.Uri); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 新增Logout回调地址
|
|||
/// </summary>
|
|||
public Task AddLogoutRedirectUriAsync(AddRedirectUriInput input) |
|||
{ |
|||
return _idenityServerClientManager.AddLogoutRedirectUriAsync(input.ClientId, input.Uri); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 删除Logout回调地址
|
|||
/// </summary>
|
|||
public Task RemoveLogoutRedirectUriAsync(RemoveRedirectUriInput input) |
|||
{ |
|||
return _idenityServerClientManager.RemoveLogoutRedirectUriAsync(input.ClientId, input.Uri); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 添加cors
|
|||
/// </summary>
|
|||
public Task AddCorsAsync(AddCorsInput input) |
|||
{ |
|||
return _idenityServerClientManager.AddCorsAsync(input.ClientId, input.Origin); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 删除cors
|
|||
/// </summary>
|
|||
public Task RemoveCorsAsync(RemoveCorsInput input) |
|||
{ |
|||
return _idenityServerClientManager.RemoveCorsAsync(input.ClientId, input.Origin); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,50 @@ |
|||
using AutoMapper; |
|||
using CompanyName.ProjectName.IdentityServers.Clients; |
|||
using CompanyName.ProjectName.IdentityServers.Dtos; |
|||
using Volo.Abp.IdentityServer.ApiResources; |
|||
using Volo.Abp.IdentityServer.ApiScopes; |
|||
using Volo.Abp.IdentityServer.Clients; |
|||
using Volo.Abp.IdentityServer.Devices; |
|||
using Volo.Abp.IdentityServer.IdentityResources; |
|||
|
|||
namespace CompanyName.ProjectName.IdentityServers.Mappers |
|||
{ |
|||
public class IdentityServerApplicationAutoMapperProfile : Profile |
|||
{ |
|||
public IdentityServerApplicationAutoMapperProfile() |
|||
{ |
|||
#region id4 model to Output
|
|||
|
|||
CreateMap<ApiResource, ApiResourceOutput>(); |
|||
CreateMap<ApiResourceClaim, ApiResourceClaimOutput>(); |
|||
CreateMap<ApiResourceProperty, ApiResourcePropertyOutput>(); |
|||
CreateMap<ApiResourceSecret, ApiResourceSecretOutput>(); |
|||
CreateMap<ApiResourceScope, ApiResourceScopeOutput>(); |
|||
|
|||
CreateMap<Client, ClientOutput>(); |
|||
CreateMap<ClientClaim, ClientClaimOutput>(); |
|||
CreateMap<ClientCorsOrigin, ClientCorsOriginOutput>(); |
|||
CreateMap<ClientGrantType, ClientGrantTypeOutput>(); |
|||
CreateMap<ClientIdPRestriction, ClientIdPRestrictionOutput>(); |
|||
CreateMap<ClientPostLogoutRedirectUri, ClientPostLogoutRedirectUriOutput>(); |
|||
CreateMap<ClientProperty, ClientPropertyOutput>(); |
|||
CreateMap<ClientRedirectUri, ClientRedirectUriOutput>(); |
|||
CreateMap<ClientScope, ClientScopeOutput>(); |
|||
CreateMap<ClientSecret, ClientSecretOutput>(); |
|||
|
|||
// CreateMap<DeviceFlowCodes, DeviceFlowCodesOutput>();
|
|||
// CreateMap<DeviceFlowCodes, DeviceFlowCodesOutput>();
|
|||
//
|
|||
// CreateMap<IdentityResourceClaim, IdentityResourceClaimOutput>();
|
|||
// CreateMap<IdentityResource, IdentityResourceOutput>();
|
|||
// CreateMap<IdentityResourceProperty, IdentityResourcePropertyOutput>();
|
|||
//
|
|||
//
|
|||
// CreateMap<ApiScope, ApiScopeOutput>();
|
|||
// CreateMap<ApiScopeClaim, ApiScopeClaimOutput>();
|
|||
// CreateMap<ApiScopeProperty, ApiScopePropertyOutput>();
|
|||
|
|||
#endregion
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using System; |
|||
|
|||
namespace CompanyName.ProjectName.IdentityServers.Dtos |
|||
{ |
|||
public class ApiResourceClaimOutput |
|||
{ |
|||
public Guid ApiResourceId { get; set; } |
|||
|
|||
public string Type { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using System; |
|||
|
|||
namespace CompanyName.ProjectName.IdentityServers.Dtos |
|||
{ |
|||
public class ApiResourcePropertyOutput |
|||
{ |
|||
public Guid ApiResourceId { get; set; } |
|||
|
|||
public string Key { get; set; } |
|||
|
|||
public string Value { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using System; |
|||
|
|||
namespace CompanyName.ProjectName.IdentityServers.Dtos |
|||
{ |
|||
public class ApiResourceScopeOutput |
|||
{ |
|||
public Guid ApiResourceId { get; set; } |
|||
|
|||
public string Scope { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
using System; |
|||
|
|||
namespace CompanyName.ProjectName.IdentityServers.Dtos |
|||
{ |
|||
public class ApiResourceSecretOutput |
|||
{ |
|||
public Guid ApiResourceId { get; set; } |
|||
|
|||
public string Type { get; set; } |
|||
|
|||
public string Value { get; set; } |
|||
|
|||
public string Description { get; set; } |
|||
|
|||
public DateTime? Expiration { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,133 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using CompanyName.ProjectName.IdentityServers.Dtos; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Domain.Services; |
|||
using Volo.Abp.IdentityServer.ApiResources; |
|||
using IdentityModel; |
|||
|
|||
namespace CompanyName.ProjectName.IdentityServer |
|||
{ |
|||
public class IdenityServerApiResourceManager : DomainService |
|||
{ |
|||
private readonly IApiResourceRepository _apiResourceRepository; |
|||
|
|||
public IdenityServerApiResourceManager(IApiResourceRepository apiResourceRepository) |
|||
{ |
|||
_apiResourceRepository = apiResourceRepository; |
|||
} |
|||
|
|||
public Task<List<ApiResource>> GetListAsync( |
|||
int skipCount, |
|||
int maxResultCount, |
|||
string filter = null, |
|||
bool includeDetails = false, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return _apiResourceRepository.GetListAsync("CreationTime", skipCount, maxResultCount, filter, |
|||
includeDetails, |
|||
cancellationToken); |
|||
} |
|||
|
|||
public Task<long> GetCountAsync(string filter = null, CancellationToken cancellationToken = default) |
|||
{ |
|||
return _apiResourceRepository.GetCountAsync(filter, |
|||
cancellationToken); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 获取所有api resource
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
public async Task<List<ApiResource>> GetResources( |
|||
bool includeDetails = false, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return await _apiResourceRepository.GetListAsync(includeDetails, cancellationToken); |
|||
} |
|||
|
|||
public async Task<ApiResource> CreateAsync( |
|||
Guid id, |
|||
string name, |
|||
string displayName, |
|||
string description, |
|||
bool enabled, |
|||
string allowedAccessTokenSigningAlgorithms, |
|||
bool showInDiscoveryDocument, |
|||
List<ApiResourceSecretOutput> secrets = null, |
|||
List<ApiResourceScopeOutput> scopes = null, |
|||
List<ApiResourceClaimOutput> claims = null, |
|||
List<ApiResourcePropertyOutput> properties = null, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var apiResource = |
|||
await _apiResourceRepository.FindByNameAsync(name.Trim(), false, cancellationToken); |
|||
if (null != apiResource) throw new UserFriendlyException(message: "ApiResource已存在"); |
|||
apiResource = new ApiResource(id, name, displayName, description) |
|||
{ |
|||
AllowedAccessTokenSigningAlgorithms = allowedAccessTokenSigningAlgorithms, |
|||
ShowInDiscoveryDocument = showInDiscoveryDocument, |
|||
Enabled = enabled |
|||
}; |
|||
|
|||
secrets?.Distinct().ToList().ForEach(item => |
|||
{ |
|||
apiResource.AddSecret(item.Value.ToSha256(), item.Expiration, item.Type, item.Description); |
|||
}); |
|||
|
|||
scopes?.Distinct().ToList().ForEach(item => { apiResource.AddScope(item.Scope); }); |
|||
|
|||
claims?.Distinct().ToList().ForEach(item => { apiResource.AddUserClaim(item.Type); }); |
|||
|
|||
properties?.Distinct().ToList().ForEach(item => { apiResource.AddProperty(item.Key, item.Value); }); |
|||
|
|||
return await _apiResourceRepository.InsertAsync(apiResource, cancellationToken: cancellationToken); |
|||
} |
|||
|
|||
public async Task DeleteAsync( |
|||
Guid id, |
|||
bool autoSave = false, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
await _apiResourceRepository.DeleteAsync(id, autoSave, cancellationToken); |
|||
} |
|||
|
|||
public async Task<ApiResource> UpdateAsync( |
|||
string name, |
|||
string displayName, |
|||
string description, |
|||
bool enabled, |
|||
string allowedAccessTokenSigningAlgorithms, |
|||
bool showInDiscoveryDocument, |
|||
List<ApiResourceSecretOutput> secrets = null, |
|||
List<ApiResourceScopeOutput> scopes = null, |
|||
List<ApiResourceClaimOutput> claims = null, |
|||
List<ApiResourcePropertyOutput> properties = null, |
|||
CancellationToken cancellationToken = default |
|||
) |
|||
{ |
|||
var apiResource = |
|||
await _apiResourceRepository.FindByNameAsync(name.Trim(), false, cancellationToken); |
|||
if (null == apiResource) throw new UserFriendlyException(message: "ApiResource不存在"); |
|||
apiResource.DisplayName = displayName; |
|||
apiResource.Description = description; |
|||
apiResource.Enabled = enabled; |
|||
apiResource.AllowedAccessTokenSigningAlgorithms = allowedAccessTokenSigningAlgorithms; |
|||
apiResource.ShowInDiscoveryDocument = showInDiscoveryDocument; |
|||
secrets?.Distinct().ToList().ForEach(item => |
|||
{ |
|||
apiResource.AddSecret(item.Value.ToSha256(), item.Expiration, item.Type, item.Description); |
|||
}); |
|||
|
|||
scopes?.Distinct().ToList().ForEach(item => { apiResource.AddScope(item.Scope); }); |
|||
|
|||
claims?.Distinct().ToList().ForEach(item => { apiResource.AddUserClaim(item.Type); }); |
|||
|
|||
properties?.Distinct().ToList().ForEach(item => { apiResource.AddProperty(item.Key, item.Value); }); |
|||
return await _apiResourceRepository.UpdateAsync(apiResource, cancellationToken: cancellationToken); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,260 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Domain.Services; |
|||
using Volo.Abp.IdentityServer.Clients; |
|||
|
|||
namespace CompanyName.ProjectName.IdentityServer |
|||
{ |
|||
public class IdenityServerClientManager : DomainService |
|||
{ |
|||
private readonly IClientRepository _clientRepository; |
|||
|
|||
public IdenityServerClientManager( |
|||
IClientRepository clientRepository) |
|||
{ |
|||
_clientRepository = clientRepository; |
|||
} |
|||
|
|||
|
|||
public Task<List<Client>> GetListAsync( |
|||
int skipCount, |
|||
int maxResultCount, |
|||
string filter = null, |
|||
bool includeDetails = false, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return _clientRepository.GetListAsync("CreationTime", skipCount, maxResultCount, filter, includeDetails, |
|||
cancellationToken); |
|||
} |
|||
|
|||
public Task<long> GetCountAsync(string filter = null, CancellationToken cancellationToken = default) |
|||
{ |
|||
return _clientRepository.GetCountAsync(filter, |
|||
cancellationToken); |
|||
} |
|||
|
|||
public Task DeleteAsync(Guid id, bool autoSave = false, CancellationToken cancellationToken = default) |
|||
{ |
|||
return _clientRepository.DeleteAsync(id, autoSave, default); |
|||
} |
|||
|
|||
public async Task<Client> CreateAsync(string clientId, string clientName, string description) |
|||
{ |
|||
var entity = new Client(GuidGenerator.Create(), clientId) |
|||
{ |
|||
ClientName = clientName, Description = description |
|||
}; |
|||
return await _clientRepository.InsertAsync(entity); |
|||
} |
|||
|
|||
public async Task<Client> UpdateBasicDataAsync( |
|||
string clientId, |
|||
string clientName, |
|||
string description, |
|||
string clientUri, |
|||
string logoUri, |
|||
bool enabled, |
|||
string protocolType, |
|||
bool requireClientSecret, |
|||
bool requireConsent, |
|||
bool allowRememberConsent, |
|||
bool alwaysIncludeUserClaimsInIdToken, |
|||
bool requirePkce, |
|||
bool allowPlainTextPkce, |
|||
bool requireRequestObject, |
|||
bool allowAccessTokensViaBrowser, |
|||
string frontChannelLogoutUri, |
|||
bool frontChannelLogoutSessionRequired, |
|||
string backChannelLogoutUri, |
|||
bool backChannelLogoutSessionRequired, |
|||
bool allowOfflineAccess, |
|||
int identityTokenLifetime, |
|||
string allowedIdentityTokenSigningAlgorithms, |
|||
int accessTokenLifetime, |
|||
int authorizationCodeLifetime, |
|||
int? consentLifetime, |
|||
int absoluteRefreshTokenLifetime, |
|||
int refreshTokenUsage, |
|||
bool updateAccessTokenClaimsOnRefresh, |
|||
int refreshTokenExpiration, |
|||
int accessTokenType, |
|||
bool enableLocalLogin, |
|||
bool includeJwtId, |
|||
bool alwaysSendClientClaims, |
|||
string clientClaimsPrefix, |
|||
string pairWiseSubjectSalt, |
|||
int? userSsoLifetime, |
|||
string userCodeType, |
|||
int deviceCodeLifetime, |
|||
int slidingRefreshTokenLifetime |
|||
) |
|||
{ |
|||
var client = await _clientRepository.FindByClientIdAsync(clientId); |
|||
if (client != null) |
|||
{ |
|||
throw new UserFriendlyException(message: "当前ClientId已存在"); |
|||
} |
|||
|
|||
client.ClientName = clientName; |
|||
client.Description = description; |
|||
client.ClientUri = clientUri; |
|||
client.LogoUri = logoUri; |
|||
client.FrontChannelLogoutUri = frontChannelLogoutUri; |
|||
client.BackChannelLogoutUri = backChannelLogoutUri; |
|||
client.AllowedIdentityTokenSigningAlgorithms = allowedIdentityTokenSigningAlgorithms; |
|||
client.Enabled = enabled; |
|||
client.RequireConsent = requireConsent; |
|||
client.RequireRequestObject = requireRequestObject; |
|||
client.AllowRememberConsent = allowRememberConsent; |
|||
client.AllowOfflineAccess = allowOfflineAccess; |
|||
client.FrontChannelLogoutSessionRequired = frontChannelLogoutSessionRequired; |
|||
client.BackChannelLogoutSessionRequired = backChannelLogoutSessionRequired; |
|||
client.IncludeJwtId = includeJwtId; |
|||
client.RequirePkce = requirePkce; |
|||
client.RequireClientSecret = requireClientSecret; |
|||
client.AccessTokenLifetime = accessTokenLifetime; |
|||
client.ConsentLifetime = consentLifetime; |
|||
client.IdentityTokenLifetime = identityTokenLifetime; |
|||
client.AuthorizationCodeLifetime = authorizationCodeLifetime; |
|||
client.AbsoluteRefreshTokenLifetime = absoluteRefreshTokenLifetime; |
|||
client.SlidingRefreshTokenLifetime = slidingRefreshTokenLifetime; |
|||
client.RefreshTokenExpiration = refreshTokenExpiration; |
|||
client.DeviceCodeLifetime = deviceCodeLifetime; |
|||
client.ProtocolType = protocolType; |
|||
client.AlwaysIncludeUserClaimsInIdToken = alwaysIncludeUserClaimsInIdToken; |
|||
client.AllowPlainTextPkce = allowPlainTextPkce; |
|||
client.AllowOfflineAccess = allowOfflineAccess; |
|||
client.AllowAccessTokensViaBrowser = allowAccessTokensViaBrowser; |
|||
client.RefreshTokenUsage = refreshTokenUsage; |
|||
client.UpdateAccessTokenClaimsOnRefresh = updateAccessTokenClaimsOnRefresh; |
|||
client.AccessTokenType = accessTokenType; |
|||
client.AlwaysSendClientClaims = alwaysSendClientClaims; |
|||
client.ClientClaimsPrefix = clientClaimsPrefix; |
|||
client.PairWiseSubjectSalt = pairWiseSubjectSalt; |
|||
client.UserSsoLifetime = userSsoLifetime; |
|||
client.UserCodeType = userCodeType; |
|||
client.EnableLocalLogin = enableLocalLogin; |
|||
return await _clientRepository.UpdateAsync(client); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 更新client scopes
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
public async Task<Client> UpdateScopesAsync(string clientId, List<string> scopes) |
|||
{ |
|||
var client = await _clientRepository.FindByClientIdAsync(clientId); |
|||
if (client == null) throw new UserFriendlyException(message: "Client不存在"); |
|||
client.RemoveAllScopes(); |
|||
scopes.ForEach(item => { client.AddScope(item.Trim()); }); |
|||
|
|||
return await _clientRepository.UpdateAsync(client); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 新增回调地址
|
|||
/// </summary>
|
|||
public async Task<Client> AddRedirectUriAsync(string clientId, string uri) |
|||
{ |
|||
uri = uri.Trim(); |
|||
var client = await _clientRepository.FindByClientIdAsync(clientId); |
|||
if (client == null) throw new UserFriendlyException(message: "Client不存在"); |
|||
if (client.RedirectUris.Any(e => e.RedirectUri != uri.Trim())) |
|||
{ |
|||
client.AddRedirectUri(uri); |
|||
return await _clientRepository.UpdateAsync(client); |
|||
} |
|||
|
|||
return client; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 删除回调地址
|
|||
/// </summary>
|
|||
public async Task<Client> RemoveRedirectUriAsync(string clientId, string uri) |
|||
{ |
|||
uri = uri.Trim(); |
|||
var client = await _clientRepository.FindByClientIdAsync(clientId); |
|||
if (client == null) throw new UserFriendlyException(message: "Client不存在"); |
|||
if (client.RedirectUris.Any(e => e.RedirectUri == uri.Trim())) |
|||
{ |
|||
client.RemoveRedirectUri(uri); |
|||
return await _clientRepository.UpdateAsync(client); |
|||
} |
|||
|
|||
return client; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 新增Logout回调地址
|
|||
/// </summary>
|
|||
public async Task<Client> AddLogoutRedirectUriAsync(string clientId, string uri) |
|||
{ |
|||
uri = uri.Trim(); |
|||
var client = await _clientRepository.FindByClientIdAsync(clientId); |
|||
if (client == null) throw new UserFriendlyException(message: "Client不存在"); |
|||
if (client.PostLogoutRedirectUris.Any(e => e.PostLogoutRedirectUri != uri)) |
|||
{ |
|||
client.AddPostLogoutRedirectUri(uri); |
|||
await _clientRepository.UpdateAsync(client); |
|||
} |
|||
|
|||
return client; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 删除Logout回调地址
|
|||
/// </summary>
|
|||
public async Task<Client> RemoveLogoutRedirectUriAsync(string clientId, string uri) |
|||
{ |
|||
uri = uri.Trim(); |
|||
var client = await _clientRepository.FindByClientIdAsync(clientId); |
|||
if (client == null) throw new UserFriendlyException(message: "Client不存在"); |
|||
if (client.PostLogoutRedirectUris.Any(e => e.PostLogoutRedirectUri == uri)) |
|||
{ |
|||
client.RemovePostLogoutRedirectUri(uri); |
|||
await _clientRepository.UpdateAsync(client); |
|||
} |
|||
|
|||
return client; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 添加cors
|
|||
/// </summary>
|
|||
public async Task<Client> AddCorsAsync(string clientId, string origin) |
|||
{ |
|||
origin = origin.Trim(); |
|||
var client = await _clientRepository.FindByClientIdAsync(clientId); |
|||
if (client == null) throw new UserFriendlyException(message: "Client不存在"); |
|||
if (client.AllowedCorsOrigins.Any(e => e.Origin != origin)) |
|||
{ |
|||
client.AddCorsOrigin(origin); |
|||
return await _clientRepository.UpdateAsync(client); |
|||
} |
|||
|
|||
return client; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 删除cors
|
|||
/// </summary>
|
|||
public async Task<Client> RemoveCorsAsync(string clientId, string origin) |
|||
{ |
|||
origin = origin.Trim(); |
|||
var client = await _clientRepository.FindByClientIdAsync(clientId); |
|||
if (client == null) throw new UserFriendlyException(message: "Client不存在"); |
|||
if (client.AllowedCorsOrigins.Any(e => e.Origin == origin)) |
|||
{ |
|||
client.RemoveCorsOrigin(origin); |
|||
return await _clientRepository.UpdateAsync(client); |
|||
} |
|||
|
|||
return client; |
|||
} |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
@ -0,0 +1,59 @@ |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using CompanyName.ProjectName.IdentityServers; |
|||
using CompanyName.ProjectName.IdentityServers.Dtos; |
|||
using CompanyName.ProjectName.Publics.Dtos; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Swashbuckle.AspNetCore.Annotations; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace CompanyName.ProjectName.Controllers.IdentityServers |
|||
{ |
|||
[Route("IdentityServer/ApiResource")] |
|||
public class ApiResourceController : ProjectNameController |
|||
{ |
|||
private readonly IApiResourceAppService _apiResourceAppService; |
|||
|
|||
public ApiResourceController(IApiResourceAppService apiResourceAppService) |
|||
{ |
|||
_apiResourceAppService = apiResourceAppService; |
|||
} |
|||
|
|||
[HttpPost("page")] |
|||
[SwaggerOperation(summary: "分页获取ApiResource信息", Tags = new[] {"IdentityServers"})] |
|||
public Task<PagedResultDto<ApiResourceOutput>> GetListAsync(PagingApiRseourceListInput input) |
|||
{ |
|||
return _apiResourceAppService.GetListAsync(input); |
|||
} |
|||
|
|||
|
|||
[HttpPost("all")] |
|||
[SwaggerOperation(summary: "获取ApiResource信息", Tags = new[] {"IdentityServers"})] |
|||
public Task<List<ApiResourceOutput>> GetApiResources() |
|||
{ |
|||
return _apiResourceAppService.GetApiResources(); |
|||
} |
|||
|
|||
[HttpPost("create")] |
|||
[SwaggerOperation(summary: "新增ApiResource", Tags = new[] {"IdentityServers"})] |
|||
public Task CreateAsync(CreateApiResourceInput input) |
|||
{ |
|||
return _apiResourceAppService.CreateAsync(input); |
|||
} |
|||
|
|||
|
|||
[HttpPost("delete")] |
|||
[SwaggerOperation(summary: "删除ApiResource", Tags = new[] {"IdentityServers"})] |
|||
public async Task DeleteAsync(IdInput input) |
|||
{ |
|||
await _apiResourceAppService.DeleteAsync(input); |
|||
} |
|||
|
|||
[HttpPost("update")] |
|||
[SwaggerOperation(summary: "删除ApiResource", Tags = new[] {"IdentityServers"})] |
|||
public Task UpdateAsync(UpdateApiResourceInput input) |
|||
{ |
|||
return _apiResourceAppService.UpdateAsync(input); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,98 @@ |
|||
using System.Threading.Tasks; |
|||
using CompanyName.ProjectName.IdentityServers.Clients; |
|||
using CompanyName.ProjectName.Publics.Dtos; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Swashbuckle.AspNetCore.Annotations; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace CompanyName.ProjectName.Controllers.IdentityServers |
|||
{ |
|||
[Route("IdentityServer/Client")] |
|||
public class ClientController : ProjectNameController |
|||
{ |
|||
private readonly IIdentityServerClientAppService _identityServerClientAppService; |
|||
|
|||
public ClientController(IIdentityServerClientAppService identityServerClientAppService) |
|||
{ |
|||
_identityServerClientAppService = identityServerClientAppService; |
|||
} |
|||
|
|||
[HttpPost("page")] |
|||
[SwaggerOperation(summary: "分页获取Client信息", Tags = new[] {"IdentityServers"})] |
|||
public Task<PagedResultDto<ClientOutput>> GetListAsync(PagingClientListInput input) |
|||
{ |
|||
return _identityServerClientAppService.GetListAsync(input); |
|||
} |
|||
|
|||
|
|||
[HttpPost("create")] |
|||
[SwaggerOperation(summary: "创建Client", Tags = new[] {"IdentityServers"})] |
|||
public Task CreateAsync(CreateClientInput input) |
|||
{ |
|||
return _identityServerClientAppService.CreateAsync(input); |
|||
} |
|||
|
|||
[HttpPost("delete")] |
|||
[SwaggerOperation(summary: "删除client", Tags = new[] {"IdentityServers"})] |
|||
public Task DeleteAsync(IdInput input) |
|||
{ |
|||
return _identityServerClientAppService.DeleteAsync(input); |
|||
} |
|||
|
|||
[HttpPost("basic/update")] |
|||
[SwaggerOperation(summary: "更新基本信息", Tags = new[] {"IdentityServers"})] |
|||
public Task UpdateBasicDataAsync(UpdataBasicDataInput input) |
|||
{ |
|||
return _identityServerClientAppService.UpdateBasicDataAsync(input); |
|||
} |
|||
|
|||
[HttpPost("scopes/update")] |
|||
[SwaggerOperation(summary: "更新client scopes", Tags = new[] {"IdentityServers"})] |
|||
public Task UpdateScopesAsync(UpdateScopeInput input) |
|||
{ |
|||
return _identityServerClientAppService.UpdateScopesAsync(input); |
|||
} |
|||
|
|||
[HttpPost("redirect/uri/add")] |
|||
[SwaggerOperation(summary: "新增回调地址", Tags = new[] {"IdentityServers"})] |
|||
public Task AddRedirectUriAsync(AddRedirectUriInput input) |
|||
{ |
|||
return _identityServerClientAppService.AddRedirectUriAsync(input); |
|||
} |
|||
|
|||
[HttpPost("redirect/uri/remove")] |
|||
[SwaggerOperation(summary: "删除回调地址", Tags = new[] {"IdentityServers"})] |
|||
public Task RemoveRedirectUriAsync(RemoveRedirectUriInput input) |
|||
{ |
|||
return _identityServerClientAppService.RemoveRedirectUriAsync(input); |
|||
} |
|||
|
|||
[HttpPost("logout/redirect/uri/add")] |
|||
[SwaggerOperation(summary: "新增Logout回调地址", Tags = new[] {"IdentityServers"})] |
|||
public Task AddLogoutRedirectUriAsync(AddRedirectUriInput input) |
|||
{ |
|||
return _identityServerClientAppService.AddLogoutRedirectUriAsync(input); |
|||
} |
|||
|
|||
[HttpPost("logout/redirect/uri/remove")] |
|||
[SwaggerOperation(summary: "删除Logout回调地址", Tags = new[] {"IdentityServers"})] |
|||
public Task RemoveLogoutRedirectUriAsync(RemoveRedirectUriInput input) |
|||
{ |
|||
return _identityServerClientAppService.RemoveLogoutRedirectUriAsync(input); |
|||
} |
|||
|
|||
[HttpPost("cors/add")] |
|||
[SwaggerOperation(summary: "添加cors", Tags = new[] {"IdentityServers"})] |
|||
public Task AddCorsAsync(AddCorsInput input) |
|||
{ |
|||
return _identityServerClientAppService.AddCorsAsync(input); |
|||
} |
|||
|
|||
[HttpPost("cors/remove")] |
|||
[SwaggerOperation(summary: "删除cors", Tags = new[] {"IdentityServers"})] |
|||
public Task RemoveCorsAsync(RemoveCorsInput input) |
|||
{ |
|||
return _identityServerClientAppService.RemoveCorsAsync(input); |
|||
} |
|||
} |
|||
} |
|||
@ -1,11 +0,0 @@ |
|||
using System; |
|||
|
|||
namespace CompanyName.ProjectName.Models.Test |
|||
{ |
|||
public class TestModel |
|||
{ |
|||
public string Name { get; set; } |
|||
|
|||
public DateTime BirthDate { get; set; } |
|||
} |
|||
} |
|||
Loading…
Reference in new issue