Skip to content

Commit 6390be7

Browse files
committed
refactor: 更新接口
1 parent 945597b commit 6390be7

3 files changed

Lines changed: 11 additions & 13 deletions

File tree

src/components/BootstrapBlazor.Authenticator/Extensions/OTPExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace BootstrapBlazor.Components;
66

7-
internal static class OTPExtensions
7+
internal static class OtpExtensions
88
{
99
public static OtpNet.OtpHashMode ToMode(this OtpHashMode mode) => mode switch
1010
{

src/components/BootstrapBlazor.Authenticator/Extensions/ServiceCollectionExtension.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,25 @@
33
// Website: https://www.blazor.zone or https://argozhang.github.io/
44

55
using Microsoft.Extensions.DependencyInjection;
6-
using Microsoft.Extensions.DependencyInjection.Extensions;
76

87
namespace BootstrapBlazor.Components;
98

109
/// <summary>
11-
/// BootstrapBlazor 服务扩展类
10+
/// BootstrapBlazor service extensions
1211
/// </summary>
1312
public static class ServiceCollectionExtension
1413
{
1514
/// <summary>
16-
/// 添加百度文字识别服务
15+
/// Inject <see cref="ITotpService"/> service extension method.
1716
/// </summary>
1817
/// <param name="services"></param>
1918
/// <param name="configOptions"></param>
2019
/// <returns></returns>
21-
public static IServiceCollection AddBootstrapBlazorAuthenticator(this IServiceCollection services, Action<
22-
AuthenticatorOptions>? configOptions = null)
20+
public static IServiceCollection AddBootstrapBlazorTotpService(this IServiceCollection services, Action<
21+
OtpOptions>? configOptions = null)
2322
{
24-
services.TryAddSingleton<ITotpService, DefaultTotpServices>();
25-
services.AddOptionsMonitor<AuthenticatorOptions>();
26-
services.Configure<AuthenticatorOptions>(options =>
23+
services.AddSingleton<ITotpService, DefaultTotpService>();
24+
services.Configure<OtpOptions>(options =>
2725
{
2826
configOptions?.Invoke(options);
2927

src/components/BootstrapBlazor.Authenticator/Services/DefaultTOTPServices.cs renamed to src/components/BootstrapBlazor.Authenticator/Services/DefaultTotpService.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
namespace BootstrapBlazor.Components;
99

10-
class DefaultTotpServices(IOptionsMonitor<AuthenticatorOptions> optionsMonitor) : ITotpService
10+
class DefaultTotpService(IOptionsMonitor<OtpOptions> optionsMonitor) : ITotpService
1111
{
1212
[NotNull]
1313
public TotpInstanceBase? Instance { get; private set; }
1414

15-
public string GenerateOtpUri(AuthenticatorOptions? options = null)
15+
public string GenerateOtpUri(OtpOptions? options = null)
1616
{
1717
options ??= optionsMonitor.CurrentValue;
1818
var type = options.Type.ToType();
@@ -21,9 +21,9 @@ public string GenerateOtpUri(AuthenticatorOptions? options = null)
2121
return uri.ToString();
2222
}
2323

24-
public string Compute(string secretKey, DateTime? timestamp = null)
24+
public string Compute(string secretKey, int step = 6, OtpHashMode mode = OtpHashMode.Sha1, int totpSize = 6, DateTime? timestamp = null)
2525
{
26-
var instance = new Totp(Base32Encoding.ToBytes(secretKey));
26+
var instance = new Totp(Base32Encoding.ToBytes(secretKey), step, mode.ToMode(), totpSize, timeCorrection: null);
2727
Instance = new DefaultTotpInstance(instance);
2828
return timestamp == null ? instance.ComputeTotp() : instance.ComputeTotp(timestamp.Value);
2929
}

0 commit comments

Comments
 (0)