https://github.com/bitwarden/passwordless-dotnet
Bitwarden Passwordless.dev .NET SDK.
https://github.com/bitwarden/passwordless-dotnet
bitwarden dotnet dotnet-core
Last synced: 6 months ago
JSON representation
Bitwarden Passwordless.dev .NET SDK.
- Host: GitHub
- URL: https://github.com/bitwarden/passwordless-dotnet
- Owner: bitwarden
- License: apache-2.0
- Created: 2023-08-02T13:17:01.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-03-27T00:37:15.000Z (6 months ago)
- Last Synced: 2025-03-28T09:19:43.330Z (6 months ago)
- Topics: bitwarden, dotnet, dotnet-core
- Language: C#
- Homepage: https://bitwarden.com/
- Size: 1.24 MB
- Stars: 37
- Watchers: 17
- Forks: 12
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# Passwordless .NET SDK
[](https://github.com/bitwarden/passwordless-dotnet/actions)
[](https://codecov.io/gh/bitwarden/passwordless-dotnet)
[](https://nuget.org/packages/Passwordless)
[](https://nuget.org/packages/Passwordless)The official [Bitwarden Passwordless.dev](https://passwordless.dev) .NET library, supporting .NET Standard 2.0+, .NET Core 2.0+, and .NET Framework 4.6.2+.
## Install
- [NuGet](https://nuget.org/packages/Passwordless): `dotnet add package Passwordless`
## See also
Integration packages:
- [Passwordless.AspNetCore](src/Passwordless.AspNetCore) — Passwordless.dev integration with ASP.NET Core Identity
Examples:
- [Passwordless.Example](examples/Passwordless.Example) — basic Passwordless.dev integration inside an ASP.NET app
- [Passwordless.AspNetIdentity.Example](examples/Passwordless.AspNetIdentity.Example) — Passwordless.dev integration using ASP.NET Identity.
- [Passwordless.MultiTenancy.Example](examples/Passwordless.AspNetIdentity.Example) — Passwordless.dev integration for multi-tenant applications.## Usage
💡 See the full [Getting started guide](https://docs.passwordless.dev/guide/get-started.html) in the official documentation.
### Resolve the client
Add Passwordless to your service container:
```csharp
// In Program.cs or Startup.cs
services.AddPasswordlessSdk(options =>
{
options.ApiSecret = "your_api_secret";
options.ApiKey = "your_api_key";
});
```Inject the client into your controller:
```csharp
public class HomeController(IPasswordlessClient passwordlessClient) : Controller
{
// ...
}
```### Register a passkey
Define an action or an endpoint to generate a registration token:
```csharp
[HttpGet("/create-token")]
public async Task GetRegisterToken(string alias)
{
// Get existing userid from session or create a new user in your database
var userId = Guid.NewGuid().ToString();
// Provide the userid and an alias to link to this user
var payload = new RegisterOptions(userId, alias)
{
// Optional: Link this userid to an alias (e.g. email)
Aliases = [alias]
};
try
{
var tokenRegistration = await passwordlessClient.CreateRegisterTokenAsync(payload);
// Return this token to the frontend
return Ok(tokenRegistration);
}
catch (PasswordlessApiException e)
{
return new JsonResult(e.Details)
{
StatusCode = (int?)e.StatusCode,
};
}
}
```### Verify user
Define an action or an endpoint to verify an authentication token:
```csharp
[HttpGet("/verify-signin")]
public async Task VerifyAuthenticationToken(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
};
}
}
```