diff --git a/admin/TwoWeeksReady.Admin/Pages/HazardHunts/List.razor b/admin/TwoWeeksReady.Admin/Pages/HazardHunts/List.razor index bcfea27..753ece8 100644 --- a/admin/TwoWeeksReady.Admin/Pages/HazardHunts/List.razor +++ b/admin/TwoWeeksReady.Admin/Pages/HazardHunts/List.razor @@ -43,7 +43,12 @@ else protected override async Task OnInitializedAsync() { - _HazardHunts = await Repository.GetAllHazardHunts(); + try { + _HazardHunts = await Repository.GetAllHazardHunts(); + } catch (NotImplementedException) { + // Application is still growing, let's not throw an error yet + _HazardHunts = Enumerable.Empty(); + } } diff --git a/admin/TwoWeeksReady.Admin/Pages/HazardInfos/List.razor b/admin/TwoWeeksReady.Admin/Pages/HazardInfos/List.razor index 938e39e..2d82d48 100644 --- a/admin/TwoWeeksReady.Admin/Pages/HazardInfos/List.razor +++ b/admin/TwoWeeksReady.Admin/Pages/HazardInfos/List.razor @@ -37,6 +37,7 @@ else if (_HazardInfos == null) else {

No hazard infos defined

+ Add New Hazard } @code { diff --git a/admin/TwoWeeksReady.Admin/Pages/Kits/List.razor b/admin/TwoWeeksReady.Admin/Pages/Kits/List.razor index 1a1fd59..7e42741 100644 --- a/admin/TwoWeeksReady.Admin/Pages/Kits/List.razor +++ b/admin/TwoWeeksReady.Admin/Pages/Kits/List.razor @@ -47,7 +47,13 @@ else protected override async Task OnInitializedAsync() { - BaseKits = await Repository.GetAllBaseKits(); + try { + BaseKits = await Repository.GetAllBaseKits(); + } catch (NotImplementedException) + { + // do nothing for now... site is still growing + BaseKits = Enumerable.Empty(); + } } diff --git a/admin/TwoWeeksReady.Admin/Program.cs b/admin/TwoWeeksReady.Admin/Program.cs index 0e145a5..3391fa0 100644 --- a/admin/TwoWeeksReady.Admin/Program.cs +++ b/admin/TwoWeeksReady.Admin/Program.cs @@ -1,26 +1,32 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; - -namespace TwoWeeksReady.Admin +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Web; +using TwoWeeksReady.Admin; + +var builder = WebApplication.CreateBuilder(args); + +// Configure the container. +builder.Services.ConfigureServices(builder.Configuration); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (!app.Environment.IsDevelopment()) { - public class Program - { - public static void Main(string[] args) - { - CreateHostBuilder(args).Build().Run(); - } - - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); - } + app.UseExceptionHandler("/Error"); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); } + +app.UseHttpsRedirection(); +app.UseStaticFiles(); + +app.UseRouting(); + +app.UseCookiePolicy(); +app.UseAuthentication(); +app.UseAuthorization(); + +app.MapBlazorHub(); +app.MapFallbackToPage("/_Host"); + +app.Run(); diff --git a/admin/TwoWeeksReady.Admin/Startup.cs b/admin/TwoWeeksReady.Admin/Startup.cs index 4e96986..3cf407f 100644 --- a/admin/TwoWeeksReady.Admin/Startup.cs +++ b/admin/TwoWeeksReady.Admin/Startup.cs @@ -15,137 +15,100 @@ using System; using System.Net.Http; -namespace TwoWeeksReady.Admin +namespace TwoWeeksReady.Admin; + +public static class StartupExtensions { - public class Startup + public static IServiceCollection ConfigureServices(this IServiceCollection services, IConfiguration configuration) { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } + services.AddRazorPages(); + services.AddServerSideBlazor(); - // This method gets called by the runtime. Use this method to add services to the container. - // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 - public void ConfigureServices(IServiceCollection services) + services.Configure(options => { - services.AddRazorPages(); - services.AddServerSideBlazor(); + options.CheckConsentNeeded = context => true; + options.MinimumSameSitePolicy = SameSiteMode.None; + }); - services.Configure(options => - { - options.CheckConsentNeeded = context => true; - options.MinimumSameSitePolicy = SameSiteMode.None; - }); + // Add authentication services + services.AddAuthentication(options => + { + options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme; + options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; + options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme; + }) + .AddCookie() + .AddOpenIdConnect("Auth0", options => + { + options.Authority = $"https://{configuration["Auth0:Domain"]}"; - // Add authentication services - services.AddAuthentication(options => - { - options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme; - options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; - options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme; - }) - .AddCookie() - .AddOpenIdConnect("Auth0", options => - { - options.Authority = $"https://{Configuration["Auth0:Domain"]}"; + options.ClientId = configuration["Auth0:ClientId"]; + options.ClientSecret = configuration["Auth0:ClientSecret"]; - options.ClientId = Configuration["Auth0:ClientId"]; - options.ClientSecret = Configuration["Auth0:ClientSecret"]; + options.ResponseType = OpenIdConnectResponseType.Code; + options.SaveTokens = true; - options.ResponseType = OpenIdConnectResponseType.Code; - options.SaveTokens = true; + options.Scope.Clear(); + options.Scope.Add("openid"); + options.Scope.Add("profile"); - options.Scope.Clear(); - options.Scope.Add("openid"); - options.Scope.Add("profile"); + options.CallbackPath = new PathString("/callback"); + options.ClaimsIssuer = "Auth0"; - options.CallbackPath = new PathString("/callback"); - options.ClaimsIssuer = "Auth0"; + options.TokenValidationParameters = new TokenValidationParameters + { + NameClaimType = "name", + RoleClaimType = "https://schemas.2wradmin.com/roles" + }; - options.TokenValidationParameters = new TokenValidationParameters + options.Events = new OpenIdConnectEvents + { + OnRedirectToIdentityProvider = context => { - NameClaimType = "name", - RoleClaimType = "https://schemas.2wradmin.com/roles" - }; - - options.Events = new OpenIdConnectEvents + // The context's ProtocolMessage can be used to pass along additional query parameters + // to Auth0's /authorize endpoint. + // + // Set the audience query parameter to the API identifier to ensure the returned Access Tokens can be used + // to call protected endpoints on the corresponding API. + context.ProtocolMessage.SetParameter("audience", configuration["Auth0:Audience"]); + + return Task.FromResult(0); + }, + OnRedirectToIdentityProviderForSignOut = (context) => { - OnRedirectToIdentityProvider = context => - { - // The context's ProtocolMessage can be used to pass along additional query parameters - // to Auth0's /authorize endpoint. - // - // Set the audience query parameter to the API identifier to ensure the returned Access Tokens can be used - // to call protected endpoints on the corresponding API. - context.ProtocolMessage.SetParameter("audience", Configuration["Auth0:Audience"]); - - return Task.FromResult(0); - }, - OnRedirectToIdentityProviderForSignOut = (context) => - { - var logoutUri = $"https://{Configuration["Auth0:Domain"]}/v2/logout?client_id={Configuration["Auth0:ClientId"]}"; + var logoutUri = $"https://{configuration["Auth0:Domain"]}/v2/logout?client_id={configuration ["Auth0:ClientId"]}"; - var postLogoutUri = context.Properties.RedirectUri; + var postLogoutUri = context.Properties.RedirectUri; - if (!string.IsNullOrEmpty(postLogoutUri)) + if (!string.IsNullOrEmpty(postLogoutUri)) + { + if (postLogoutUri.StartsWith("/")) { - if (postLogoutUri.StartsWith("/")) - { - var request = context.Request; - postLogoutUri = request.Scheme + "://" + request.Host + request.PathBase + postLogoutUri; - } + var request = context.Request; + postLogoutUri = request.Scheme + "://" + request.Host + request.PathBase + postLogoutUri; } + } - context.Response.Redirect(logoutUri); - context.HandleResponse(); - - return Task.CompletedTask; - } - }; - }); + context.Response.Redirect(logoutUri); + context.HandleResponse(); - services.AddHttpContextAccessor(); - services.AddHttpClient("ApiClient", (HttpClient client) => - { - client.BaseAddress = new Uri(Configuration["ApiUrl"]); - }); - - services.AddScoped(); - //services.AddScoped(); - services.AddScoped(); - services.AddSingleton(); - } + return Task.CompletedTask; + } + }; + }); - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + services.AddHttpContextAccessor(); + services.AddHttpClient("ApiClient", (HttpClient client) => { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - } - else - { - app.UseExceptionHandler("/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); - } - - app.UseHttpsRedirection(); - app.UseStaticFiles(); - - app.UseRouting(); + client.BaseAddress = new Uri(configuration["ApiUrl"]); + }); - app.UseCookiePolicy(); - app.UseAuthentication(); - app.UseAuthorization(); + services.AddScoped(); + //services.AddScoped(); + services.AddScoped(); + services.AddSingleton(); - app.UseEndpoints(endpoints => - { - endpoints.MapBlazorHub(); - endpoints.MapFallbackToPage("/_Host"); - }); - } + return services; } + } diff --git a/admin/TwoWeeksReady.Admin/TwoWeeksReady.Admin.csproj b/admin/TwoWeeksReady.Admin/TwoWeeksReady.Admin.csproj index f25e619..b83dcb5 100644 --- a/admin/TwoWeeksReady.Admin/TwoWeeksReady.Admin.csproj +++ b/admin/TwoWeeksReady.Admin/TwoWeeksReady.Admin.csproj @@ -1,8 +1,9 @@  - net5.0 + net6.0 4c82d094-3afe-4274-922b-9c0d8bdda7c5 + enable @@ -16,7 +17,7 @@ - +