mirror of https://github.com/abpframework/abp.git
committed by
GitHub
5 changed files with 95 additions and 5 deletions
@ -0,0 +1,25 @@ |
|||||
|
using System; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using IdentityServer4.Configuration; |
||||
|
using IdentityServer4.Validation; |
||||
|
|
||||
|
namespace Volo.Abp.IdentityServer |
||||
|
{ |
||||
|
public class AbpClientConfigurationValidator : DefaultClientConfigurationValidator |
||||
|
{ |
||||
|
public AbpClientConfigurationValidator(IdentityServerOptions options) |
||||
|
: base(options) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
protected override Task ValidateAllowedCorsOriginsAsync(ClientConfigurationValidationContext context) |
||||
|
{ |
||||
|
context.Client.AllowedCorsOrigins = context.Client |
||||
|
.AllowedCorsOrigins.Select(x => x.Replace("{0}.", string.Empty, StringComparison.OrdinalIgnoreCase)) |
||||
|
.ToHashSet(); |
||||
|
|
||||
|
return base.ValidateAllowedCorsOriginsAsync(context); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,52 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Threading.Tasks; |
||||
|
using IdentityServer4.Models; |
||||
|
using IdentityServer4.Validation; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Shouldly; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Volo.Abp.IdentityServer |
||||
|
{ |
||||
|
public class AbpClientConfigurationValidator_Tests : AbpIdentityServerTestBase |
||||
|
{ |
||||
|
private readonly IClientConfigurationValidator _abpClientConfigurationValidator; |
||||
|
|
||||
|
private readonly Client _testClient = new Client |
||||
|
{ |
||||
|
AllowedGrantTypes = GrantTypes.Code, |
||||
|
|
||||
|
ClientSecrets = new List<IdentityServer4.Models.Secret>() |
||||
|
{ |
||||
|
new IdentityServer4.Models.Secret("1q2w3e*") |
||||
|
}, |
||||
|
|
||||
|
RedirectUris = new List<string> |
||||
|
{ |
||||
|
"https://{0}.api.abp.io:8080", |
||||
|
"http://{0}.ng.abp.io", |
||||
|
"http://ng.abp.io" |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
public AbpClientConfigurationValidator_Tests() |
||||
|
{ |
||||
|
_abpClientConfigurationValidator = GetRequiredService<IClientConfigurationValidator>(); |
||||
|
} |
||||
|
|
||||
|
protected override void AfterAddApplication(IServiceCollection services) |
||||
|
{ |
||||
|
services.AddAbpClientConfigurationValidator(); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task ValidateAsync() |
||||
|
{ |
||||
|
var context = new ClientConfigurationValidationContext(_testClient); |
||||
|
|
||||
|
await _abpClientConfigurationValidator.ValidateAsync(context); |
||||
|
|
||||
|
context.IsValid.ShouldBeTrue(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue