Skip to content

Commit

Permalink
🛠️ Scoping authentication scripts security own pages
Browse files Browse the repository at this point in the history
🔼 Updating dependencies
  • Loading branch information
xxnickles committed Feb 12, 2024
1 parent 0135a64 commit 64550cc
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="NSubstitute.Analyzers.CSharp" Version="1.0.16">
<PackageReference Include="NSubstitute.Analyzers.CSharp" Version="1.0.17">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage" Version="6.3.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues" Version="5.3.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.3.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.4" OutputItemType="Analyzer" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.17.0" OutputItemType="Analyzer" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.21.0" />
<PackageReference Include="SendGrid" Version="9.29.1" />
</ItemGroup>
Expand Down
20 changes: 3 additions & 17 deletions src/AnimeFeedManager.Web/Features/App.razor
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
@using Passwordless.Net
@using Microsoft.Extensions.Options
@inject IOptions<PasswordlessOptions> PasswordlessOptions

<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en">

<head>
Expand All @@ -14,6 +10,8 @@
<link rel="icon" type="image/png" href="favicon.png"/>
<script defer src="lib/htmx/htmx.min.js"></script>
<script defer src="lib/alpinejs/cdn.min.js"></script>
@* <script defer src="_framework/blazor.web.js"></script> *@
<SectionOutlet SectionName="additional-scripts"/>
<HeadOutlet/>
</head>

Expand All @@ -24,18 +22,6 @@
<div id="toast-panel" class="toast"></div>

<HtmxConfirm></HtmxConfirm>
@* <script src="_framework/blazor.web.js"></script> *@
<script>
const PASSWORDLESS_API_URL = "https://v4.passwordless.dev"; // For self-hosting, change this. This is always the default value.
const API_KEY = "@PasswordlessOptions.Value.ApiKey"; // Replace this value with your API Key
</script>

<script
defer
src="https://cdn.passwordless.dev/dist/1.1.0/umd/passwordless.umd.min.js"
crossorigin="anonymous"></script>

<script defer src="scripts/client-signin.js" type="module"></script>
</body>

</html>
21 changes: 18 additions & 3 deletions src/AnimeFeedManager.Web/Features/Security/Login.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
@using AnimeFeedManager.Features.Users.IO
@using Microsoft.AspNetCore.Authentication
@using Microsoft.AspNetCore.Authentication.Cookies
@using Microsoft.Extensions.Options
@using Passwordless.Net

@inject IPasswordlessLogin PasswordlessLogin;
@inject NavigationManager NavigationManager;
@inject ILogger<Login> Logger;
@inject IOptions<PasswordlessOptions> PasswordlessOptions

<PageTitle>@PageTitle("Login")</PageTitle>

Expand Down Expand Up @@ -72,6 +75,19 @@
</div>
</section>

<SectionContent SectionName="additional-scripts">
<script defer>
const PASSWORDLESS_API_URL = "https://v4.passwordless.dev"; // For self-hosting, change this. This is always the default value.
const API_KEY = "@PasswordlessOptions.Value.ApiKey"; // Replace this value with your API Key
</script>
<script
defer
src="https://cdn.passwordless.dev/dist/1.1.0/umd/passwordless.umd.min.js"
crossorigin="anonymous"></script>
<script defer src="scripts/client-signin.js" type="module"></script>
<script src="./Features/Security/Login.razor.js" type="text/javascript"></script>
</SectionContent>


@code {
[SupplyParameterFromForm] public string? Id { get; set; }
Expand All @@ -97,7 +113,7 @@

private async Task CompleteLogin(ClaimsPrincipal principal)
{
await HttpContext.SignInAsync(principal, new AuthenticationProperties {IsPersistent = true});
await HttpContext.SignInAsync(principal, new AuthenticationProperties { IsPersistent = true });
NavigationManager.NavigateTo("/");
}

Expand All @@ -115,7 +131,7 @@
new(ClaimTypes.Name, user),
new(ClaimTypes.Email, user),
new(CustomClaimTypes.Sub, id),
new (ClaimTypes.Role, role)
new(ClaimTypes.Role, role)
};

return
Expand All @@ -124,4 +140,3 @@

}

<script src="./Features/Security/Login.razor.js" type="text/javascript"></script>
20 changes: 17 additions & 3 deletions src/AnimeFeedManager.Web/Features/Security/Register.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
@page "/Register"
@using Passwordless.Net
@using Microsoft.Extensions.Options

@inject IOptions<PasswordlessOptions> PasswordlessOptions
@page "/Register"


<PageTitle>@PageTitle("Registration")</PageTitle>

Expand Down Expand Up @@ -63,5 +68,14 @@
</div>
</section>


<script src="./Features/Security/Register.razor.js" type="text/javascript"></script>
<SectionContent SectionName="additional-scripts">
<script defer>
const PASSWORDLESS_API_URL = "https://v4.passwordless.dev"; // For self-hosting, change this. This is always the default value.
const API_KEY = "@PasswordlessOptions.Value.ApiKey"; // Replace this value with your API Key
</script>
<script
defer
src="https://cdn.passwordless.dev/dist/1.1.0/umd/passwordless.umd.min.js"
crossorigin="anonymous"></script>
<script src="./Features/Security/Register.razor.js" type="text/javascript"></script>
</SectionContent>
8 changes: 5 additions & 3 deletions src/AnimeFeedManager.Web/Features/Tv/TvGrid.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
@inject TvLibraryGetter LibraryGetter;
@inject IUserProvider UserProvider;
@inject ILogger<TvGrid> Logger;
@* @attribute [StreamRendering] *@
@* @attribute [StreamRendering(true)] *@

<PageTitle>@PageTitleForSeason(SeriesType.Tv, _selectedSeason)</PageTitle>

<SeriesGrid Series="_animes" SeriesType="SeriesType.Tv" CurrentSeason="_selectedSeason"></SeriesGrid>


@code {

[CascadingParameter] public HttpContext context { get; set; } = default!;
Expand All @@ -31,7 +32,7 @@
var results = await LibraryGetter.GetForSeason(_selectedSeason.Season, _selectedSeason.Year)
.MapAsync(lib => MapForUser(lib, user))
.LogErrors(Logger);

_animes = results.Match(
collection => collection,
_ => []
Expand Down Expand Up @@ -62,4 +63,5 @@
};
}

}
}

3 changes: 2 additions & 1 deletion src/AnimeFeedManager.Web/Features/_Imports.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.AspNetCore.Components.Authorization
@using static Microsoft.AspNetCore.Components.Web.RenderMode
@using Microsoft.AspNetCore.Components.Sections
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.JSInterop
@using AnimeFeedManager.Web
Expand All @@ -25,4 +25,5 @@
@using LanguageExt;
@using static LanguageExt.Prelude;
@using static AnimeFeedManager.Web.Features.Common.Utils;
@using static Microsoft.AspNetCore.Components.Web.RenderMode

2 changes: 1 addition & 1 deletion src/AnimeFeedManager.WebApp/AnimeFeedManager.WebApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Blazored.LocalStorage" Version="4.4.0" />
<PackageReference Include="Blazored.LocalStorage" Version="4.5.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="8.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.1" PrivateAssets="all" />
Expand Down

0 comments on commit 64550cc

Please sign in to comment.