Skip to content

Commit

Permalink
Added IsSupportedAsync method.
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferStrube committed Sep 24, 2023
1 parent e2d77ea commit e960975
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

<h2>Blazor Web Authentication</h2>

@if (!isSupported)
{
<p>This browser feature is not support on your device.</p>
return;
}

<p>Here you can try create a credential from your device's native identification mechanism.</p>

<button class="btn btn-success" @onclick="CreateCredential">Create Credentials</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace KristofferStrube.Blazor.WebAuthentication.WasmExample.Pages;

public partial class Index : ComponentBase
{
private bool isSupported = false;
private CredentialsContainer container = default!;
private PublicKeyCredential? credential;
private PublicKeyCredential? validatedCredential;
Expand All @@ -18,6 +19,8 @@ public partial class Index : ComponentBase

protected override async Task OnInitializedAsync()
{
isSupported = await CredentialsService.IsSupportedAsync();
if (!isSupported) return;
container = await CredentialsService.GetCredentialsAsync();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.JSInterop;
using KristofferStrube.Blazor.CredentialManagement.Extensions;
using Microsoft.JSInterop;

namespace KristofferStrube.Blazor.CredentialManagement;

Expand All @@ -9,6 +10,12 @@ public async Task<CredentialsContainer> GetCredentialsAsync()
IJSObjectReference jSInstance = await jSRuntime.InvokeAsync<IJSObjectReference>("navigator.credentials.valueOf");
return new CredentialsContainer(jSRuntime, jSInstance);
}

public async Task<bool> IsSupportedAsync()
{
IJSObjectReference helper = await jSRuntime.GetHelperAsync();
return await helper.InvokeAsync<bool>("isSupported");
}
}


Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export function getAttribute(object, attribute) { return object[attribute]; }
export function getAttribute(object, attribute) { return object[attribute]; }

export function isSupported() { return !(!window.PublicKeyCredential); }

0 comments on commit e960975

Please sign in to comment.