AuthifyPass.Client
1.0.2
See the version list below for details.
dotnet add package AuthifyPass.Client --version 1.0.2
NuGet\Install-Package AuthifyPass.Client -Version 1.0.2
<PackageReference Include="AuthifyPass.Client" Version="1.0.2" />
<PackageVersion Include="AuthifyPass.Client" Version="1.0.2" />
<PackageReference Include="AuthifyPass.Client" />
paket add AuthifyPass.Client --version 1.0.2
#r "nuget: AuthifyPass.Client, 1.0.2"
#:package AuthifyPass.Client@1.0.2
#addin nuget:?package=AuthifyPass.Client&version=1.0.2
#tool nuget:?package=AuthifyPass.Client&version=1.0.2
AuthifyPass.Client Library Documentation
Overview
The AuthifyPass.Client library to consume AuthifyPass API.
Prerequisites
To use this library, you need:
- You must register first in AuthifyPass here to get your CLIENT and SECRET.
Installation
Install the NuGet Package:
- Install the
AuthifyPass.ClientNuGet package in your project using the Package Manager or the .NET CLI:dotnet add package AuthifyPass.Client
- Install the
Configure Client:
- In your appsettings, add
"AuthifyPassOptions": { "ClientID": "", "Secret": "", "BaseUrl": "https://authifypass.com/", "UserEndpoint": "user", "ValidateCodeEndpoint": "user/validate-code", "Header": "x-authify-key" }- NOTE: If AuthifyPass API it's in other URL or change the endpoints, here is where can set. Also the Header key.
- NOTE: Because AuthifyPass is opensource, you can download the code and personalize, so here can change the values.
Register dependencies:
- Add the
IAuthifyPassClientto your dependencies.
var builder = WebApplication.CreateBuilder(args); // OR any other like var builder = WebAssemblyHostBuilder.CreateDefault(args); [...] builder.Services.AddAuthifyPassClient(); [...]- Add the
How to use
Create new QR
internal class Enable2FactorQRInteractor(IAuthifyPassClient client)
{
public async Task<AuthifyPassDto> GetQR(string userId, CancellationToken token)
{
var response = await client.RequestUser2FactorQRAsync(userId, user.Email, token);
var result = new AuthifyPassDto(response.Sharedkey, response.ImageSVG);
result.Code = userId;
return result;
}
}
Login example
internal class UserLoginInteractor(
IRepository<User> repository,
IValidator<UserRequest> validator,
IAuthifyPassClient client)
{
public async Task Login(UserRequest login)
{
bool isValidated = await validator.Validate(login);
if (isValidated)
{
User? user = await repository.GetAsync(u => u.Email == login.Email);
if (user is not null && user.PasswordHash == login.Password)
{
var result2Factor = await client.ValidateUser2FactorAsync(user.Id.ToString(), login.DoubleFactorCode);
if (!result2Factor)
throw new UnauthorizedAccessException("Two-factor authentication is enabled for this user.");
}
}
throw new UnauthorizedAccessException("Invalid email or password.");
}
}
Delete User and all QR
internal class DeleteFactorQRInteractor(IAuthifyPassClient client)
{
public async Task DeleteUserQR(string userId, CancellationToken token)
{
await client.RequestDeleteUser2FactorAsync(userId, token);
}
}
NOTES:
- UserId It's a string, can send any identityies. This identifier it's HASH in AuthifyPass API Side, so we don't have any data from user.
- When delete a User, delete all QR and no more validation will happen.
- User Client App can also delete the QR and invalidate all QR generated.
Errors
When have some error client will return a ProblemDetails model.
Models
The library includes two main models:
AuthifyPassOptions:- Represents the configuration about AuthifyPass API. Check documentation
https://authifypass.com/api/docs. - Properties:
- SectionKey
- ClientID
- Secret
- BaseUrl
- UserEndpoint
- ValidateCodeEndpoint
- Header
- Represents the configuration about AuthifyPass API. Check documentation
AuthifyPassResponse:- Represents the response when request for some new QR and Shared Key.
- Properties:
- Sharedkey
- ImageSVG: QR
Contributing
If you encounter issues or have suggestions for improvements, please submit an issue or pull request to the repository hosting this library.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.DependencyInjection (>= 10.0.0)
- Microsoft.Extensions.Http (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options (>= 10.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Fixed return false if have exception when try to verify user code.