mirror of
https://github.com/XFox111/SimpleOTP.git
synced 2026-04-22 08:00:45 +03:00
Added DependencyInjection API reference
+6
-2
@@ -31,5 +31,9 @@
|
|||||||
|
|
||||||
## EugeneFox.SimpleOTP.DependencyInjection package
|
## EugeneFox.SimpleOTP.DependencyInjection package
|
||||||
|
|
||||||
> [!NOTE]
|
- **SimpleOTP.DependencyInjection**
|
||||||
This section is still in development.
|
- [IOtpService](./simpleotp.dependencyinjection.iotpservice)
|
||||||
|
- [OtpOptions](./simpleotp.dependencyinjection.otpoptions)
|
||||||
|
- [OtpServiceConfig](./simpleotp.dependencyinjection.otpserviceconfig)
|
||||||
|
- [OtpServiceExtensions](./simpleotp.dependencyinjection.otpserviceextensions)
|
||||||
|
- [ToleranceSpanConfig](./simpleotp.dependencyinjection.tolerancespanconfig)
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
# IOtpService
|
||||||
|
|
||||||
|
Namespace: SimpleOTP.DependencyInjection
|
||||||
|
|
||||||
|
Provides methods for generating and validating One-Time Passwords.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public interface IOtpService
|
||||||
|
```
|
||||||
|
|
||||||
|
Attributes [NullableContextAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullablecontextattribute)
|
||||||
|
|
||||||
|
## Methods
|
||||||
|
|
||||||
|
### **CreateUri(String, OtpSecret, Int64)**
|
||||||
|
|
||||||
|
Creates an OTP URI for specified user and secret.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
Uri CreateUri(string username, OtpSecret secret, long counter)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
|
||||||
|
`username` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
|
||||||
|
The username of the user.
|
||||||
|
|
||||||
|
`secret` OtpSecret<br>
|
||||||
|
The secret to use.
|
||||||
|
|
||||||
|
`counter` [Int64](https://docs.microsoft.com/en-us/dotnet/api/system.int64)<br>
|
||||||
|
(only for HOTP) The counter to use.
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
|
||||||
|
Uri<br>
|
||||||
|
The generated URI.
|
||||||
|
|
||||||
|
### **GenerateCode(OtpSecret, Int64)**
|
||||||
|
|
||||||
|
Creates an OTP code for specified user and secret.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
OtpCode GenerateCode(OtpSecret secret, long counter)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
|
||||||
|
`secret` OtpSecret<br>
|
||||||
|
The secret to use.
|
||||||
|
|
||||||
|
`counter` [Int64](https://docs.microsoft.com/en-us/dotnet/api/system.int64)<br>
|
||||||
|
(only for HOTP) The counter to use.
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
|
||||||
|
OtpCode<br>
|
||||||
|
|
||||||
|
### **ValidateCode(OtpCode, OtpSecret, Int32&, Int64)**
|
||||||
|
|
||||||
|
Validates an OTP code for specified user and secret.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
bool ValidateCode(OtpCode code, OtpSecret secret, Int32& resyncValue, long counter)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
|
||||||
|
`code` OtpCode<br>
|
||||||
|
The code to validate.
|
||||||
|
|
||||||
|
`secret` OtpSecret<br>
|
||||||
|
The secret to use.
|
||||||
|
|
||||||
|
`resyncValue` [Int32&](https://docs.microsoft.com/en-us/dotnet/api/system.int32&)<br>
|
||||||
|
The resync value. Shows how much the code is ahead or behind the current counter value.
|
||||||
|
|
||||||
|
`counter` [Int64](https://docs.microsoft.com/en-us/dotnet/api/system.int64)<br>
|
||||||
|
(only for HOTP) The counter to use.
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
|
||||||
|
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
|
||||||
|
`true` if the code is valid; otherwise, `false`.
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
# OtpOptions
|
||||||
|
|
||||||
|
Namespace: SimpleOTP.DependencyInjection
|
||||||
|
|
||||||
|
Provides options for the One-Time Password service.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public class OtpOptions
|
||||||
|
```
|
||||||
|
|
||||||
|
Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [OtpOptions](simpleotp.dependencyinjection.otpoptions)<br>
|
||||||
|
Attributes [NullableContextAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullablecontextattribute), [NullableAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullableattribute), [RequiredMemberAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.requiredmemberattribute)
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
|
||||||
|
### **Issuer**
|
||||||
|
|
||||||
|
The name of the issuer.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public string Issuer { get; set; }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Property Value
|
||||||
|
|
||||||
|
[String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
|
||||||
|
|
||||||
|
### **IssuerDomain**
|
||||||
|
|
||||||
|
The issuer domain.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public string IssuerDomain { get; set; }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Property Value
|
||||||
|
|
||||||
|
[String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
|
||||||
|
|
||||||
|
**Remarks:**
|
||||||
|
|
||||||
|
IMPORTANT: Using this property will imply adherence to the Apple specification.
|
||||||
|
|
||||||
|
### **Algorithm**
|
||||||
|
|
||||||
|
The algorithm to use.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public OtpAlgorithm Algorithm { get; set; }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Property Value
|
||||||
|
|
||||||
|
OtpAlgorithm<br>
|
||||||
|
|
||||||
|
### **Digits**
|
||||||
|
|
||||||
|
The number of digits in the OTP code.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public int Digits { get; set; }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Property Value
|
||||||
|
|
||||||
|
[Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
|
||||||
|
|
||||||
|
### **Period**
|
||||||
|
|
||||||
|
The number of seconds between each OTP code.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public int Period { get; set; }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Property Value
|
||||||
|
|
||||||
|
[Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
|
||||||
|
|
||||||
|
### **Type**
|
||||||
|
|
||||||
|
The type of One-Time Password to generate.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public OtpType Type { get; set; }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Property Value
|
||||||
|
|
||||||
|
OtpType<br>
|
||||||
|
|
||||||
|
### **UriFormat**
|
||||||
|
|
||||||
|
The format of OTP URIs.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public OtpUriFormat UriFormat { get; set; }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Property Value
|
||||||
|
|
||||||
|
OtpUriFormat<br>
|
||||||
|
|
||||||
|
### **ToleranceSpan**
|
||||||
|
|
||||||
|
The tolerance span for the OTP codes validation.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public ToleranceSpan ToleranceSpan { get; set; }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Property Value
|
||||||
|
|
||||||
|
ToleranceSpan<br>
|
||||||
|
|
||||||
|
### **CustomProperties**
|
||||||
|
|
||||||
|
Custom properties to place in OTP URIs.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public NameValueCollection CustomProperties { get; }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Property Value
|
||||||
|
|
||||||
|
NameValueCollection<br>
|
||||||
|
|
||||||
|
## Constructors
|
||||||
|
|
||||||
|
### **OtpOptions()**
|
||||||
|
|
||||||
|
#### Caution
|
||||||
|
|
||||||
|
Constructors of types with required members are not supported in this version of your compiler.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public OtpOptions()
|
||||||
|
```
|
||||||
@@ -0,0 +1,146 @@
|
|||||||
|
# OtpServiceConfig
|
||||||
|
|
||||||
|
Namespace: SimpleOTP.DependencyInjection
|
||||||
|
|
||||||
|
Configuration for the One-Time Password service.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public class OtpServiceConfig
|
||||||
|
```
|
||||||
|
|
||||||
|
Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [OtpServiceConfig](simpleotp.dependencyinjection.otpserviceconfig)<br>
|
||||||
|
Attributes [NullableContextAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullablecontextattribute), [NullableAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullableattribute)
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
|
||||||
|
### **Issuer**
|
||||||
|
|
||||||
|
The name of the issuer.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public string Issuer { get; set; }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Property Value
|
||||||
|
|
||||||
|
[String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
|
||||||
|
|
||||||
|
### **IssuerDomain**
|
||||||
|
|
||||||
|
The issuer domain.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public string IssuerDomain { get; set; }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Property Value
|
||||||
|
|
||||||
|
[String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
|
||||||
|
|
||||||
|
**Remarks:**
|
||||||
|
|
||||||
|
IMPORTANT: Using this property will imply adherence to the Apple specification.
|
||||||
|
|
||||||
|
### **Algorithm**
|
||||||
|
|
||||||
|
The algorithm to use.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public OtpAlgorithm Algorithm { get; set; }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Property Value
|
||||||
|
|
||||||
|
OtpAlgorithm<br>
|
||||||
|
|
||||||
|
### **Digits**
|
||||||
|
|
||||||
|
The number of digits in the OTP code.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public int Digits { get; set; }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Property Value
|
||||||
|
|
||||||
|
[Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
|
||||||
|
|
||||||
|
### **Period**
|
||||||
|
|
||||||
|
The number of seconds between each OTP code.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public int Period { get; set; }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Property Value
|
||||||
|
|
||||||
|
[Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
|
||||||
|
|
||||||
|
### **Type**
|
||||||
|
|
||||||
|
The type of One-Time Password to generate.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public OtpType Type { get; set; }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Property Value
|
||||||
|
|
||||||
|
OtpType<br>
|
||||||
|
|
||||||
|
### **UriFormat**
|
||||||
|
|
||||||
|
The format of OTP URIs.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public OtpUriFormat UriFormat { get; set; }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Property Value
|
||||||
|
|
||||||
|
OtpUriFormat<br>
|
||||||
|
|
||||||
|
### **MinimalUri**
|
||||||
|
|
||||||
|
Whether to use minimal URI formatting (only required, or altered properties are included), or full URI formatting.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public bool MinimalUri { get; set; }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Property Value
|
||||||
|
|
||||||
|
[Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
|
||||||
|
|
||||||
|
### **ToleranceSpan**
|
||||||
|
|
||||||
|
The tolerance span for the OTP codes validation.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public ToleranceSpanConfig ToleranceSpan { get; set; }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Property Value
|
||||||
|
|
||||||
|
[ToleranceSpanConfig](simpleotp.dependencyinjection.tolerancespanconfig)<br>
|
||||||
|
|
||||||
|
### **CustomProperties**
|
||||||
|
|
||||||
|
Custom properties to place in OTP URIs.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public Dictionary<string, string> CustomProperties { get; }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Property Value
|
||||||
|
|
||||||
|
[Dictionary<String, String>](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2)<br>
|
||||||
|
|
||||||
|
## Constructors
|
||||||
|
|
||||||
|
### **OtpServiceConfig()**
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public OtpServiceConfig()
|
||||||
|
```
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
# OtpServiceExtensions
|
||||||
|
|
||||||
|
Namespace: SimpleOTP.DependencyInjection
|
||||||
|
|
||||||
|
Extension methods for the One-Time Password service.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public static class OtpServiceExtensions
|
||||||
|
```
|
||||||
|
|
||||||
|
Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [OtpServiceExtensions](simpleotp.dependencyinjection.otpserviceextensions)<br>
|
||||||
|
Attributes [NullableContextAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullablecontextattribute), [NullableAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.nullableattribute), [ExtensionAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.extensionattribute)
|
||||||
|
|
||||||
|
## Methods
|
||||||
|
|
||||||
|
### **AddAuthenticator(IServiceCollection, String)**
|
||||||
|
|
||||||
|
Adds the One-Time Password service to the service collection.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public static IServiceCollection AddAuthenticator(IServiceCollection services, string issuerName)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
|
||||||
|
`services` IServiceCollection<br>
|
||||||
|
The service collection.
|
||||||
|
|
||||||
|
`issuerName` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
|
||||||
|
The issuer/application/service name.
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
|
||||||
|
IServiceCollection<br>
|
||||||
|
A reference to this instance after the operation has completed.
|
||||||
|
|
||||||
|
### **AddAuthenticator(IServiceCollection, String, Action<OtpOptions>)**
|
||||||
|
|
||||||
|
Adds the One-Time Password service to the service collection.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public static IServiceCollection AddAuthenticator(IServiceCollection services, string issuerName, Action<OtpOptions> configure)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
|
||||||
|
`services` IServiceCollection<br>
|
||||||
|
The service collection.
|
||||||
|
|
||||||
|
`issuerName` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
|
||||||
|
The issuer/application/service name.
|
||||||
|
|
||||||
|
`configure` [Action<OtpOptions>](https://docs.microsoft.com/en-us/dotnet/api/system.action-1)<br>
|
||||||
|
The configuration for the One-Time Password service.
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
|
||||||
|
IServiceCollection<br>
|
||||||
|
A reference to this instance after the operation has completed.
|
||||||
|
|
||||||
|
### **AddAuthenticator(IServiceCollection, IConfiguration)**
|
||||||
|
|
||||||
|
Adds the One-Time Password service to the service collection.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public static IServiceCollection AddAuthenticator(IServiceCollection services, IConfiguration configuration)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
|
||||||
|
`services` IServiceCollection<br>
|
||||||
|
The service collection.
|
||||||
|
|
||||||
|
`configuration` IConfiguration<br>
|
||||||
|
The configuration for the One-Time Password service.
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
|
||||||
|
IServiceCollection<br>
|
||||||
|
A reference to this instance after the operation has completed.
|
||||||
|
|
||||||
|
### **AddAuthenticator(IServiceCollection, IConfiguration, Action<OtpOptions>)**
|
||||||
|
|
||||||
|
Adds the One-Time Password service to the service collection.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public static IServiceCollection AddAuthenticator(IServiceCollection services, IConfiguration configuration, Action<OtpOptions> configure)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
|
||||||
|
`services` IServiceCollection<br>
|
||||||
|
The service collection.
|
||||||
|
|
||||||
|
`configuration` IConfiguration<br>
|
||||||
|
The configuration for the One-Time Password service.
|
||||||
|
|
||||||
|
`configure` [Action<OtpOptions>](https://docs.microsoft.com/en-us/dotnet/api/system.action-1)<br>
|
||||||
|
The configuration for the One-Time Password service.
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
|
||||||
|
IServiceCollection<br>
|
||||||
|
A reference to this instance after the operation has completed.
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
# ToleranceSpanConfig
|
||||||
|
|
||||||
|
Namespace: SimpleOTP.DependencyInjection
|
||||||
|
|
||||||
|
Configuration for the tolerance span.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public class ToleranceSpanConfig
|
||||||
|
```
|
||||||
|
|
||||||
|
Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [ToleranceSpanConfig](simpleotp.dependencyinjection.tolerancespanconfig)
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
|
||||||
|
### **Behind**
|
||||||
|
|
||||||
|
The number of periods/counter values behind the current value.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public int Behind { get; set; }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Property Value
|
||||||
|
|
||||||
|
[Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
|
||||||
|
|
||||||
|
### **Ahead**
|
||||||
|
|
||||||
|
The number of periods/counter values ahead of the current value.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public int Ahead { get; set; }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Property Value
|
||||||
|
|
||||||
|
[Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
|
||||||
|
|
||||||
|
## Constructors
|
||||||
|
|
||||||
|
### **ToleranceSpanConfig()**
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public ToleranceSpanConfig()
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user