-
-
Notifications
You must be signed in to change notification settings - Fork 242
Add WebAuthn to Boilerplate (#9922) #10225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
msynk
merged 22 commits into
bitfoundation:develop
from
msynk:9922-templates-boilerplate-webauthn
Mar 11, 2025
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
76fe85b
fist commit
msynk f1d9111
Merge branch 'develop' into 9922-templates-boilerplate-webauthn
msynk 5e84234
2nd commit
msynk 406cd39
3rd commit
msynk 39ecf2e
merge with develop
msynk 88719ac
merge with dev
msynk 8cdf1ae
Merge branch '9922-templates-boilerplate-webauthn' of https://github.…
msynk c26e33e
add migration
msynk ebe7844
add registration ui
msynk 20d5056
merge with dev
msynk c266a75
first try for disable
msynk 7158b9f
finish passwordless pivot
msynk dd9b5ee
add passwordless signin
msynk 3b085dd
fix review
msynk 5846267
improve showing passwordless btn
msynk fa569f7
add comments and review
msynk bdb79bd
rename ts file
msynk 11aa64a
rename ts file back
msynk 4c8af44
fix
ysmoradi 267c6d6
fix appstrings
msynk 0dd4f6b
fix
ysmoradi babb85a
fix
ysmoradi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...nt/Boilerplate.Client.Core/Components/Pages/Authorized/Settings/PasswordlessSection.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
@inherits AppComponentBase | ||
|
||
<section> | ||
<BitStack FillContent HorizontalAlign="BitAlignment.Center" Class="max-width"> | ||
<BitText Typography="BitTypography.H6" Align="BitTextAlign.Center"> | ||
@Localizer[nameof(AppStrings.PasswordlessTitle)] | ||
</BitText> | ||
<br /> | ||
@if (isConfigured) | ||
{ | ||
<BitButton OnClick="WrapHandled(DisablePasswordless)" Variant="BitVariant.Outline" Color="BitColor.Warning"> | ||
@Localizer[nameof(AppStrings.DisablePasswordless)] | ||
</BitButton> | ||
} | ||
else | ||
{ | ||
<BitButton OnClick="WrapHandled(EnablePasswordless)"> | ||
@Localizer[nameof(AppStrings.EnablePasswordless)] | ||
</BitButton> | ||
} | ||
<br /> | ||
</BitStack> | ||
</section> |
83 changes: 83 additions & 0 deletions
83
...Boilerplate.Client.Core/Components/Pages/Authorized/Settings/PasswordlessSection.razor.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using Fido2NetLib; | ||
using Boilerplate.Shared.Dtos.Identity; | ||
using Boilerplate.Shared.Controllers.Identity; | ||
|
||
namespace Boilerplate.Client.Core.Components.Pages.Authorized.Settings; | ||
|
||
public partial class PasswordlessSection | ||
{ | ||
private bool isConfigured; | ||
|
||
|
||
[AutoInject] IUserController userController = default!; | ||
[AutoInject] IIdentityController identityController = default!; | ||
|
||
|
||
[Parameter] public UserDto? User { get; set; } | ||
|
||
protected override async Task OnParamsSetAsync() | ||
{ | ||
await base.OnParamsSetAsync(); | ||
|
||
if (User?.UserName is null) return; | ||
|
||
isConfigured = await JSRuntime.IsWebAuthnConfigured(User.UserName); | ||
} | ||
|
||
|
||
private async Task EnablePasswordless() | ||
{ | ||
if (User?.UserName is null) return; | ||
|
||
var options = await userController.GetWebAuthnCredentialOptions(CurrentCancellationToken); | ||
|
||
AuthenticatorAttestationRawResponse attestationResponse; | ||
try | ||
{ | ||
attestationResponse = await JSRuntime.CreateWebAuthnCredential(options); | ||
} | ||
catch (Exception ex) | ||
{ | ||
// we can safely handle the exception thrown here since it mostly because of a timeout or user cancelling the native ui. | ||
ExceptionHandler.Handle(ex, ExceptionDisplayKind.None); | ||
return; | ||
} | ||
|
||
await userController.CreateWebAuthnCredential(attestationResponse, CurrentCancellationToken); | ||
|
||
await JSRuntime.StoreWebAuthnConfigured(User.UserName); | ||
|
||
isConfigured = true; | ||
|
||
SnackBarService.Success(Localizer[nameof(AppStrings.EnablePasswordlessSucsessMessage)]); | ||
} | ||
|
||
private async Task DisablePasswordless() | ||
{ | ||
if (User?.UserName is null) return; | ||
|
||
var options = await identityController.GetWebAuthnAssertionOptions(CurrentCancellationToken); | ||
|
||
AuthenticatorAssertionRawResponse assertion; | ||
try | ||
{ | ||
assertion = await JSRuntime.VerifyWebAuthnCredential(options); | ||
} | ||
catch (Exception ex) | ||
{ | ||
// we can safely handle the exception thrown here since it mostly because of a timeout or user cancelling the native ui. | ||
ExceptionHandler.Handle(ex, ExceptionDisplayKind.None); | ||
return; | ||
} | ||
|
||
var verifyResult = await identityController.VerifyWebAuthAssertion(assertion, CurrentCancellationToken); | ||
|
||
await userController.DeleteWebAuthnCredential(assertion.Id, CurrentCancellationToken); | ||
|
||
await JSRuntime.RemoveWebAuthnConfigured(User.UserName); | ||
|
||
isConfigured = false; | ||
|
||
SnackBarService.Success(Localizer[nameof(AppStrings.DisablePasswordlessSucsessMessage)]); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...ilerplate.Client.Core/Components/Pages/Authorized/Settings/PasswordlessSection.razor.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
section { | ||
width: 100%; | ||
display: flex; | ||
justify-content: center; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.