pull/4578/head
maliming 5 years ago
parent cee969f7bb
commit 87e5dc4259

@ -4,9 +4,8 @@ using System.Linq;
using IdentityServer4;
using JetBrains.Annotations;
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.IdentityServer.ApiResources;
namespace Volo.Abp.IdentityServer.ApiScopes
namespace Volo.Abp.IdentityServer.ApiResources
{
public class ApiResource : FullAuditedAggregateRoot<Guid>
{

@ -1,7 +1,7 @@
using System;
using JetBrains.Annotations;
namespace Volo.Abp.IdentityServer.ApiScopes
namespace Volo.Abp.IdentityServer.ApiResources
{
public class ApiResourceClaim : UserClaim
{
@ -28,4 +28,4 @@ namespace Volo.Abp.IdentityServer.ApiScopes
return new object[] {ApiResourceId, Type};
}
}
}
}

@ -2,7 +2,7 @@
using JetBrains.Annotations;
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.IdentityServer.ApiScopes
namespace Volo.Abp.IdentityServer.ApiResources
{
public class ApiResourceScope : Entity
{

@ -2,7 +2,7 @@
using IdentityServer4;
using JetBrains.Annotations;
namespace Volo.Abp.IdentityServer.ApiScopes
namespace Volo.Abp.IdentityServer.ApiResources
{
public class ApiResourceSecret : Secret
{

@ -4,7 +4,7 @@ using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
namespace Volo.Abp.IdentityServer.ApiScopes
namespace Volo.Abp.IdentityServer.ApiResources
{
public interface IApiResourceRepository : IBasicRepository<ApiResource, Guid>
{

@ -3,6 +3,7 @@ using System.Linq;
using System.Threading.Tasks;
using IdentityServer4.Models;
using IdentityServer4.Stores;
using Volo.Abp.IdentityServer.ApiResources;
using Volo.Abp.IdentityServer.ApiScopes;
using Volo.Abp.IdentityServer.IdentityResources;
using Volo.Abp.ObjectMapping;
@ -52,7 +53,7 @@ namespace Volo.Abp.IdentityServer
public virtual async Task<IEnumerable<IdentityServer4.Models.ApiResource>> FindApiResourcesByScopeNameAsync(IEnumerable<string> scopeNames)
{
var resources = await ApiResourceRepository.GetListByScopesAsync(scopeNames.ToArray(), includeDetails: true);
return ObjectMapper.Map<List<Volo.Abp.IdentityServer.ApiScopes.ApiResource>, List<IdentityServer4.Models.ApiResource>>(resources);
return ObjectMapper.Map<List<Volo.Abp.IdentityServer.ApiResources.ApiResource>, List<IdentityServer4.Models.ApiResource>>(resources);
}
/// <summary>
@ -61,7 +62,7 @@ namespace Volo.Abp.IdentityServer
public virtual async Task<IEnumerable<IdentityServer4.Models.ApiResource>> FindApiResourcesByNameAsync(IEnumerable<string> apiResourceNames)
{
var resources = await ApiResourceRepository.FindByNameAsync(apiResourceNames.ToArray(), includeDetails: true);
return ObjectMapper.Map<List<Volo.Abp.IdentityServer.ApiScopes.ApiResource>, List<IdentityServer4.Models.ApiResource>>(resources);
return ObjectMapper.Map<List<Volo.Abp.IdentityServer.ApiResources.ApiResource>, List<IdentityServer4.Models.ApiResource>>(resources);
}
/// <summary>
@ -75,7 +76,7 @@ namespace Volo.Abp.IdentityServer
return new Resources(
ObjectMapper.Map<List<Volo.Abp.IdentityServer.IdentityResources.IdentityResource>, List<IdentityServer4.Models.IdentityResource>>(identityResources),
ObjectMapper.Map<List<Volo.Abp.IdentityServer.ApiScopes.ApiResource>, List<IdentityServer4.Models.ApiResource>>(apiResources),
ObjectMapper.Map<List<Volo.Abp.IdentityServer.ApiResources.ApiResource>, List<IdentityServer4.Models.ApiResource>>(apiResources),
ObjectMapper.Map<List<Volo.Abp.IdentityServer.ApiScopes.ApiScope>, List<IdentityServer4.Models.ApiScope>>(apiScopes));
}
}

@ -1,5 +1,6 @@
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.IdentityServer.ApiResources;
using Volo.Abp.IdentityServer.ApiScopes;
using Volo.Abp.IdentityServer.Clients;
using Volo.Abp.IdentityServer.IdentityResources;

@ -1,16 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.IdentityServer.EntityFrameworkCore;
using System.Linq.Dynamic.Core;
using System.Runtime.InteropServices.ComTypes;
namespace Volo.Abp.IdentityServer.ApiScopes
namespace Volo.Abp.IdentityServer.ApiResources
{
public class ApiResourceRepository : EfCoreRepository<IIdentityServerDbContext, ApiResource, Guid>, IApiResourceRepository
{

@ -1,5 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.IdentityServer.ApiResources;
using Volo.Abp.IdentityServer.ApiScopes;
using Volo.Abp.IdentityServer.Clients;
using Volo.Abp.IdentityServer.Devices;

@ -8,11 +8,6 @@ using Volo.Abp.IdentityServer.Clients;
using Volo.Abp.IdentityServer.Devices;
using Volo.Abp.IdentityServer.Grants;
using Volo.Abp.IdentityServer.IdentityResources;
using ApiResource = Volo.Abp.IdentityServer.ApiScopes.ApiResource;
using Client = Volo.Abp.IdentityServer.Clients.Client;
using ClientClaim = Volo.Abp.IdentityServer.Clients.ClientClaim;
using IdentityResource = Volo.Abp.IdentityServer.IdentityResources.IdentityResource;
using PersistedGrant = Volo.Abp.IdentityServer.Grants.PersistedGrant;
namespace Volo.Abp.IdentityServer.EntityFrameworkCore
{

@ -1,5 +1,6 @@
using MongoDB.Driver;
using Volo.Abp.Data;
using Volo.Abp.IdentityServer.ApiResources;
using Volo.Abp.IdentityServer.ApiScopes;
using Volo.Abp.IdentityServer.Clients;
using Volo.Abp.IdentityServer.Devices;

@ -1,4 +1,5 @@
using System;
using Volo.Abp.IdentityServer.ApiResources;
using Volo.Abp.IdentityServer.ApiScopes;
using Volo.Abp.IdentityServer.Clients;
using Volo.Abp.IdentityServer.Devices;

@ -1,4 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.IdentityServer.ApiResources;
using Volo.Abp.IdentityServer.ApiScopes;
using Volo.Abp.IdentityServer.Clients;
using Volo.Abp.IdentityServer.Devices;

@ -1,12 +1,12 @@
using MongoDB.Driver;
using Volo.Abp.Data;
using Volo.Abp.IdentityServer.ApiResources;
using Volo.Abp.IdentityServer.ApiScopes;
using Volo.Abp.IdentityServer.Clients;
using Volo.Abp.IdentityServer.Devices;
using Volo.Abp.IdentityServer.Grants;
using Volo.Abp.IdentityServer.IdentityResources;
using Volo.Abp.MongoDB;
using ApiResource = Volo.Abp.IdentityServer.ApiScopes.ApiResource;
namespace Volo.Abp.IdentityServer.MongoDB
{

@ -8,6 +8,7 @@ using MongoDB.Driver.Linq;
using Volo.Abp.Domain.Repositories.MongoDB;
using Volo.Abp.IdentityServer.ApiScopes;
using System.Linq.Dynamic.Core;
using Volo.Abp.IdentityServer.ApiResources;
using Volo.Abp.MongoDB;
namespace Volo.Abp.IdentityServer.MongoDB

@ -33,7 +33,7 @@ namespace Volo.Abp.IdentityServer.Clients
client.ClientId.ShouldBe("42");
client.ProtocolType.ShouldBe("TestProtocol-42");
client.AllowedCorsOrigins.ShouldContain("Origin1");
client.AllowedScopes.ShouldContain("api1");
client.AllowedScopes.ShouldContain("Test-ApiScope-Name-1");
}
}
}

@ -2,11 +2,13 @@
using IdentityServer4.Models;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Guids;
using Volo.Abp.IdentityServer.ApiResources;
using Volo.Abp.IdentityServer.ApiScopes;
using Volo.Abp.IdentityServer.Clients;
using Volo.Abp.IdentityServer.Grants;
using Volo.Abp.IdentityServer.IdentityResources;
using ApiResource = Volo.Abp.IdentityServer.ApiScopes.ApiResource;
using ApiResource = Volo.Abp.IdentityServer.ApiResources.ApiResource;
using ApiScope = Volo.Abp.IdentityServer.ApiScopes.ApiScope;
using Client = Volo.Abp.IdentityServer.Clients.Client;
using IdentityResource = Volo.Abp.IdentityServer.IdentityResources.IdentityResource;
using PersistedGrant = Volo.Abp.IdentityServer.Grants.PersistedGrant;
@ -21,6 +23,7 @@ namespace Volo.Abp.IdentityServer
private readonly IClientRepository _clientRepository;
private readonly IPersistentGrantRepository _persistentGrantRepository;
private readonly IApiResourceRepository _apiResourceRepository;
private readonly IApiScopeRepository _apiScopeRepository;
private readonly IIdentityResourceRepository _identityResourceRepository;
public AbpIdentityServerTestDataBuilder(
@ -28,21 +31,64 @@ namespace Volo.Abp.IdentityServer
IGuidGenerator guidGenerator,
IPersistentGrantRepository persistentGrantRepository,
IApiResourceRepository apiResourceRepository,
IIdentityResourceRepository identityResourceRepository)
IIdentityResourceRepository identityResourceRepository,
IApiScopeRepository apiScopeRepository)
{
_clientRepository = clientRepository;
_guidGenerator = guidGenerator;
_persistentGrantRepository = persistentGrantRepository;
_apiResourceRepository = apiResourceRepository;
_identityResourceRepository = identityResourceRepository;
_apiScopeRepository = apiScopeRepository;
}
public async Task BuildAsync()
{
await AddClients();
await AddPersistentGrants();
await AddApiResources();
await AddApiScopes();
await AddIdentityResources();
await AddClients();
await AddPersistentGrants();
}
private async Task AddApiResources()
{
var apiResource = new ApiResource(_guidGenerator.Create(), "Test-ApiResource-Name-1")
{
Enabled = true,
Description = "Test-ApiResource-Description-1",
DisplayName = "Test-ApiResource-DisplayName-1"
};
apiResource.AddSecret("secret".Sha256());
apiResource.AddScope("Test-ApiResource-ApiScope-Name-1");
apiResource.AddScope("Test-ApiResource-ApiScope-DisplayName-1");
apiResource.AddUserClaim("Test-ApiResource-Claim-Type-1");
await _apiResourceRepository.InsertAsync(apiResource);
}
private async Task AddApiScopes()
{
var apiScope = new ApiScope(_guidGenerator.Create(), "Test-ApiScope-Name-1");
apiScope.AddUserClaim("Test-ApiScope-Claim-Type-1");
await _apiScopeRepository.InsertAsync(apiScope);
}
private async Task AddIdentityResources()
{
var identityResource = new IdentityResource(_guidGenerator.Create(), "Test-Identity-Resource-Name-1")
{
Description = "Test-Identity-Resource-Description-1",
DisplayName = "Test-Identity-Resource-DisplayName-1",
Required = true,
Emphasize = true
};
identityResource.AddUserClaim("Test-Identity-Resource-1-IdentityClaim-Type-1");
await _identityResourceRepository.InsertAsync(identityResource);
}
private async Task AddClients()
@ -54,7 +100,7 @@ namespace Volo.Abp.IdentityServer
client42.AddCorsOrigin("Origin1");
client42.AddScope("api1");
client42.AddScope("Test-ApiScope-Name-1");
await _clientRepository.InsertAsync(client42);
}
@ -98,36 +144,5 @@ namespace Volo.Abp.IdentityServer
});
}
private async Task AddApiResources()
{
var apiResource = new ApiResource(_guidGenerator.Create(), "Test-ApiResource-Name-1")
{
Enabled = true,
Description = "Test-ApiResource-Description-1",
DisplayName = "Test-ApiResource-DisplayName-1"
};
apiResource.AddSecret("secret".Sha256());
apiResource.AddScope("Test-ApiResource-ApiScope-Name-1");
apiResource.AddScope("Test-ApiResource-ApiScope-DisplayName-1");
apiResource.AddUserClaim("Test-ApiResource-Claim-Type-1");
await _apiResourceRepository.InsertAsync(apiResource);
}
private async Task AddIdentityResources()
{
var identityResource = new IdentityResource(_guidGenerator.Create(), "Test-Identity-Resource-Name-1")
{
Description = "Test-Identity-Resource-Description-1",
DisplayName = "Test-Identity-Resource-DisplayName-1",
Required = true,
Emphasize = true
};
identityResource.AddUserClaim("Test-Identity-Resource-1-IdentityClaim-Type-1");
await _identityResourceRepository.InsertAsync(identityResource);
}
}
}

@ -4,6 +4,7 @@ using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Guids;
using Volo.Abp.Identity;
using Volo.Abp.IdentityServer.ApiResources;
using Volo.Abp.IdentityServer.ApiScopes;
using Volo.Abp.IdentityServer.Clients;
using Volo.Abp.IdentityServer.Devices;

@ -1,6 +1,7 @@
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Volo.Abp.IdentityServer.ApiResources;
using Volo.Abp.IdentityServer.ApiScopes;
using Volo.Abp.Modularity;
using Xunit;

@ -8,11 +8,12 @@ using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Guids;
using Volo.Abp.IdentityServer.ApiScopes;
using Volo.Abp.IdentityServer.ApiResources;
using Volo.Abp.IdentityServer.Clients;
using Volo.Abp.IdentityServer.IdentityResources;
using Volo.Abp.PermissionManagement;
using Volo.Abp.Uow;
using ApiResource = Volo.Abp.IdentityServer.ApiScopes.ApiResource;
using ApiResource = Volo.Abp.IdentityServer.ApiResources.ApiResource;
using ApiScope = Volo.Abp.IdentityServer.ApiScopes.ApiScope;
using Client = Volo.Abp.IdentityServer.Clients.Client;

@ -8,11 +8,12 @@ using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Guids;
using Volo.Abp.IdentityServer.ApiScopes;
using Volo.Abp.IdentityServer.ApiResources;
using Volo.Abp.IdentityServer.Clients;
using Volo.Abp.IdentityServer.IdentityResources;
using Volo.Abp.PermissionManagement;
using Volo.Abp.Uow;
using ApiResource = Volo.Abp.IdentityServer.ApiScopes.ApiResource;
using ApiResource = Volo.Abp.IdentityServer.ApiResources.ApiResource;
using ApiScope = Volo.Abp.IdentityServer.ApiScopes.ApiScope;
using Client = Volo.Abp.IdentityServer.Clients.Client;
@ -142,14 +143,14 @@ namespace MyCompanyName.MyProjectName.IdentityServer
}
//Console Test Client
var consoleClientId = configurationSection["MyProjectName_App:ClientId"];
var consoleClientId = configurationSection["MyProjectName_ConsoleTestApp:ClientId"];
if (!consoleClientId.IsNullOrWhiteSpace())
{
await CreateClientAsync(
name: consoleClientId,
scopes: commonScopes,
grantTypes: new[] {"password", "client_credentials"},
secret: (configurationSection["MyProjectName_App:ClientSecret"] ?? "1q2w3e*").Sha256()
secret: (configurationSection["MyProjectName_ConsoleTestApp:ClientSecret"] ?? "1q2w3e*").Sha256()
);
}
}

Loading…
Cancel
Save