Albatross.Authentication
9.0.1
Prefix Reserved
dotnet add package Albatross.Authentication --version 9.0.1
NuGet\Install-Package Albatross.Authentication -Version 9.0.1
<PackageReference Include="Albatross.Authentication" Version="9.0.1" />
<PackageVersion Include="Albatross.Authentication" Version="9.0.1" />
<PackageReference Include="Albatross.Authentication" />
paket add Albatross.Authentication --version 9.0.1
#r "nuget: Albatross.Authentication, 9.0.1"
#:package Albatross.Authentication@9.0.1
#addin nuget:?package=Albatross.Authentication&version=9.0.1
#tool nuget:?package=Albatross.Authentication&version=9.0.1
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 userName
: 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
- Check existing issues to avoid duplicates
- Use the issue template when creating new issues
- Provide clear reproduction steps and environment details
- Include relevant code samples when reporting bugs
Making Changes
- Fork the repository on GitHub
- Clone your fork locally:
git clone https://github.com/YOUR-USERNAME/authentication.git
- Create a branch for your changes:
git checkout -b feature/your-feature-name
- Make your changes following the existing code style
- Add or update tests for your changes
- Build and test locally:
dotnet build dotnet test
- Commit your changes with a clear message:
git commit -m "Add support for new authentication provider"
- 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 | Versions 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. |
-
.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 |