This repository has been archived by the owner on Jul 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d950f0f
commit 2191d30
Showing
4 changed files
with
150 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
test/IdentityServer.IntegrationTests/Clients/CustomTokenRequestValidatorClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
|
||
|
||
using FluentAssertions; | ||
using IdentityModel; | ||
using IdentityModel.Client; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.TestHost; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace IdentityServer4.IntegrationTests.Clients | ||
{ | ||
public class CustomTokenRequestValidatorClient | ||
{ | ||
private const string TokenEndpoint = "https://server/connect/token"; | ||
|
||
private readonly HttpClient _client; | ||
private readonly HttpMessageHandler _handler; | ||
|
||
public CustomTokenRequestValidatorClient() | ||
{ | ||
var val = new TestCustomTokenRequestValidator(); | ||
Startup.CustomTokenRequestValidator = val; | ||
|
||
var builder = new WebHostBuilder() | ||
.UseStartup<Startup>(); | ||
var server = new TestServer(builder); | ||
|
||
_handler = server.CreateHandler(); | ||
_client = server.CreateClient(); | ||
} | ||
|
||
[Fact] | ||
public async Task client_credentials_request_should_contain_custom_response() | ||
{ | ||
var client = new TokenClient( | ||
TokenEndpoint, | ||
"client", | ||
"secret", | ||
innerHttpMessageHandler: _handler); | ||
|
||
var response = await client.RequestClientCredentialsAsync("api1"); | ||
|
||
var fields = GetFields(response); | ||
fields.Should().Contain("custom", "custom"); | ||
} | ||
|
||
[Fact] | ||
public async Task resource_owner_credentials_request_should_contain_custom_response() | ||
{ | ||
var client = new TokenClient( | ||
TokenEndpoint, | ||
"roclient", | ||
"secret", | ||
innerHttpMessageHandler: _handler); | ||
|
||
var response = await client.RequestResourceOwnerPasswordAsync("bob", "bob", "api1"); | ||
|
||
var fields = GetFields(response); | ||
fields.Should().Contain("custom", "custom"); | ||
} | ||
|
||
[Fact] | ||
public async Task refreshing_a_token_should_contain_custom_response() | ||
{ | ||
var client = new TokenClient( | ||
TokenEndpoint, | ||
"roclient", | ||
"secret", | ||
innerHttpMessageHandler: _handler); | ||
|
||
var response = await client.RequestResourceOwnerPasswordAsync("bob", "bob", "api1 offline_access"); | ||
response = await client.RequestRefreshTokenAsync(response.RefreshToken); | ||
|
||
var fields = GetFields(response); | ||
fields.Should().Contain("custom", "custom"); | ||
} | ||
|
||
[Fact] | ||
public async Task extension_grant_request_should_contain_custom_response() | ||
{ | ||
var client = new TokenClient( | ||
TokenEndpoint, | ||
"client.custom", | ||
"secret", | ||
innerHttpMessageHandler: _handler); | ||
|
||
var customParameters = new Dictionary<string, string> | ||
{ | ||
{ "custom_credential", "custom credential"} | ||
}; | ||
|
||
var response = await client.RequestCustomGrantAsync("custom", "api1", customParameters); | ||
|
||
var fields = GetFields(response); | ||
fields.Should().Contain("custom", "custom"); | ||
} | ||
|
||
private Dictionary<string, object> GetFields(TokenResponse response) | ||
{ | ||
return response.Json.ToObject<Dictionary<string, object>>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
test/IdentityServer.IntegrationTests/Clients/Setup/TestCustomTokenRequestValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
|
||
|
||
using IdentityServer4.Validation; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace IdentityServer4.IntegrationTests.Clients | ||
{ | ||
public class TestCustomTokenRequestValidator : ICustomTokenRequestValidator | ||
{ | ||
public Task ValidateAsync(CustomTokenRequestValidationContext context) | ||
{ | ||
context.Result.CustomResponse = new Dictionary<string, object> | ||
{ | ||
{"custom", "custom" } | ||
}; | ||
|
||
return Task.CompletedTask; | ||
} | ||
} | ||
} |