Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bitwarden/passwordless-blazor-webassembly
Bitwarden Passwordless.dev Blazor WebAssembly SDK.
https://github.com/bitwarden/passwordless-blazor-webassembly
bitwarden blazor blazor-webassembly
Last synced: about 2 months ago
JSON representation
Bitwarden Passwordless.dev Blazor WebAssembly SDK.
- Host: GitHub
- URL: https://github.com/bitwarden/passwordless-blazor-webassembly
- Owner: bitwarden
- License: other
- Created: 2024-04-14T07:54:05.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-11-11T15:14:30.000Z (2 months ago)
- Last Synced: 2024-11-11T16:25:50.048Z (2 months ago)
- Topics: bitwarden, blazor, blazor-webassembly
- Language: C#
- Homepage: https://bitwarden.com/
- Size: 168 KB
- Stars: 3
- Watchers: 19
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE_BITWARDEN.txt
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
![Build](https://github.com/bitwarden/passwordless-blazor-webassembly/actions/workflows/ci.yml/badge.svg)
# Passwordless.dev Blazor WebAssembly Client SDK
## Requirements
- A Blazor WebAssembly application using .NET 6 or higher.
## Installation
TODO
## Configuration
## Using
Be mindful that the code below are simple representations of how to use the SDK. To properly secure your Blazor WebAssembly application, check the [Secure ASP.NET Core Blazor WebAssembly](https://learn.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/) guide.
### Dependency Injection
You can use the following extension methods on `WebApplicationBuilder` to add configure the Passwordless client to your
Blazor WebAssembly application:```csharp
public static void AddPasswordlessClient(this IServiceCollection services, Action configureOptions);public static void AddPasswordlessClient(this IServiceCollection services, IConfiguration configuration);
public static void AddPasswordlessClient(this IServiceCollection services, string section);
```### Registration
Inject the `IPasswordlessClient` into your component and call the `RegisterAsync` method to register a new user.
```
@inject IPasswordlessClient PasswordlessClient
```Your form could look like the one below.
```html
Register```
In the form submission event handlers, handle the registration.
```csharp
private const string RegisterFormName = "RegisterForm";[SupplyParameterFromForm(FormName = RegisterFormName)]
public RegisterViewModel RegisterViewModel { get; set; } = new();private async Task OnRegistrationAsync()
{
if (RegisterViewModel?.Username == null) return;
// 1. Call your backend to obtain the `register_` token.
var registrationToken = await PasswordlessClient.RegisterAsync(new RegisterRequest(RegisterViewModel.Username, RegisterViewModel.Alias));
// 2. Call the Passwordless client to create and store the credentials.
var token = await WebAuthnClient.RegisterAsync(registrationToken.Token, RegisterViewModel.Alias!);
}
```### Logging in
Inject the `IPasswordlessClient` into your component and call the `RegisterAsync` method to register a new user.
```
@inject IPasswordlessClient PasswordlessClient
```Your form could look like the one below.
```html
Sign In```
In the form submission event handlers, handle the login.
```csharp
private const string LoginFormName = "LoginForm";[SupplyParameterFromForm(FormName = LoginFormName)]
public LoginViewModel LoginViewModel { get; set; } = new();private async Task OnSignInAsync()
{
// 1. Call Passwordless.dev to initiate the login process.
var token = await PasswordlessClient.LoginAsync(LoginViewModel.Alias!);// 2. Once a valid credential is selected, call your backend to authenticate the user.
// `backendResponse` can contain a JWT token or any other authentication information.
var backendRequest = new SignInRequest(token.Token);
var backendResponse = await BackendClient.SignInAsync(backendRequest);
}
```## References
- [Get Started - Passwordless.dev](https://docs.passwordless.dev/guide/get-started.html)
- [Integration with your backend - Passwordless.dev](https://docs.passwordless.dev/guide/backend)
- [Secure ASP.NET Core Blazor WebAssembly](https://learn.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/)