Skip to content

Commit

Permalink
Merge pull request #980 from DuendeSoftware/brock/missing_client_id_e…
Browse files Browse the repository at this point in the history
…rror

support invalid_request when client_id is missing in client secret validator
  • Loading branch information
leastprivilege authored Jul 22, 2022
2 parents 0222403 + 44ffb33 commit 1b2eaf8
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,9 @@ private async Task<IEndpointResult> ProcessAuthenticationRequestAsync(HttpContex

// validate client
var clientResult = await _clientValidator.ValidateAsync(context);

if (clientResult.Client == null)
if (clientResult.IsError)
{
return Error(OidcConstants.BackchannelAuthenticationRequestErrors.InvalidClient);
return Error(clientResult.Error ?? OidcConstants.BackchannelAuthenticationRequestErrors.InvalidClient);
}

// validate request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private async Task<IEndpointResult> ProcessDeviceAuthorizationRequestAsync(HttpC

// validate client
var clientResult = await _clientValidator.ValidateAsync(context);
if (clientResult.Client == null) return Error(OidcConstants.TokenErrors.InvalidClient);
if (clientResult.IsError) return Error(clientResult.Error ?? OidcConstants.TokenErrors.InvalidClient);

// validate request
var form = (await context.Request.ReadFormAsync()).AsNameValueCollection();
Expand Down
5 changes: 2 additions & 3 deletions src/IdentityServer/Endpoints/TokenEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,9 @@ private async Task<IEndpointResult> ProcessTokenRequestAsync(HttpContext context

// validate client
var clientResult = await _clientValidator.ValidateAsync(context);

if (clientResult.Client == null)
if (clientResult.IsError)
{
return Error(OidcConstants.TokenErrors.InvalidClient);
return Error(clientResult.Error ?? OidcConstants.TokenErrors.InvalidClient);
}

// validate request
Expand Down
3 changes: 1 addition & 2 deletions src/IdentityServer/Endpoints/TokenRevocationEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,9 @@ private async Task<IEndpointResult> ProcessRevocationRequestAsync(HttpContext co

// validate client
var clientValidationResult = await _clientValidator.ValidateAsync(context);

if (clientValidationResult.IsError)
{
return new TokenRevocationErrorResult(OidcConstants.TokenErrors.InvalidClient);
return new TokenRevocationErrorResult(clientValidationResult.Error ?? OidcConstants.TokenErrors.InvalidClient);
}

_logger.LogTrace("Client validation successful");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public async Task<ClientSecretValidationResult> ValidateAsync(HttpContext contex

var fail = new ClientSecretValidationResult
{
IsError = true
IsError = true,
Error = IdentityModel.OidcConstants.TokenErrors.InvalidClient
};

var parsedSecret = await _parser.ParseAsync(context);
Expand All @@ -62,6 +63,8 @@ public async Task<ClientSecretValidationResult> ValidateAsync(HttpContext contex
await RaiseFailureEventAsync("unknown", "No client id found");

_logger.LogError("No client identifier found");

fail.Error = IdentityModel.OidcConstants.TokenErrors.InvalidRequest;
return fail;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public async Task wrong_content_type_return_InvalidRequest()

[Fact]
[Trait("Category", Category)]
public async Task empty_request_should_return_InvalidClient()
public async Task empty_request_should_return_InvalidRequest()
{
var response = await _mockPipeline.BackChannelClient.PostAsync(IdentityServerPipeline.DeviceAuthorization,
new FormUrlEncodedContent(new Dictionary<string, string>()));
Expand All @@ -85,7 +85,7 @@ public async Task empty_request_should_return_InvalidClient()
var resultDto = ParseJsonBody<ErrorResultDto>(await response.Content.ReadAsStreamAsync());

resultDto.Should().NotBeNull();
resultDto.error.Should().Be(OidcConstants.TokenErrors.InvalidClient);
resultDto.error.Should().Be(OidcConstants.TokenErrors.InvalidRequest);
}

[Fact]
Expand Down

0 comments on commit 1b2eaf8

Please sign in to comment.