The official Bitwarden Passwordless.dev .NET library, supporting .NET Standard 2.0+, .NET Core 2.0+ (and soon .NET Framework 4.6.1+).
Using the .NET Core command-line interface (CLI) tools:
dotnet add package PasswordlessUsing the NuGet Command Line Interface (CLI):
nuget install PasswordlessUsing the Package Manager Console:
Install-Package PasswordlessFrom within Visual Studio:
- Open the Solution Explorer.
- Right-click on a project within your solution.
- Click on Manage NuGet Packages...
- Click on the Browse tab and search for "Passwordless".
- Click on the Passwordless package, select the appropriate version in the right-tab and click Install.
Follow the Get started guide
// in Program.cs or Startup.cs
services.AddPasswordlessSdk(options =>
{
options.ApiSecret = "your_api_secret";
});[HttpGet("/create-token")]
public async Task<IActionResult> GetRegisterToken(string alias)
{
// Get existing userid from session or create a new user in your database
var userId = Guid.NewGuid().ToString();
// Options to give the Api
var payload = new RegisterOptions
{
UserId = userId, // your user id
Username = alias, // e.g. user email, is shown in browser ui
Aliases = new HashSet<string> { alias } // Optional: Link this userid to an alias (e.g. email)
};
try
{
var token = await _passwordlessClient.CreateRegisterTokenAsync(payload);
// return this token to the frontend
return Ok(token);
}
catch (PasswordlessApiException e)
{
return new JsonResult(e.Details)
{
StatusCode = (int)e.StatusCode,
};
}
}[HttpGet]
[Route("/verify-signin")]
public async Task<IActionResult> VerifySignInToken(string token)
{
try
{
var verifiedUser = await _passwordlessClient.VerifyTokenAsync(token);
// Sign the user in, set a cookie, etc,
return Ok(verifiedUser);
}
catch (PasswordlessApiException e)
{
return new JsonResult(e.Details)
{
StatusCode = (int)e.StatusCode
};
}
}For a comprehensive list of examples, check out the API documentation.