Skip to content

Add ASP.NET Core Identity with OIDC/OAuth2 support #5

Description

@wendellmva

Summary

Add proper authentication with ASP.NET Core Identity and OIDC/OAuth2 support while maintaining backward compatibility with API key authentication.

Current State

  • Simple API key authentication only (X-NuGet-ApiKey header)
  • Single global API key from configuration
  • No user accounts or roles

Target State

  • ASP.NET Core Identity for user management
  • OIDC/OAuth2 for SSO integration
  • Per-user API keys stored in database
  • Backward compatible with existing API key auth

New Packages

  • Microsoft.AspNetCore.Identity.EntityFrameworkCore 9.0.0
  • Microsoft.AspNetCore.Authentication.OpenIdConnect 9.0.0

Tasks

  • Add Identity packages to BaGet.Core.csproj and BaGet.csproj
  • Create BaGetUser entity (extends IdentityUser)
  • Create UserApiKey entity for per-user API keys
  • Update AbstractContext to inherit from IdentityDbContext<BaGetUser>
  • Configure Identity in Startup.cs
  • Configure OIDC authentication
  • Create CompositeAuthenticationService (supports multiple auth methods)
  • Add Login/Logout Razor Pages
  • Add API Key management page
  • Generate database migration for Identity tables
  • Update authorization on controllers

New Entities

public class BaGetUser : IdentityUser
{
    public ICollection<UserApiKey> ApiKeys { get; set; }
}

public class UserApiKey
{
    public int Id { get; set; }
    public string Key { get; set; }
    public string Description { get; set; }
    public DateTime Created { get; set; }
    public DateTime? Expires { get; set; }
    public string UserId { get; set; }
    public BaGetUser User { get; set; }
}

Configuration

{
  "Authentication": {
    "Type": "None",
    "ApiKey": "",
    "OIDC": {
      "Authority": "",
      "ClientId": "",
      "ClientSecret": ""
    }
  }
}

Files to Modify

  • src/BaGet.Core/BaGet.Core.csproj
  • src/BaGet/BaGet.csproj
  • src/BaGet.Core/Entities/AbstractContext.cs
  • src/BaGet/Startup.cs
  • src/BaGet/appsettings.json
  • src/BaGet.Core/Authentication/ (new files)
  • src/BaGet.Web/Pages/Account/ (new pages)

Dependencies

  • Depends on .NET 9 upgrade
  • Depends on PostgreSQL migration

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium priorityfeatureNew feature

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions