Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure Token provider from the corresponding provider #15627

Merged
merged 33 commits into from
Apr 12, 2024
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
20a097a
Configure Token provider from the corresponding provider
MikeAlhayek Mar 29, 2024
a0e10f8
rename
MikeAlhayek Mar 29, 2024
574acbd
Update Startup.cs
MikeAlhayek Apr 7, 2024
1876438
Update Startup.cs
MikeAlhayek Apr 7, 2024
067d7fa
Merge branch 'main' into ma/configure-token-providers
hishamco Apr 7, 2024
d04b1a6
Add a way to configure the email-confirmation, password-reset, change…
MikeAlhayek Apr 7, 2024
b44ec21
Merge branch 'main' into ma/configure-token-providers
MikeAlhayek Apr 7, 2024
73a9631
Merge branch 'main' into ma/configure-token-providers
MikeAlhayek Apr 8, 2024
462def1
Use 15 mins for email change
MikeAlhayek Apr 8, 2024
70b53cf
Fix the TwoFactor provider
MikeAlhayek Apr 8, 2024
d1b3242
Merge branch 'main' into ma/configure-token-providers
MikeAlhayek Apr 8, 2024
aecad0f
update comments
MikeAlhayek Apr 8, 2024
2b09441
Rename
MikeAlhayek Apr 8, 2024
fbcb3e8
Update 1.9.0.md
MikeAlhayek Apr 9, 2024
8c7b73c
Update 1.9.0.md
MikeAlhayek Apr 9, 2024
16a4cae
Update TwoFactorEmailTokenProvider.cs
MikeAlhayek Apr 9, 2024
eadcc90
Update TwoFactorEmailTokenProvider.cs
MikeAlhayek Apr 9, 2024
a2782e1
Update TwoFactorEmailTokenProvider.cs
MikeAlhayek Apr 9, 2024
119befd
Fix build
MikeAlhayek Apr 9, 2024
9941023
Use 3 mins by default for TOTP
MikeAlhayek Apr 9, 2024
9f66cda
Merge branch 'main' into ma/configure-token-providers
MikeAlhayek Apr 9, 2024
0c76454
Fix build
MikeAlhayek Apr 9, 2024
6ffca4a
Use IClock
MikeAlhayek Apr 9, 2024
812d56d
cleanup
MikeAlhayek Apr 9, 2024
e284ca0
Merge branch 'main' into ma/configure-token-providers
hishamco Apr 9, 2024
f5f20f5
Add a test
MikeAlhayek Apr 9, 2024
cfd9c53
cleanup
MikeAlhayek Apr 9, 2024
77a7b0b
Merge branch 'main' into ma/configure-token-providers
MikeAlhayek Apr 9, 2024
45b8c30
Use the default RFC6238 implementation
MikeAlhayek Apr 10, 2024
ffcda7e
Fix services. The issue is generating numeric tokens
MikeAlhayek Apr 10, 2024
1a8a0b9
Merge branch 'main' into ma/configure-token-providers
MikeAlhayek Apr 11, 2024
eebfa80
Merge branch 'main' into ma/configure-token-providers
MikeAlhayek Apr 12, 2024
5e51c0e
Merge branch 'main' into ma/configure-token-providers
MikeAlhayek Apr 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use IClock
MikeAlhayek committed Apr 9, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 6ffca4aff20716e33739125c7d8949cf688bd994
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Options;
using OrchardCore.Modules;
using OrchardCore.Users.Models;

namespace OrchardCore.Users.Services;
@@ -18,10 +19,12 @@ public sealed class TwoFactorEmailTokenProvider : IUserTwoFactorTokenProvider<IU

private string _format;

public TwoFactorEmailTokenProvider(IOptions<TwoFactorEmailTokenProviderOptions> options)
public TwoFactorEmailTokenProvider(
IOptions<TwoFactorEmailTokenProviderOptions> options,
IClock clock)
{
_options = options.Value;
_service = new Rfc6238AuthenticationService(options.Value.TokenLifespan, options.Value.TokenLength);
_service = new Rfc6238AuthenticationService(options.Value.TokenLifespan, options.Value.TokenLength, clock);
}

public Task<bool> CanGenerateTwoFactorTokenAsync(UserManager<IUser> manager, IUser user)
@@ -89,12 +92,18 @@ internal sealed class Rfc6238AuthenticationService

private readonly TimeSpan _timeSpan;
private readonly TwoFactorEmailTokenLength _length;
private readonly IClock _clock;

private int? _modulo;

public Rfc6238AuthenticationService(TimeSpan timeSpan, TwoFactorEmailTokenLength length)
public Rfc6238AuthenticationService(
TimeSpan timeSpan,
TwoFactorEmailTokenLength length,
IClock clock)
{
_timeSpan = timeSpan;
_length = length;
_clock = clock;
}

private int GetModuloValue()
@@ -159,7 +168,7 @@ private static byte[] ApplyModifier(Span<byte> input, byte[] modifierBytes)
/// </summary>
private ulong GetCurrentTimeStepNumber()
{
var delta = DateTimeOffset.UtcNow - DateTimeOffset.UnixEpoch;
var delta = _clock.UtcNow - DateTimeOffset.UnixEpoch;

return (ulong)(delta.Ticks / _timeSpan.Ticks);
}

Unchanged files with check annotations Beta

}
[Benchmark]
public object CreateInstance()

Check warning on line 36 in test/OrchardCore.Benchmarks/ShapeProxyBenchmark.cs

GitHub Actions / Build & Test (ubuntu-latest)

Member 'CreateInstance' does not access instance data and can be marked as static (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822)

Check warning on line 36 in test/OrchardCore.Benchmarks/ShapeProxyBenchmark.cs

GitHub Actions / Build & Test (ubuntu-latest)

Member 'CreateInstance' does not access instance data and can be marked as static (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822)

Check warning on line 36 in test/OrchardCore.Benchmarks/ShapeProxyBenchmark.cs

GitHub Actions / Build & Test (windows-latest)

Member 'CreateInstance' does not access instance data and can be marked as static (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822)

Check warning on line 36 in test/OrchardCore.Benchmarks/ShapeProxyBenchmark.cs

GitHub Actions / Build & Test (windows-latest)

Member 'CreateInstance' does not access instance data and can be marked as static (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822)
{
var shape = (IShape)Activator.CreateInstance(typeof(ContentItemViewModel));
return shape;
}
[Benchmark]
public object CreateDynamicProxy()

Check warning on line 43 in test/OrchardCore.Benchmarks/ShapeProxyBenchmark.cs

GitHub Actions / Build & Test (ubuntu-latest)

Member 'CreateDynamicProxy' does not access instance data and can be marked as static (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822)

Check warning on line 43 in test/OrchardCore.Benchmarks/ShapeProxyBenchmark.cs

GitHub Actions / Build & Test (ubuntu-latest)

Member 'CreateDynamicProxy' does not access instance data and can be marked as static (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822)

Check warning on line 43 in test/OrchardCore.Benchmarks/ShapeProxyBenchmark.cs

GitHub Actions / Build & Test (windows-latest)

Member 'CreateDynamicProxy' does not access instance data and can be marked as static (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822)

Check warning on line 43 in test/OrchardCore.Benchmarks/ShapeProxyBenchmark.cs

GitHub Actions / Build & Test (windows-latest)

Member 'CreateDynamicProxy' does not access instance data and can be marked as static (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822)
{
var options = new ProxyGenerationOptions();
options.AddMixinInstance(new ShapeViewModel());
}
[Benchmark]
public object CreateCachedProxy()

Check warning on line 51 in test/OrchardCore.Benchmarks/ShapeProxyBenchmark.cs

GitHub Actions / Build & Test (ubuntu-latest)

Member 'CreateCachedProxy' does not access instance data and can be marked as static (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822)

Check warning on line 51 in test/OrchardCore.Benchmarks/ShapeProxyBenchmark.cs

GitHub Actions / Build & Test (ubuntu-latest)

Member 'CreateCachedProxy' does not access instance data and can be marked as static (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822)

Check warning on line 51 in test/OrchardCore.Benchmarks/ShapeProxyBenchmark.cs

GitHub Actions / Build & Test (windows-latest)

Member 'CreateCachedProxy' does not access instance data and can be marked as static (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822)

Check warning on line 51 in test/OrchardCore.Benchmarks/ShapeProxyBenchmark.cs

GitHub Actions / Build & Test (windows-latest)

Member 'CreateCachedProxy' does not access instance data and can be marked as static (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822)
{
if (_proxyTypesCache.TryGetValue(typeof(MenuItem), out var proxyType))
{