Skip to content

Commit 76550be

Browse files
authored
Merge pull request #353 from DuendeSoftware/dh/need-to-revert-pr-350
Revert PR #350: Override refresh token max length
2 parents 8883594 + 92bf275 commit 76550be

File tree

6 files changed

+5
-271
lines changed

6 files changed

+5
-271
lines changed

access-token-management/src/AccessTokenManagement/RefreshToken.cs

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,13 @@ namespace Duende.AccessTokenManagement;
1010
[JsonConverter(typeof(StringValueJsonConverter<RefreshToken>))]
1111
public readonly record struct RefreshToken : IStronglyTypedValue<RefreshToken>
1212
{
13-
private static int? _overriddenMaxLength;
14-
private static ValidationRule<string>[] _validators = [];
15-
16-
// Officially, there's no max length refresh tokens, but 4k is a good limit
1713
public const int MaxLength = 4 * 1024;
18-
19-
static RefreshToken() => InitializeValidators();
20-
2114
public override string ToString() => Value;
2215

23-
/// <summary>
24-
/// Changes the maximum length for refresh tokens.
25-
/// </summary>
26-
/// <param name="maxLength">The new maximum length. Must be a strictly positive value.</param>
27-
/// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="maxLength"/> is zero or a negative value.</exception>
28-
/// <remarks>
29-
/// Note that this change is applied statically and will affect all instances of <see cref="RefreshToken"/> across the entire application.
30-
/// </remarks>
31-
public static void SetMaxLength(int maxLength)
32-
{
33-
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(maxLength);
34-
35-
_overriddenMaxLength = maxLength;
36-
InitializeValidators();
37-
}
38-
39-
private static void InitializeValidators() =>
40-
_validators = [
41-
ValidationRules.MaxLength(_overriddenMaxLength ?? MaxLength)
42-
];
16+
private static readonly ValidationRule<string>[] Validators = [
17+
// Officially, there's no max length refresh tokens, but 4k is a good limit
18+
ValidationRules.MaxLength(MaxLength)
19+
];
4320

4421
/// <summary>
4522
/// You can't directly create this type.
@@ -61,7 +38,7 @@ private static void InitializeValidators() =>
6138
/// and also includes a list of errors. This is useful for validating user input or other scenarios where you want to provide feedback
6239
/// </summary>
6340
public static bool TryParse(string value, [NotNullWhen(true)] out RefreshToken? parsed, out string[] errors) =>
64-
IStronglyTypedValue<RefreshToken>.TryBuildValidatedObject(value, _validators, out parsed, out errors);
41+
IStronglyTypedValue<RefreshToken>.TryBuildValidatedObject(value, Validators, out parsed, out errors);
6542

6643
static RefreshToken IStronglyTypedValue<RefreshToken>.Create(string result) => new(result);
6744

access-token-management/test/AccessTokenManagement.Tests/AccessTokenHandler/AccessTokenHandlerTests.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111

1212
namespace Duende.AccessTokenManagement.AccessTokenHandler;
1313

14-
// This class uses <see cref="RefreshToken"/>, whose max length is static mutable state
15-
// (via <see cref="RefreshToken.SetMaxLength"/>). Sharing a collection with the other
16-
// RefreshToken test classes prevents parallel execution that could cause flaky failures.
17-
[Collection(nameof(Types.RefreshTokenTests))]
1814
public class AccessTokenHandlerTests(ITestOutputHelper output)
1915
{
2016
private readonly CancellationToken _ct = TestContext.Current.CancellationToken;

access-token-management/test/AccessTokenManagement.Tests/PublicApiVerificationTests.VerifyPublicApi.verified.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@
184184
public RefreshToken() { }
185185
public override string ToString() { }
186186
public static Duende.AccessTokenManagement.RefreshToken Parse(string value) { }
187-
public static void SetMaxLength(int maxLength) { }
188187
public static bool TryParse(string value, [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out Duende.AccessTokenManagement.RefreshToken? parsed, out string[] errors) { }
189188
public static string op_Implicit(Duende.AccessTokenManagement.RefreshToken value) { }
190189
}

access-token-management/test/AccessTokenManagement.Tests/StoreTokensInAuthenticationPropertiesTests.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010

1111
namespace Duende.AccessTokenManagement;
1212

13-
// This class uses <see cref="RefreshToken"/>, whose max length is static mutable state
14-
// (via <see cref="RefreshToken.SetMaxLength"/>). Sharing a collection with the other
15-
// RefreshToken test classes prevents parallel execution that could cause flaky failures.
16-
[Collection(nameof(Types.RefreshTokenTests))]
1713
public class StoreTokensInAuthenticationPropertiesTests
1814
{
1915
private readonly CancellationToken _ct = TestContext.Current.CancellationToken;

access-token-management/test/AccessTokenManagement.Tests/Types/RefreshTokenSetMaxLengthTests.cs

Lines changed: 0 additions & 117 deletions
This file was deleted.

access-token-management/test/AccessTokenManagement.Tests/Types/RefreshTokenTests.cs

Lines changed: 0 additions & 117 deletions
This file was deleted.

0 commit comments

Comments
 (0)