-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from alexfdezsauco/feature/fingerprint-authoriz…
…ation Implements fingerprint authentication and authorization
- Loading branch information
Showing
22 changed files
with
275 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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
7 changes: 7 additions & 0 deletions
7
src/Nothing.Nauta.App/Authorization/FingerprintAuthorizationRequirement.cs
This file contains 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,7 @@ | ||
namespace Nothing.Nauta.App.Authorization; | ||
|
||
using Microsoft.AspNetCore.Authorization; | ||
|
||
public class FingerprintAuthorizationRequirement : IAuthorizationRequirement | ||
{ | ||
} |
30 changes: 30 additions & 0 deletions
30
src/Nothing.Nauta.App/Authorization/FingerprintAuthorizationRequirementHandler.cs
This file contains 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,30 @@ | ||
namespace Nothing.Nauta.App.Authorization; | ||
|
||
using Microsoft.AspNetCore.Authorization; | ||
using Plugin.Fingerprint.Abstractions; | ||
|
||
public class FingerprintAuthorizationRequirementHandler : AuthorizationHandler<FingerprintAuthorizationRequirement> | ||
{ | ||
private readonly IFingerprint fingerprint; | ||
|
||
public FingerprintAuthorizationRequirementHandler(IFingerprint fingerprint) | ||
{ | ||
this.fingerprint = fingerprint; | ||
} | ||
|
||
protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, FingerprintAuthorizationRequirement requirement) | ||
{ | ||
// Required to display devices authentication request controls (fingerprint) | ||
context.Succeed(requirement); | ||
|
||
if (await this.fingerprint.IsAvailableAsync()) | ||
{ | ||
var authenticationRequestConfiguration = new AuthenticationRequestConfiguration("Nauta Session", "Please unlock with your fingerprint to proceed"); | ||
var authenticationResult = await this.fingerprint.AuthenticateAsync(authenticationRequestConfiguration); | ||
if (!authenticationResult.Authenticated) | ||
{ | ||
context.Fail(); | ||
} | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/Nothing.Nauta.App/Authorization/FingerprintAuthorizationStateProvider.cs
This file contains 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,14 @@ | ||
namespace Nothing.Nauta.App.Authorization; | ||
|
||
using System.Security.Claims; | ||
|
||
using Microsoft.AspNetCore.Components.Authorization; | ||
|
||
public class FingerprintAuthorizationStateProvider : AuthenticationStateProvider | ||
{ | ||
public override Task<AuthenticationState> GetAuthenticationStateAsync() | ||
{ | ||
var claimsPrincipal = new ClaimsPrincipal(new ClaimsIdentity(Array.Empty<Claim>(), "Fingerprint")); | ||
return Task.FromResult(new AuthenticationState(claimsPrincipal)); | ||
} | ||
} |
This file contains 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,6 @@ | ||
namespace Nothing.Nauta.App.Authorization; | ||
|
||
public class Policies | ||
{ | ||
public const string Fingerprint = nameof(Fingerprint); | ||
} |
This file contains 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,24 @@ | ||
namespace Nothing.Nauta.App | ||
{ | ||
using Microsoft.AspNetCore.Components; | ||
|
||
/// <summary> | ||
/// The Main class. | ||
/// </summary> | ||
public partial class Main | ||
{ | ||
/// <summary> | ||
/// Gets or sets navigation manager. | ||
/// </summary> | ||
[Inject] | ||
public NavigationManager? NavigationManager { get; set; } | ||
|
||
/// <summary> | ||
/// Called on unlock button click. | ||
/// </summary> | ||
private void OnUnlockButtonClick() | ||
{ | ||
this.NavigationManager?.NavigateTo("/"); | ||
} | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -1,12 +1,29 @@ | ||
@using AddProfile = Nothing.Nauta.App.Shared.MainLayout | ||
<Router AppAssembly="@typeof(Main).Assembly"> | ||
<Found Context="routeData"> | ||
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" /> | ||
<FocusOnNavigate RouteData="@routeData" Selector="h1" /> | ||
</Found> | ||
<NotFound> | ||
<LayoutView Layout="@typeof(MainLayout)"> | ||
<p role="alert">Sorry, there's nothing at this address.</p> | ||
</LayoutView> | ||
</NotFound> | ||
</Router> | ||
|
||
<CascadingAuthenticationState> | ||
<Router AppAssembly="@typeof(Main).Assembly"> | ||
<Found Context="routeData"> | ||
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"> | ||
<Authorizing> | ||
<MudPaper Class="d-flex align-content-center justify-center flex-wrap flex-grow-1 gap-4" Height="800px" Width="100%" Elevation="0"> | ||
<MudIcon Icon="@Icons.Material.Filled.Lock" Size="Size.Large" Color="Color.Primary"/> | ||
</MudPaper> | ||
</Authorizing> | ||
<NotAuthorized> | ||
<MudPaper Class="d-flex align-content-center justify-center flex-wrap flex-grow-1 gap-4 border-dashed" Height="800px" Width="100%" Elevation="0"> | ||
<MudStack Justify="Justify.Center" AlignItems="AlignItems.Center"> | ||
<MudText Color="Color.Primary" Typo="Typo.h5">Nauta Session locked.</MudText> | ||
<MudButton Color="Color.Primary" StartIcon="@Icons.Material.Filled.Lock" Size="Size.Large" OnClick="OnUnlockButtonClick">Unlock</MudButton> | ||
</MudStack> | ||
</MudPaper> | ||
</NotAuthorized> | ||
</AuthorizeRouteView> | ||
<FocusOnNavigate RouteData="@routeData" Selector="h1"/> | ||
</Found> | ||
<NotFound> | ||
<LayoutView Layout="@typeof(MainLayout)"> | ||
<p role="alert">Sorry, there's nothing at this address.</p> | ||
</LayoutView> | ||
</NotFound> | ||
</Router> | ||
</CascadingAuthenticationState> | ||
|
This file contains 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 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 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 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 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 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 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 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,18 @@ | ||
using Nothing.Nauta.App.Services.Interfaces; | ||
|
||
namespace Nothing.Nauta.App.Services; | ||
|
||
public class AuthenticationService : IAuthenticationService | ||
{ | ||
public event EventHandler? SessionExpired; | ||
|
||
public void ExpireSession() | ||
{ | ||
this.OnSessionExpired(); | ||
} | ||
|
||
protected virtual void OnSessionExpired() | ||
{ | ||
this.SessionExpired?.Invoke(this, System.EventArgs.Empty); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/Nothing.Nauta.App/Services/Interfaces/IAuthenticationService.cs
This file contains 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,8 @@ | ||
namespace Nothing.Nauta.App.Services.Interfaces; | ||
|
||
public interface IAuthenticationService | ||
{ | ||
event EventHandler SessionExpired; | ||
|
||
void ExpireSession(); | ||
} |
Oops, something went wrong.