Skip to content

Commit

Permalink
Updated description and actually used username.
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferStrube committed Dec 27, 2023
1 parent c82bc7c commit e510ac3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
<p>
Here you can try to register some credentials and validate them.
<br />
<small>If you have registered some credentials for a username within 20 minutes then you can still validate it even after having refreshed this page as it is the server that remembers credentials.</small>
<small>
If you have registered some credentials for a username within 20 minutes then you can still validate it even after having refreshed this page as it is the server that remembers credentials.
<br />
Usernames are not reserved so you can register the same username on multiple devices and validate with either of them. It would of cause be limited who can register new devices for a username in a real use case.
</small>
</p>

<label for="username">Username</label>
Expand All @@ -28,7 +32,7 @@
@if (publicKey is not null)
{
<b>Registered a user! 🎊</b>
<br/>
<br />
<b>Public Key: </b> @string.Join(", ", publicKey.Select(b => $"{b:X2}"))
<br />
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ protected override async Task OnInitializedAsync()

private async Task CreateCredential()
{
byte[] userId = Encoding.ASCII.GetBytes("bob");
challenge = await WebAuthenticationClient.RegisterChallenge("bob");
byte[] userId = Encoding.ASCII.GetBytes(username);
challenge = await WebAuthenticationClient.RegisterChallenge(username);
CredentialCreationOptions options = new()
{
PublicKey = new PublicKeyCredentialCreationOptions()
Expand All @@ -47,9 +47,9 @@ private async Task CreateCredential()
},
User = new PublicKeyCredentialUserEntity()
{
Name = "bob",
Name = username,
Id = userId,
DisplayName = "Bob"
DisplayName = username
},
Challenge = challenge,

Check warning on line 54 in samples/KristofferStrube.Blazor.WebAuthentication.WasmExample/Pages/Index.razor.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference assignment.
PubKeyCredParams =
Expand Down Expand Up @@ -81,7 +81,7 @@ private async Task CreateCredential()
PublicKeyCredentialJSON registrationResponse = await credential.ToJSONAsync();
if (registrationResponse is RegistrationResponseJSON { } registration)
{
await WebAuthenticationClient.Register("bob", registration);
await WebAuthenticationClient.Register(username, registration);
publicKey = registration.Response.PublicKey is not null ? Convert.FromBase64String(registration.Response.PublicKey) : null;
}
}
Expand All @@ -97,7 +97,7 @@ private async Task CreateCredential()

private async Task GetCredential()
{
ValidateCredentials? setup = await WebAuthenticationClient.ValidateChallenge("bob");
ValidateCredentials? setup = await WebAuthenticationClient.ValidateChallenge(username);
if (setup is not { Challenge: { Length: > 0 } challenge, Credentials: { Count: > 0 } credentials })
{
errorMessage = "The user was not previously registered.";
Expand Down Expand Up @@ -134,7 +134,7 @@ private async Task GetCredential()
PublicKeyCredentialJSON authenticationResponse = await validatedCredential.ToJSONAsync();
if (authenticationResponse is AuthenticationResponseJSON { } authentication)
{
validated = await WebAuthenticationClient.Validate("bob", authentication);
validated = await WebAuthenticationClient.Validate(username, authentication);
}
}

Expand Down

0 comments on commit e510ac3

Please sign in to comment.