Skip to content

Commit

Permalink
修改API资源
Browse files Browse the repository at this point in the history
  • Loading branch information
lurudong committed Jan 23, 2021
1 parent 934ee44 commit 3c825b4
Show file tree
Hide file tree
Showing 16 changed files with 917 additions and 412 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using Destiny.Core.Flow.AspNetCore.Api;
using Destiny.Core.Flow.Audit;
using Destiny.Core.Flow.IServices.IdentityServer4;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using Destiny.Core.Flow.AspNetCore.Ui;
using Destiny.Core.Flow.Dtos.IdentityServer4;

namespace Destiny.Core.Flow.API.Controllers.IdentityServer4
{
Expand All @@ -16,6 +19,23 @@ namespace Destiny.Core.Flow.API.Controllers.IdentityServer4
public class ApiResourceController : ApiControllerBase
{

private readonly IApiResourceService _apiResourceService = null;

public ApiResourceController(IApiResourceService apiResourceService)
{

_apiResourceService = apiResourceService;
}

/// <summary>
/// 异步创建Api资源
/// </summary>
/// <param name="dto"></param>
/// <returns></returns>
[Description("创建Api资源")]
[HttpPost]
public async Task<AjaxResult> CreateApiResourceAsync([FromBody] ApiResourceInputDto dto)
{ return (await _apiResourceService.CreateApiResourceAsync(dto)).ToAjaxResult();
}
}
}
7 changes: 7 additions & 0 deletions src/Destiny.Core.Flow.API/Destiny.Core.Flow.API.xml

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
Expand Up @@ -52,7 +52,7 @@ public class ApiResourceInputBase:IDto<Guid>
/// <summary>
/// Api秘钥
/// </summary>
public ICollection<string> ApiSecrets { get; set; }
public ICollection<ApiResourceSecretDto> ApiSecrets { get; set; }

/// <summary>
/// 范围
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ namespace Destiny.Core.Flow.Dtos.IdentityServer4
public class ApiResourceInputDto: ApiResourceInputBase, IInputDto<Guid>
{


public ICollection<string> AllowedAccessTokenSigningAlgorithms
{
get;
set;
} = new HashSet<string>();

}
}
65 changes: 65 additions & 0 deletions src/Destiny.Core.Flow.DTOs/IdentityServer4/ApiResourceSecretDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using Destiny.Core.Flow.Extensions;
using System;
using System.Collections.Generic;
using System.Text;

namespace Destiny.Core.Flow.Dtos.IdentityServer4
{
public class ApiResourceSecretDto
{

public string Description
{
get;
set;
}


public string Value
{
get;
set;
}


public DateTime? Expiration
{
get;
set;
}


public string Type
{
get;
set;
}


public ApiResourceSecretDto()
{
Type = "SharedSecret";
Value = this.Value.Sha256();
}




//public ApiResourceSecretDto(string value, DateTime? expiration = null)
// : this()
//{
// Value = value;
// Expiration = expiration;
//}



//public ApiResourceSecretDto(string value, string description, DateTime? expiration = null)
// : this()
//{
// Description = description;
// Value = value;
// Expiration = expiration;
//}
}
}
14 changes: 14 additions & 0 deletions src/Destiny.Core.Flow.DTOs/IdentityServer4/ApiScopeClaimDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Destiny.Core.Flow.Entity;
using System;
using System.Collections.Generic;
using System.Text;

namespace Destiny.Core.Flow.Dtos.IdentityServer4
{
public class ApiScopeClaimDto : IDto<Guid>
{
public Guid Id { get; set; }


}
}
97 changes: 97 additions & 0 deletions src/Destiny.Core.Flow.DTOs/IdentityServer4/ApiScopeDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using Destiny.Core.Flow.Entity;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;

namespace Destiny.Core.Flow.Dtos.IdentityServer4
{
public class ApiScopeDto : IDto<Guid>
{
public Guid Id { get; set; }


//
// 摘要:
// Indicates if this resource is enabled. Defaults to true.
public bool Enabled
{
get;
set;
} = true;


//
// 摘要:
// The unique name of the resource.
public string Name
{
get;
set;
}

//
// 摘要:
// Display name of the resource.
public string DisplayName
{
get;
set;
}

//
// 摘要:
// Description of the resource.
public string Description
{
get;
set;
}

//
// 摘要:
// Specifies whether this scope is shown in the discovery document. Defaults to
// true.
public bool ShowInDiscoveryDocument
{
get;
set;
} = true;


//
// 摘要:
// List of associated user claims that should be included when this resource is
// requested.
public ICollection<string> UserClaims
{
get;
set;
} = new HashSet<string>();


//
// 摘要:
// Gets or sets the custom properties for the resource.
//
// 值:
// The properties.
public IDictionary<string, string> Properties
{
get;
set;
} = new Dictionary<string, string>();

/// <summary>
/// 是否必须
/// </summary>
[Description("是否必须")]
public bool Required { get; set; }

/// <summary>
/// 是否强调显示
/// </summary>
[Description("是否强调显示")]
public bool Emphasize { get; set; }
}
}
16 changes: 16 additions & 0 deletions src/Destiny.Core.Flow.DTOs/IdentityServer4/ApiScopePropertyDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Destiny.Core.Flow.Entity;
using System;
using System.Collections.Generic;
using System.Text;

namespace Destiny.Core.Flow.Dtos.IdentityServer4
{
public class ApiScopePropertyDto : IDto<Guid>
{
public Guid Id { get; set; }

public string Key { get; set; }

public string Name { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using AutoMapper;
using Destiny.Core.Flow.Dtos.PlatformApplication;
using Destiny.Core.Flow.Extensions;
using Destiny.Core.Flow.Model.DestinyIdentityServer4;
using IdentityModel;
using System;
using System.Collections.Generic;
using System.Text;

namespace Destiny.Core.Flow.Dtos.IdentityServer4.Profiles
{
/// <summary>
/// 资源APIProfile
/// </summary>
public class ApiResourceProfile : Profile
{

public ApiResourceProfile()
{


CreateMap<ApiResourceProperty, KeyValuePair<string, string>>()
.ReverseMap();

CreateMap<ApiResource, ApiResourceInputDto>(MemberList.Destination)
.ConstructUsing(src => new ApiResourceInputDto())
.ForMember(x => x.ApiSecrets, opts => opts.MapFrom(x => x.Secrets))
.ForMember(x => x.AllowedAccessTokenSigningAlgorithms, opts => opts.ConvertUsing(AllowedSigningAlgorithmsConverter.Converter, x => x.AllowedAccessTokenSigningAlgorithms))
.ReverseMap()
.ForMember(x => x.AllowedAccessTokenSigningAlgorithms, opts => opts.ConvertUsing(AllowedSigningAlgorithmsConverter.Converter, x => x.AllowedAccessTokenSigningAlgorithms));


CreateMap<ApiResourceSecret, ApiResourceSecretDto>(MemberList.Destination)
.ForMember(dest => dest.Type, opt => opt.Condition(srs => srs != null))
.ReverseMap();

CreateMap<ApiResourceClaim, string>()
.ConstructUsing(x => x.Type)
.ReverseMap()
.ForMember(dest => dest.Type, opt => opt.MapFrom(src => src));


CreateMap<ApiResourceScope, string>()
.ConstructUsing(x => x.Scope)
.ReverseMap()
.ForMember(dest => dest.Scope, opt => opt.MapFrom(src => src));


}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using AutoMapper;
using Destiny.Core.Flow.Model.DestinyIdentityServer4;
using System.Collections.Generic;
using System.Linq;

namespace Destiny.Core.Flow.Dtos.IdentityServer4.Profiles
{
public class ApiScopeMapperProfile : Profile
{
/// <summary>
/// <see cref="ApiScopeMapperProfile"/>
/// </summary>
public ApiScopeMapperProfile()
{
CreateMap<ApiScopeProperty, KeyValuePair<string, string>>()
.ReverseMap();

CreateMap<ApiScopeClaim, string>()
.ConstructUsing(x => x.Type)
.ReverseMap()
.ForMember(dest => dest.Type, opt => opt.MapFrom(src => src));

CreateMap<ApiScope, ApiScopeDto>(MemberList.Destination)
.ConstructUsing(src => new ApiScopeDto())
.ForMember(x => x.Properties, opts => opts.MapFrom(x => x.Properties))
.ForMember(x => x.UserClaims, opts => opts.MapFrom(x => x.UserClaims))
.ReverseMap();
}
}
}

This file was deleted.

19 changes: 19 additions & 0 deletions src/Destiny.Core.Flow.DTOs/IdentityServer4/UserClaimDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Destiny.Core.Flow.Entity;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;

namespace Destiny.Core.Flow.Dtos.IdentityServer4
{
public class UserClaimDto : IDto<Guid>
{
public Guid Id { get; set; }

/// <summary>
/// 类型
/// </summary>
[DisplayName("类型")]
public string Type { get; set; }
}
}
Loading

0 comments on commit 3c825b4

Please sign in to comment.