housekeeping updates #7
5 changed files with 64 additions and 98 deletions
|
@ -1,43 +0,0 @@
|
||||||
@page "/authentication/{action}"
|
|
||||||
@using System.Security.Claims
|
|
||||||
@layout SimpleLayout
|
|
||||||
|
|
||||||
@code{
|
|
||||||
private const string Login = "login";
|
|
||||||
private const string Logout = "logout";
|
|
||||||
public ClaimsPrincipal? User { get; private set; }
|
|
||||||
|
|
||||||
[CascadingParameter]
|
|
||||||
public required Task<AuthenticationState> AuthenticationState { get; set; }
|
|
||||||
|
|
||||||
[Parameter]
|
|
||||||
public string? Action { get; set; }
|
|
||||||
|
|
||||||
[Inject]
|
|
||||||
public required NavigationManager NavigationManager { get; set; }
|
|
||||||
|
|
||||||
private void SignOut()
|
|
||||||
{
|
|
||||||
NavigationManager.NavigateTo("MicrosoftIdentity/Account/SignOut", true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SignIn()
|
|
||||||
{
|
|
||||||
NavigationManager.NavigateTo("MicrosoftIdentity/Account/SignIn", true);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
|
||||||
{
|
|
||||||
var authenticationState = await AuthenticationState;
|
|
||||||
User = authenticationState.User;
|
|
||||||
if (Action == Logout)
|
|
||||||
{
|
|
||||||
SignOut();
|
|
||||||
}
|
|
||||||
else if (Action == Login)
|
|
||||||
{
|
|
||||||
SignIn();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -21,11 +21,6 @@
|
||||||
Thanks for visiting!
|
Thanks for visiting!
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p class="mt-4 text-base leading-7 text-slate-900">
|
|
||||||
Click this button to throw an error:
|
|
||||||
<button class="px-4 py-2 bg-brand text-white rounded-md" @onclick="ThrowError">Throw Error</button>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<div class="w-full sm:w-auto">
|
<div class="w-full sm:w-auto">
|
||||||
<div class="mt-10 grid grid-cols-1 gap-x-6 gap-y-4 sm:grid-cols-3">
|
<div class="mt-10 grid grid-cols-1 gap-x-6 gap-y-4 sm:grid-cols-3">
|
||||||
|
|
|
@ -5,30 +5,14 @@
|
||||||
|
|
||||||
<PageTitle>Not Found</PageTitle>
|
<PageTitle>Not Found</PageTitle>
|
||||||
|
|
||||||
<div class="fixed inset-y-0 right-0 left-[40rem] hidden lg:block xl:left-[50rem] z-0">
|
<h1 class="mt-4 text-4xl md:text-5xl lg:text-6xl font-semibold text-[2rem] leading-10 tracking-tighter">Not Found</h1>
|
||||||
<svg
|
<p class="text-slate text-xl mt-4">
|
||||||
viewBox="0 0 1080 957"
|
No page was found at <code>@Path</code>.
|
||||||
fill="none"
|
</p>
|
||||||
aria-hidden="true"
|
|
||||||
class="absolute inset-0 h-full w-full"
|
|
||||||
preserveAspectRatio="xMinYMid slice">
|
|
||||||
<path fill="#2e3440" d="M0 0h1080v957H0z"/>
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="px-4 py-10 sm:py-28 sm:px-6 lg:px-8 xl:py-32 xl:px-28">
|
<p class="text-blue-600 text-xl mt-4">
|
||||||
<div class="mx-auto max-w-xl lg:mx-0">
|
<a href="/" aria-label="Home" class="underline">Go to home page</a>
|
||||||
<h1 class="mt-4 text-4xl md:text-5xl lg:text-6xl font-semibold text-[2rem] leading-10 tracking-tighter">Not Found</h1>
|
</p>
|
||||||
<p class="text-slate text-xl mt-4">
|
|
||||||
No page was found at <code>@Path</code>.<br/>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="text-blue-600 text-xl mt-4">
|
|
||||||
<a href="/" aria-label="Home" class="underline">Go to home page</a>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
private string Path { get; set; }
|
private string Path { get; set; }
|
||||||
|
|
|
@ -1,24 +1,33 @@
|
||||||
<CascadingAuthenticationState>
|
<Router AppAssembly="@typeof(Program).Assembly" AdditionalAssemblies="new[] {typeof(Client._Imports).Assembly, typeof(AsyncEventHandler).Assembly}">
|
||||||
<Router AppAssembly="@typeof(Program).Assembly" AdditionalAssemblies="new[] {typeof(Client._Imports).Assembly}">
|
<Found Context="routeData">
|
||||||
<Found Context="routeData">
|
<RouteView RouteData="@routeData" DefaultLayout="@typeof(SimpleLayout)"/>
|
||||||
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(SimpleLayout)">
|
</Found>
|
||||||
<NotAuthorized>
|
<NotFound>
|
||||||
@if (context.User.Identity?.IsAuthenticated != true)
|
<PageTitle>Not found</PageTitle>
|
||||||
{
|
<LayoutView Layout="@typeof(SimpleLayout)">
|
||||||
<RedirectToLogin/>
|
<div class="fixed inset-y-0 right-0 left-[40rem] hidden lg:block xl:left-[50rem] z-0">
|
||||||
}
|
<svg
|
||||||
else
|
viewBox="0 0 1080 957"
|
||||||
{
|
fill="none"
|
||||||
<p role="alert">You are not authorized to access this resource.</p>
|
aria-hidden="true"
|
||||||
}
|
class="absolute inset-0 h-full w-full"
|
||||||
</NotAuthorized>
|
preserveAspectRatio="xMinYMid slice">
|
||||||
</AuthorizeRouteView>
|
<path fill="#2e3440" d="M0 0h1080v957H0z"/>
|
||||||
</Found>
|
</svg>
|
||||||
<NotFound>
|
</div>
|
||||||
<PageTitle>Not found</PageTitle>
|
|
||||||
<LayoutView Layout="@typeof(SimpleLayout)">
|
<div class="px-4 py-10 sm:py-28 sm:px-6 lg:px-8 xl:py-32 xl:px-28">
|
||||||
<p role="alert">Sorry, there's nothing at this address.</p>
|
<div class="mx-auto max-w-xl lg:mx-0">
|
||||||
</LayoutView>
|
<h1 class="mt-4 text-4xl md:text-5xl lg:text-6xl font-semibold text-[2rem] leading-10 tracking-tighter">Not Found</h1>
|
||||||
</NotFound>
|
<p class="text-slate text-xl mt-4">
|
||||||
</Router>
|
No page was found at this address. Please check the web address and try again.
|
||||||
</CascadingAuthenticationState>
|
</p>
|
||||||
|
<p class="text-blue-600 text-xl mt-4">
|
||||||
|
<a href="/" aria-label="Home" class="underline">Go to home page</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</LayoutView>
|
||||||
|
</NotFound>
|
||||||
|
</Router>
|
|
@ -1,6 +1,7 @@
|
||||||
using Azure.Identity;
|
using Azure.Identity;
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
|
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.FileProviders;
|
using Microsoft.Extensions.FileProviders;
|
||||||
using Microsoft.Identity.Web;
|
using Microsoft.Identity.Web;
|
||||||
using Microsoft.Identity.Web.UI;
|
using Microsoft.Identity.Web.UI;
|
||||||
|
@ -31,6 +32,20 @@ builder.Services.AddRazorComponents()
|
||||||
.AddInteractiveServerComponents()
|
.AddInteractiveServerComponents()
|
||||||
.AddInteractiveWebAssemblyComponents();
|
.AddInteractiveWebAssemblyComponents();
|
||||||
|
|
||||||
|
builder.Services.AddProblemDetails(
|
||||||
|
options =>
|
||||||
|
{
|
||||||
|
options.CustomizeProblemDetails = ctx =>
|
||||||
|
{
|
||||||
|
ctx.ProblemDetails.Extensions.TryAdd("traceId", ctx.HttpContext.TraceIdentifier);
|
||||||
|
if (ctx.HttpContext.RequestServices.GetRequiredService<IHostEnvironment>()
|
||||||
|
.IsDevelopment())
|
||||||
|
{
|
||||||
|
ctx.ProblemDetails.Extensions.TryAdd("exception", ctx.Exception?.ToString());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
if (builder.Environment.IsStaging() || builder.Environment.IsProduction())
|
if (builder.Environment.IsStaging() || builder.Environment.IsProduction())
|
||||||
{
|
{
|
||||||
builder.Configuration.AddAzureAppConfiguration(
|
builder.Configuration.AddAzureAppConfiguration(
|
||||||
|
@ -92,21 +107,27 @@ app.UseHttpLogging();
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
app.UseBlazorFrameworkFiles();
|
app.UseBlazorFrameworkFiles();
|
||||||
app.UseStaticFiles(new StaticFileOptions {ServeUnknownFileTypes = true});
|
app.UseStaticFiles(new StaticFileOptions {ServeUnknownFileTypes = true});
|
||||||
|
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
app.UseAntiforgery();
|
app.UseAntiforgery();
|
||||||
app.MapRazorComponents<App>()
|
app.MapRazorComponents<App>()
|
||||||
.AddAdditionalAssemblies(typeof(Counter).Assembly)
|
.AddAdditionalAssemblies(typeof(Counter).Assembly)
|
||||||
|
.AddAdditionalAssemblies(typeof(AsyncEventHandler).Assembly)
|
||||||
.AddInteractiveServerRenderMode()
|
.AddInteractiveServerRenderMode()
|
||||||
.AddInteractiveWebAssemblyRenderMode();
|
.AddInteractiveWebAssemblyRenderMode();
|
||||||
|
|
||||||
app.MapControllers();
|
app.UseExceptionHandler();
|
||||||
app.MapFallback(
|
app.MapFallback(
|
||||||
ctx =>
|
ctx =>
|
||||||
{
|
{
|
||||||
ctx.Response.Redirect($"/NotFound?path={ctx.Request.Path}");
|
ctx.Response.StatusCode = StatusCodes.Status404NotFound;
|
||||||
|
var headers = ctx.Request.GetTypedHeaders();
|
||||||
|
if (headers.Accept.Any(h => h.MatchesMediaType("text/html")))
|
||||||
|
{
|
||||||
|
ctx.Response.Redirect($"/NotFound?path={ctx.Request.Path}");
|
||||||
|
}
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue