Skip to content

Commit

Permalink
Added the possibility to configure the length of the nonce and the st…
Browse files Browse the repository at this point in the history
…ate (#305)

Added the raw response if HttpStatusCode is not OK (redeem code for tokens)

Co-authored-by: Rémi Ollagnier <[email protected]>
  • Loading branch information
rollagnier and Rémi Ollagnier authored Jul 16, 2021
1 parent d21a580 commit 2798d22
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/OidcClient/AuthorizeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public AuthorizeState CreateAuthorizeState(Parameters frontChannelParameters)

var state = new AuthorizeState
{
State = _crypto.CreateState(),
State = _crypto.CreateState(_options.StateLength),
RedirectUri = _options.RedirectUri,
CodeVerifier = pkce.CodeVerifier,
};
Expand Down
11 changes: 2 additions & 9 deletions src/OidcClient/CryptoHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,11 @@ public bool ValidateHash(string data, string hashedData, string signatureAlgorit
}
}

public string CreateState()
public string CreateState(int length)
{
_logger.LogTrace("CreateState");

return CryptoRandom.CreateUniqueId(16);
}

public string CreateNonce()
{
_logger.LogTrace("CreateNonce");

return CryptoRandom.CreateUniqueId(16);
return CryptoRandom.CreateUniqueId(length);
}

public Pkce CreatePkceData()
Expand Down
8 changes: 8 additions & 0 deletions src/OidcClient/OidcClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ public class OidcClientOptions
/// </value>
public string PostLogoutRedirectUri { get; set; }

/// <summary>
/// Gets or sets the state length.
/// </summary>
/// <value>
/// The state length.
/// </value>
public int StateLength { get; set; } = 16;

/// <summary>
/// Gets or sets the browser implementation.
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions src/OidcClient/ResponseProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Net;
using System.Security.Claims;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -78,6 +79,10 @@ private async Task<ResponseValidationResult> ProcessCodeFlowResponseAsync(
{
return new ResponseValidationResult($"Error redeeming code: {tokenResponse.Error ?? "no error code"} / {tokenResponse.ErrorDescription ?? "no description"}");
}
if (tokenResponse.HttpStatusCode != HttpStatusCode.OK)
{
return new ResponseValidationResult($"Error redeeming code: {tokenResponse.Raw}");
}

// validate token response
var tokenResponseValidationResult = await ValidateTokenResponseAsync(tokenResponse, state, requireIdentityToken:false, cancellationToken: cancellationToken);
Expand Down

0 comments on commit 2798d22

Please sign in to comment.