Modifiche x sperimentare gestione ruoli auth

This commit is contained in:
Samuele Locatelli
2021-08-24 14:59:11 +02:00
parent bf7acb2b08
commit 104e4acd93
6 changed files with 66 additions and 11 deletions
@@ -22,7 +22,7 @@
</li>
<li>
<p>Scan the QR Code or enter this key <kbd>@Model.SharedKey</kbd> into your two factor authenticator app. Spaces and casing do not matter.</p>
<div class="alert alert-info">Learn how to <a href="https://go.microsoft.com/fwlink/?Linkid=852423">enable QR code generation</a>.</div>
@*<div class="alert alert-info">Learn how to <a href="https://go.microsoft.com/fwlink/?Linkid=852423">enable QR code generation</a>.</div>*@
<div id="qrCode"></div>
<div id="qrCodeData" data-url="@Html.Raw(@Model.AuthenticatorUri)"></div>
</li>
@@ -50,4 +50,14 @@
@section Scripts {
<partial name="_ValidationScriptsPartial" />
}
<script type="text/javascript" src="~/lib/qrcode.js"></script>
<script type="text/javascript">
new QRCode(document.getElementById("qrCode"),
{
text: "@Html.Raw(Model.AuthenticatorUri)",
width: 150,
height: 150
});
</script>
}
@@ -34,11 +34,11 @@
if (Model.IsMachineRemembered)
{
<form method="post" style="display: inline-block">
<button type="submit" class="btn btn-default">Forget this browser</button>
<button type="submit" class="btn btn-warning">Forget this browser</button>
</form>
}
<a asp-page="./Disable2fa" class="btn btn-default">Disable 2FA</a>
<a asp-page="./GenerateRecoveryCodes" class="btn btn-default">Reset recovery codes</a>
<a asp-page="./Disable2fa" class="btn btn-danger">Disable 2FA</a>
<a asp-page="./GenerateRecoveryCodes" class="btn btn-warning">Reset recovery codes</a>
}
<h5>Authenticator app</h5>
+4
View File
@@ -33,4 +33,8 @@
<ItemGroup>
<ProjectReference Include="..\GWMS.Data\GWMS.Data.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="wwwroot\lib\" />
</ItemGroup>
</Project>
+16
View File
@@ -9,6 +9,22 @@
<p>Current count: @currentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
<AuthorizeView>
<Authorized>
<div class="alert alert-success">
<h4>Hello, @context.User.Identity.Name!</h4>
<p>This content is only visible if user is authenticated.</p>
</div>
</Authorized>
<NotAuthorized>
<div class="alert alert-warning">
<h4>Utente anonimo</h4>
<p>Please signed in.</p>
</div>
</NotAuthorized>
</AuthorizeView>
<br />
<button class="btn btn-danger" @onclick="SendTestEmail">Test Invio Email</button>
+17 -6
View File
@@ -17,11 +17,22 @@
<span class="oi oi-plus" aria-hidden="true"></span> Counter
</NavLink>
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="fetchdata">
<span class="oi oi-list-rich" aria-hidden="true"></span> Fetch data
</NavLink>
</li>
<AuthorizeView>
<Authorized>
<li class="nav-item px-3">
<NavLink class="nav-link" href="fetchdata">
<span class="oi oi-list-rich" aria-hidden="true"></span> Fetch data
</NavLink>
</li>
</Authorized>
<NotAuthorized>
<li class="nav-item px-3">
<div class="alert alert-warning">
<p>Accesso riservato</p>
</div>
</li>
</NotAuthorized>
</AuthorizeView>
</ul>
</div>
@@ -34,4 +45,4 @@
{
collapseNavMenu = !collapseNavMenu;
}
}
}
+14
View File
@@ -1,6 +1,7 @@
using GWMS.Data;
using GWMS.User.Areas.Identity;
using GWMS.User.Data;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
@@ -95,6 +96,9 @@ namespace GWMS.User
o.ExpireTimeSpan = TimeSpan.FromDays(30);
o.SlidingExpiration = true;
});
// token di sicurezza dati a 3h
services.Configure<DataProtectionTokenProviderOptions>(o =>
o.TokenLifespan = TimeSpan.FromHours(3));
// DB management
services.AddDbContext<UserIdentityDbContext>(options =>
@@ -102,9 +106,19 @@ namespace GWMS.User
// identity management
services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddRoles<IdentityRole>()
.AddEntityFrameworkStores<UserIdentityDbContext>();
services.AddRazorPages();
// richeista esplicita autorizzazione
services.AddAuthorization(options =>
{
options.FallbackPolicy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
});
services.AddServerSideBlazor();
services.AddScoped<AuthenticationStateProvider, RevalidatingIdentityAuthenticationStateProvider<IdentityUser>>();
services.AddDatabaseDeveloperPageExceptionFilter();