Albatross.Authentication 9.0.1

Prefix Reserved
This package has a SemVer 2.0.0 package version: 9.0.1+a13e79e.
dotnet add package Albatross.Authentication --version 9.0.1
                    
NuGet\Install-Package Albatross.Authentication -Version 9.0.1
                    
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="Albatross.Authentication" Version="9.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Albatross.Authentication" Version="9.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Albatross.Authentication" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Albatross.Authentication --version 9.0.1
                    
#r "nuget: Albatross.Authentication, 9.0.1"
                    
#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.
#:package Albatross.Authentication@9.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Albatross.Authentication&version=9.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Albatross.Authentication&version=9.0.1
                    
Install as a Cake Tool

Albatross.Authentication

A comprehensive .NET library that provides a unified interface for retrieving the identity of the current user across different platforms and authentication mechanisms.

Features

  • Cross-platform user authentication - Unified interface that works across different environments
  • Multiple authentication providers - Support for Windows, ASP.NET Core, Google OAuth, and Active Directory
  • Extensible architecture - Easy to add new authentication providers through the ILoginFactory interface
  • Standardized user information - Consistent ILogin interface with Provider, Subject, and Name properties
  • Legacy support - Backward compatibility with IGetCurrentUser interface for existing applications
  • Dependency injection ready - Built-in support for Microsoft.Extensions.DependencyInjection

Core Interfaces

  • ILogin - Represents a user login with the following properties:
    • Provider: The authentication provider (e.g., "Windows", "https://accounts.google.com")
    • Subject: The unique identifier of the user
    • Name: The display name of the user
  • IGetCurrentLogin - Service interface that returns the login information of the current user
  • IGetCurrentUser - Legacy interface that returns the string identity of the current user (primarily used in Windows domain environments)
  • ILoginFactory - Factory interface for creating login instances from claims

Prerequisites

  • .NET Standard 2.0 or higher
  • dotnet SDK 8.0 or higher for building and development
  • Microsoft.Extensions.DependencyInjection (for dependency injection scenarios)

Platform-specific Requirements

  • Windows Authentication: Windows environment with System.Security.Principal.Windows package
  • ASP.NET Core Authentication: ASP.NET Core application with Microsoft.AspNetCore.App framework reference

Installation

Using .NET CLI

dotnet add package Albatross.Authentication

Using Package Manager Console

Install-Package Albatross.Authentication

Building from Source

# Clone the repository
git clone https://github.com/RushuiGuan/authentication.git
cd authentication

# Restore dependencies
dotnet restore

# Build the project
dotnet build

# Run tests (requires .NET 9.0 SDK)
dotnet test

Usage Examples

Basic Usage with Dependency Injection

using Microsoft.Extensions.DependencyInjection;
using Albatross.Authentication;

// Setup dependency injection
var services = new ServiceCollection();

// For Windows authentication
services.AddWindowsPrincipalProvider();

// For ASP.NET Core authentication
services.AddAspNetCorePrincipalProvider();

var serviceProvider = services.BuildServiceProvider();

// Get current user login information
var loginService = serviceProvider.GetRequiredService<IGetCurrentLogin>();
var login = loginService.Get();

if (login != null)
{
    Console.WriteLine($"Provider: {login.Provider}");
    Console.WriteLine($"Subject: {login.Subject}");
    Console.WriteLine($"Name: {login.Name}");
}

// Legacy interface for simple user name
var userService = serviceProvider.GetRequiredService<IGetCurrentUser>();
var userName = userService.Get();
Console.WriteLine($"Current User: {userName}");

Creating Custom Authentication Providers

using Albatross.Authentication;
using System.Security.Claims;

// Example: Custom Twitter authentication provider
public class TwitterLoginFactory : ILoginFactory
{
    public string Issuer => "https://twitter.com/i/oauth2/authorize";
    
    public Login Create(IEnumerable<Claim> claims)
    {
        var login = new Login("Twitter");
        foreach (var claim in claims)
        {
            switch (claim.Type)
            {
                case "name":
                    login.Name = claim.Value;
                    break;
                case "email":
                    login.Email = claim.Value;
                    break;
                case "sub":
                    login.Subject = claim.Value;
                    break;
            }
        }
        
        if (string.IsNullOrEmpty(login.Subject))
        {
            throw new InvalidOperationException(
                "Twitter JWT bearer token is missing sub claim. " +
                "Make sure the openid scope is included in the authentication request.");
        }
        
        return login;
    }
}

// Register the custom factory
services.TryAddEnumerable(ServiceDescriptor.Singleton<ILoginFactory, TwitterLoginFactory>());

ASP.NET Core Integration

using Albatross.Authentication.AspNetCore;

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        // Add ASP.NET Core authentication services
        services.AddAspNetCorePrincipalProvider();
        
        // Other service configuration...
    }
}

// In a controller or service
[ApiController]
public class UserController : ControllerBase
{
    private readonly IGetCurrentLogin _loginService;
    
    public UserController(IGetCurrentLogin loginService)
    {
        _loginService = loginService;
    }
    
    [HttpGet("current")]
    public IActionResult GetCurrentUser()
    {
        var login = _loginService.Get();
        return Ok(new { 
            Provider = login?.Provider,
            Subject = login?.Subject,
            Name = login?.Name 
        });
    }
}

Project Structure

authentication/
├── Albatross.Authentication/              # Core library (.NET Standard 2.0)
│   ├── ILogin.cs                         # Core login interface
│   ├── IGetCurrentLogin.cs               # Current login service interface
│   ├── IGetCurrentUser.cs                # Legacy user service interface
│   ├── ILoginFactory.cs                  # Login factory interface
│   └── README.md                         # This file
├── Albatross.Authentication.AspNetCore/   # ASP.NET Core implementation
│   ├── GetCurrentLoginFromHttpContext.cs # HttpContext-based login service
│   ├── GoogleLoginFactory.cs             # Google OAuth login factory
│   ├── OnPremiseActiveDirectoryLoginFactory.cs # AD login factory
│   └── Extensions.cs                     # Dependency injection extensions
├── Albatross.Authentication.Windows/      # Windows implementation
│   ├── GetCurrentWindowsLogin.cs         # Windows-based login service
│   ├── GetCurrentWindowsUser.cs          # Windows-based user service
│   └── Extensions.cs                     # Dependency injection extensions
├── Albatross.Authentication.UnitTest/     # Unit tests
├── Sample.Api/                           # Sample API application
└── README.md                             # Repository overview

Running Unit Tests

The project includes comprehensive unit tests to verify functionality across different authentication scenarios.

# Run all tests (requires .NET 9.0 SDK)
dotnet test

# Run specific test project
dotnet test Albatross.Authentication.UnitTest/Albatross.Authentication.UnitTest.csproj

# Run tests with detailed output
dotnet test --verbosity normal

Test Coverage

  • Windows authentication validation
  • Anonymous login scenarios
  • Claims-based authentication
  • Login factory implementations
  • HttpContext integration

Contributing

We welcome contributions to improve Albatross.Authentication! Here's how you can contribute:

Submitting Issues

  1. Check existing issues to avoid duplicates
  2. Use the issue template when creating new issues
  3. Provide clear reproduction steps and environment details
  4. Include relevant code samples when reporting bugs

Making Changes

  1. Fork the repository on GitHub
  2. Clone your fork locally:
    git clone https://github.com/YOUR-USERNAME/authentication.git
    
  3. Create a branch for your changes:
    git checkout -b feature/your-feature-name
    
  4. Make your changes following the existing code style
  5. Add or update tests for your changes
  6. Build and test locally:
    dotnet build
    dotnet test
    
  7. Commit your changes with a clear message:
    git commit -m "Add support for new authentication provider"
    
  8. Push to your fork and submit a pull request

Code Style Guidelines

  • Follow existing code formatting and naming conventions
  • Add XML documentation comments for public APIs
  • Include unit tests for new functionality
  • Keep changes focused and atomic
  • Update documentation when adding new features

License

This project is licensed under the MIT License - see the LICENSE file for details.

MIT License Summary

  • ✅ Commercial use
  • ✅ Modification
  • ✅ Distribution
  • ✅ Private use
  • ❌ Liability
  • ❌ Warranty

Albatross.Authentication - Developed and maintained by Rushui Guan

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Albatross.Authentication:

Package Downloads
Albatross.Authentication.AspNetCore

The assembly contains the AspNetCore implementation of IGetCurrentUser interface. It retrieves the current user name using AspNetCore HttpContext.

Albatross.Authentication.Windows

The assembly contains the Windows implementation of IGetCurrentUser interface. It retrieves the current window user name.

Albatross.EFCore.Audit

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
9.0.1 41 9/5/2025
9.0.0 39 7/15/2025
7.6.6-26.main 36 5/22/2025
7.6.5 59 5/4/2025
7.6.2 207 2/27/2025
7.6.0 96 12/28/2024
7.5.8 89 11/11/2024
7.5.7 74 11/11/2024
7.4.2 93 10/8/2024
7.2.6 121 5/17/2024
6.1.1 340 9/18/2023
4.0.2 853 10/18/2022
2.8.0 1,524 8/11/2021
2.3.6 782 2/23/2021
1.5.35 5,546 8/5/2020
1.5.34 2,004 7/29/2020