Browse Source

Update OpenIddictProvider.ValidateTokenRequest to skip request validation when client authentication cannot be enforced

pull/151/head
Kévin Chalet 10 years ago
parent
commit
9f27be57ec
  1. 60
      src/OpenIddict.Core/Infrastructure/OpenIddictProvider.Exchange.cs

60
src/OpenIddict.Core/Infrastructure/OpenIddictProvider.Exchange.cs

@ -84,46 +84,56 @@ namespace OpenIddict.Infrastructure {
return; return;
} }
// Reject tokens requests containing a client_secret if the client application is not confidential.
var type = await services.Applications.GetClientTypeAsync(application); var type = await services.Applications.GetClientTypeAsync(application);
if (!string.Equals(type, OpenIddictConstants.ClientTypes.Confidential, StringComparison.OrdinalIgnoreCase) && if (string.Equals(type, OpenIddictConstants.ClientTypes.Public, StringComparison.OrdinalIgnoreCase)) {
!string.IsNullOrEmpty(context.ClientSecret)) { // Reject tokens requests containing a client_secret when the client is a public application.
services.Logger.LogError("The token request was rejected because the public application '{ClientId}' " + if (!string.IsNullOrEmpty(context.ClientSecret)) {
"was not allowed to send a client secret.", context.ClientId); services.Logger.LogError("The token request was rejected because the public application '{ClientId}' " +
"was not allowed to send a client secret.", context.ClientId);
context.Reject( context.Reject(
error: OpenIdConnectConstants.Errors.InvalidRequest, error: OpenIdConnectConstants.Errors.InvalidRequest,
description: "Public clients are not allowed to send a client_secret."); description: "Public clients are not allowed to send a client_secret.");
return;
}
services.Logger.LogInformation("The token request validation process was not fully validated because " +
"the client '{ClientId}' was a public application.", context.ClientId);
// If client authentication cannot be enforced, call context.Skip() to inform
// the OpenID Connect server middleware that the caller cannot be fully trusted.
context.Skip();
return; return;
} }
// Confidential applications MUST authenticate to protect them from impersonation attacks. // Confidential applications MUST authenticate to protect them from impersonation attacks.
else if (!string.Equals(type, OpenIddictConstants.ClientTypes.Public)) { if (string.IsNullOrEmpty(context.ClientSecret)) {
if (string.IsNullOrEmpty(context.ClientSecret)) { services.Logger.LogError("The token request was rejected because the confidential application " +
services.Logger.LogError("The token request was rejected because the confidential application " + "'{ClientId}' didn't specify a client secret.", context.ClientId);
"'{ClientId}' didn't specify a client secret.", context.ClientId);
context.Reject( context.Reject(
error: OpenIdConnectConstants.Errors.InvalidClient, error: OpenIdConnectConstants.Errors.InvalidClient,
description: "Missing credentials: ensure that you specified a client_secret."); description: "Missing credentials: ensure that you specified a client_secret.");
return; return;
} }
if (!await services.Applications.ValidateSecretAsync(application, context.ClientSecret)) { if (!await services.Applications.ValidateSecretAsync(application, context.ClientSecret)) {
services.Logger.LogError("The token request was rejected because the confidential application " + services.Logger.LogError("The token request was rejected because the confidential application " +
"'{ClientId}' didn't specify valid client credentials.", context.ClientId); "'{ClientId}' didn't specify valid client credentials.", context.ClientId);
context.Reject( context.Reject(
error: OpenIdConnectConstants.Errors.InvalidClient, error: OpenIdConnectConstants.Errors.InvalidClient,
description: "Invalid credentials: ensure that you specified a correct client_secret."); description: "Invalid credentials: ensure that you specified a correct client_secret.");
return; return;
}
} }
context.Validate(); context.Validate();
return;
} }
public override async Task HandleTokenRequest([NotNull] HandleTokenRequestContext context) { public override async Task HandleTokenRequest([NotNull] HandleTokenRequestContext context) {

Loading…
Cancel
Save