Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update BWA WinAuth sample app #478

Merged
merged 1 commit into from
Feb 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions 9.0/BlazorWebAppWinAuthServer/Components/ForceLogin.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@inject NavigationManager Navigation

@code {
protected override void OnInitialized()
{
Navigation.Refresh(forceReload: true);
}
}
32 changes: 15 additions & 17 deletions 9.0/BlazorWebAppWinAuthServer/Components/Layout/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,23 @@
</NavLink>
</div>

<AuthorizeView>
<div class="nav-item px-3">
<NavLink class="nav-link" href="weather">
<span class="bi bi-list-nested-nav-menu" aria-hidden="true"></span> Weather
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="weather">
<span class="bi bi-list-nested-nav-menu" aria-hidden="true"></span> Weather (Secure)
</NavLink>
</div>

<div class="nav-item px-3">
<NavLink class="nav-link" href="user-claims">
<span class="bi bi-list-nested-nav-menu" aria-hidden="true"></span> User Claims
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="user-claims">
<span class="bi bi-list-nested-nav-menu" aria-hidden="true"></span> User Claims (Secure)
</NavLink>
</div>

<div class="nav-item px-3">
<NavLink class="nav-link" href="local-account-only">
<span class="bi bi-list-nested-nav-menu" aria-hidden="true"></span> Local Account Only
</NavLink>
</div>
</AuthorizeView>
<div class="nav-item px-3">
<NavLink class="nav-link" href="local-account">
<span class="bi bi-list-nested-nav-menu" aria-hidden="true"></span> Local Account (Secure)
</NavLink>
</div>
</nav>
</div>

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@page "/local-account-only"
@page "/local-account"
@using Microsoft.AspNetCore.Authorization
@attribute [Authorize("LocalAccount")]

Expand Down
6 changes: 5 additions & 1 deletion 9.0/BlazorWebAppWinAuthServer/Components/Routes.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<Router AppAssembly="typeof(Program).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" />
<AuthorizeRouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)">
<NotAuthorized>
<ForceLogin />
</NotAuthorized>
</AuthorizeRouteView>
<FocusOnNavigate RouteData="routeData" Selector="h1" />
</Found>
</Router>
4 changes: 4 additions & 0 deletions 9.0/BlazorWebAppWinAuthServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
builder.Services.AddAuthentication(NegotiateDefaults.AuthenticationScheme)
.AddNegotiate();

// To require authentication for all users for the
// entire app, use the following code.
/*
builder.Services.AddAuthorization(options =>
{
options.FallbackPolicy = options.DefaultPolicy;
});
*/

builder.Services.AddCascadingAuthenticationState();

Expand Down