KenHaggerty.Com.SingleUser 1.0.0-rc

This is a prerelease version of KenHaggerty.Com.SingleUser.
There is a newer version of this package available.
See the version list below for details.
dotnet add package KenHaggerty.Com.SingleUser --version 1.0.0-rc
NuGet\Install-Package KenHaggerty.Com.SingleUser -Version 1.0.0-rc
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="KenHaggerty.Com.SingleUser" Version="1.0.0-rc" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add KenHaggerty.Com.SingleUser --version 1.0.0-rc
#r "nuget: KenHaggerty.Com.SingleUser, 1.0.0-rc"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install KenHaggerty.Com.SingleUser as a Cake Addin
#addin nuget:?package=KenHaggerty.Com.SingleUser&version=1.0.0-rc&prerelease

// Install KenHaggerty.Com.SingleUser as a Cake Tool
#tool nuget:?package=KenHaggerty.Com.SingleUser&version=1.0.0-rc&prerelease

Features

  • A ServiceExtension which adds cookie authentication.
  • Middleware which adds authentication to the ApplicationBuilder.
  • Log In and Log Out pages reference the host's Shared/_Layout.cshtml.
  • A default Admin/Index page.
  • A _SingleUserLoginPartial.cshtml.
  • An optional password.

Quick Start

  1. Install KenHaggerty.Com.SingleUser.
  2. Edit the host web app's Startup.cs.
  3. Authorize the Admin folder.
  4. Add the _SingleUserLoginPartial to the host's Shared/_Layout.cshtml's navbar.
  5. Build, run, and test.
Host Startup.ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
    services.AddRazorPages();    
    services.AddSingleUser();
}
AddSingleUser Implements:
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
    .AddCookie(options =>
    {
        options.LoginPath = "/account/login";
        options.LogoutPath = "/account/logout";
        options.Cookie.SameSite = SameSiteMode.Strict;
        options.Cookie.SecurePolicy = CookieSecurePolicy.SameAsRequest;
        options.Cookie.IsEssential = true;
    });
Host Startup.Configure
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    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();

    app.UseSingleUserMiddleware();

    app.UseAuthorization();

    app.UseEndpoints(endpoints =>
    {
        endpoints.MapRazorPages();
    });
}
UseSingleUserMiddleware Implements:
app.UseAuthentication();
Log In and Log Out Pages

The Log In and Log Out pages are in an Account folder/path. All package pages reference the host's Shared/_Layout.cshtml.

Default Admin/Index Page

The host needs to authorize the Admin folder.

services.AddRazorPage(options => { options.Conventions.AuthorizeFolder("/Admin"); });

The default admin index page will be overridden by the host's Admin/Index page.

Host Shared/_Layout.cshtml

Insert _SingleUserLoginPartial into the host's navbar.

<div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">
    <partial name="_SingleUserLoginPartial" />
    <ul class="navbar-nav flex-grow-1">
        <li class="nav-item">
            <a class="nav-link text-dark" asp-area="" asp-page="/Admin/Index">Admin</a>
        </li>
    </ul>
</div>
_SingleUserLoginPartial.cshtml Implements:
<ul class="navbar-nav">
    @if (User.Identity.IsAuthenticated)
    {
        <li class="nav-item">
            <form class="form-inline" asp-page="/Account/LogOut" method="post">
                <button type="submit" class="nav-link text-dark btn btn-link pt-1">Log Out @User.Identity.Name</button>
            </form>
        </li>
    }
    else
    {
        <li class="nav-item">
            <a class="nav-link text-dark" asp-page="/Account/LogIn">Log In</a>
        </li>
    }
</ul>
Optional Password

A password is not required. For basic password support, add a SingleUserPassword key with your password to the host's appsettings.json's root.

KenHaggerty.Com

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net5.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.2 489 7/28/2021
2.1.1 412 7/26/2021
2.1.0 391 7/25/2021
2.0.1 397 1/18/2021
2.0.0 406 1/17/2021
1.0.2 413 11/22/2020
1.0.1-rc 297 10/17/2020
1.0.0-rc 362 10/6/2020

Initial Package