Skip to content
Open
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
6 changes: 6 additions & 0 deletions UltimateAuth.slnx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<Solution>
<Folder Name="/Packages/">
<Project Path="nuget/CodeBeam.UltimateAuth.EntityFrameworkCore/CodeBeam.UltimateAuth.EntityFrameworkCore.csproj" Id="764569b4-dd5b-4a18-a332-7307d20ee21a" />
<Project Path="nuget/CodeBeam.UltimateAuth.InMemory/CodeBeam.UltimateAuth.InMemory.csproj" />
</Folder>
<Folder Name="/Samples/">
<Project Path="samples/blazor-server/CodeBeam.UltimateAuth.Sample.BlazorServer/CodeBeam.UltimateAuth.Sample.BlazorServer.csproj" />
<Project Path="samples/blazor-standalone-wasm/CodeBeam.UltimateAuth.Sample.BlazorStandaloneWasm/CodeBeam.UltimateAuth.Sample.BlazorStandaloneWasm.csproj" Id="27bd3c4d-65a9-4c70-a6c9-4178b1897730" />
Expand All @@ -12,6 +16,7 @@
<Folder Name="/Tests/">
<Project Path="tests/CodeBeam.UltimateAuth.Tests.Unit/CodeBeam.UltimateAuth.Tests.Unit.csproj" Id="6f4b22da-849a-4a79-b5c5-aee7cb1429a6" />
</Folder>
<Project Path="src/authentication/CodeBeam.UltimateAuth.Authentication.EntityFrameworkCore/CodeBeam.UltimateAuth.Authentication.EntityFrameworkCore.csproj" Id="a8d758ad-052e-4331-9bf7-280ea9a55981" />
<Project Path="src/authentication/CodeBeam.UltimateAuth.Authentication.InMemory/CodeBeam.UltimateAuth.Authentication.InMemory.csproj" Id="bd87e254-0565-4fc5-950d-ee5bbb416079" />
<Project Path="src/authorization/CodeBeam.UltimateAuth.Authorization.Contracts/CodeBeam.UltimateAuth.Authorization.Contracts.csproj" Id="40a23002-f885-42a8-bdd9-fd962ab28742" />
<Project Path="src/authorization/CodeBeam.UltimateAuth.Authorization.EntityFrameworkCore/CodeBeam.UltimateAuth.Authorization.EntityFrameworkCore.csproj" Id="8572d1e8-db32-42a1-b61c-e8805e59c019" />
Expand All @@ -28,6 +33,7 @@
<Project Path="src/credentials/CodeBeam.UltimateAuth.Credentials.Reference/CodeBeam.UltimateAuth.Credentials.Reference.csproj" Id="ca03a140-f3dc-4a21-9b7d-895a3b10808b" />
<Project Path="src/credentials/CodeBeam.UltimateAuth.Credentials/CodeBeam.UltimateAuth.Credentials.csproj" Id="2281c3b5-1d60-4542-a673-553f96eed25b" />
<Project Path="src/persistence/CodeBeam.UltimateAuth.EntityFrameworkCore.Abstractions/CodeBeam.UltimateAuth.EntityFrameworkCore.Abstractions.csproj" Id="8867767d-bd1b-4d51-ac3f-0979038165c9" />
<Project Path="src/persistence/CodeBeam.UltimateAuth.InMemory.Abstractions/CodeBeam.UltimateAuth.InMemory.Abstractions.csproj" Id="68de660f-3eb8-4922-b8eb-7ad7c97217ab" />
<Project Path="src/policies/CodeBeam.UltimateAuth.Policies/CodeBeam.UltimateAuth.Policies.csproj" Id="b37c337f-2446-4f54-8684-b72fa83ac444" />
<Project Path="src/security/CodeBeam.UltimateAuth.Security.Argon2/CodeBeam.UltimateAuth.Security.Argon2.csproj" Id="6abfb7a6-ea36-42db-a843-38054dd40fd8" />
<Project Path="src/sessions/CodeBeam.UltimateAuth.Sessions.EntityFrameworkCore/CodeBeam.UltimateAuth.Sessions.EntityFrameworkCore.csproj" Id="5b9a090d-1689-4a81-9dfa-3ba69f0bda38" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>0.1.0-preview.1</Version>
<InformationalVersion>0.1.0-preview.1</InformationalVersion>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\authentication\CodeBeam.UltimateAuth.Authentication.EntityFrameworkCore\CodeBeam.UltimateAuth.Authentication.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\src\authorization\CodeBeam.UltimateAuth.Authorization.EntityFrameworkCore\CodeBeam.UltimateAuth.Authorization.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\src\authorization\CodeBeam.UltimateAuth.Authorization.Reference\CodeBeam.UltimateAuth.Authorization.Reference.csproj" />
<ProjectReference Include="..\..\src\credentials\CodeBeam.UltimateAuth.Credentials.EntityFrameworkCore\CodeBeam.UltimateAuth.Credentials.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\src\credentials\CodeBeam.UltimateAuth.Credentials.Reference\CodeBeam.UltimateAuth.Credentials.Reference.csproj" />
<ProjectReference Include="..\..\src\sessions\CodeBeam.UltimateAuth.Sessions.EntityFrameworkCore\CodeBeam.UltimateAuth.Sessions.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\src\tokens\CodeBeam.UltimateAuth.Tokens.EntityFrameworkCore\CodeBeam.UltimateAuth.Tokens.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\src\users\CodeBeam.UltimateAuth.Users.EntityFrameworkCore\CodeBeam.UltimateAuth.Users.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\src\users\CodeBeam.UltimateAuth.Users.Reference\CodeBeam.UltimateAuth.Users.Reference.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using Microsoft.EntityFrameworkCore;

namespace CodeBeam.UltimateAuth.EntityFrameworkCore
{
/// <summary>
/// Provides configuration options for setting up Entity Framework Core database contexts used by the UltimateAuth
/// system.
/// </summary>
/// <remarks>Use this class to specify delegates that configure the options for various DbContext
/// instances, such as Users, Credentials, Authorization, Sessions, Tokens, and Authentication. Each property allows
/// customization of the corresponding context's setup, including database provider and connection details. If a
/// specific configuration delegate is not set for a context, the default configuration is applied. This class is
/// typically configured during application startup to ensure consistent and flexible database context
/// initialization.</remarks>
public sealed class UAuthEfCoreOptions
{
/// <summary>
/// Gets or sets the default action to configure the database context options builder.
/// </summary>
/// <remarks>Use this property to specify a delegate that applies default configuration to a
/// DbContextOptionsBuilder instance. This action is typically invoked when setting up a new database context to
/// ensure consistent configuration across the application.</remarks>
public Action<DbContextOptionsBuilder>? Default { get; set; }


/// <summary>
/// Gets or sets the delegate used to configure options for the Users DbContext.
/// If not set, default option will implement.
/// </summary>
/// <remarks>Assign a delegate to customize the configuration of the Users DbContext, such as
/// specifying the database provider or connection string. This property is typically used during application
/// startup to control how the Users context is set up.</remarks>
public Action<DbContextOptionsBuilder>? Users { get; set; }

/// <summary>
/// Gets or sets the delegate used to configure options for the Credentials DbContext.
/// If not set, default option will implement.
/// </summary>
/// <remarks>Assign a delegate to customize the configuration of the Credentials DbContext, such as
/// specifying the database provider or connection string. This property is typically used during application
/// startup to control how the Credentials context is set up.</remarks>
public Action<DbContextOptionsBuilder>? Credentials { get; set; }

/// <summary>
/// Gets or sets the delegate used to configure options for the Authorization DbContext.
/// If not set, default option will implement.
/// </summary>
/// <remarks>Assign a delegate to customize the configuration of the Authorization DbContext, such as
/// specifying the database provider or connection string. This property is typically used during application
/// startup to control how the Authorization context is set up.</remarks>
public Action<DbContextOptionsBuilder>? Authorization { get; set; }

/// <summary>
/// Gets or sets the delegate used to configure options for the Sessions DbContext.
/// If not set, default option will implement.
/// </summary>
/// <remarks>Assign a delegate to customize the configuration of the Sessions DbContext, such as
/// specifying the database provider or connection string. This property is typically used during application
/// startup to control how the Sessions context is set up.</remarks>
public Action<DbContextOptionsBuilder>? Sessions { get; set; }

/// <summary>
/// Gets or sets the delegate used to configure options for the Tokens DbContext.
/// If not set, default option will implement.
/// </summary>
/// <remarks>Assign a delegate to customize the configuration of the Tokens DbContext, such as
/// specifying the database provider or connection string. This property is typically used during application
/// startup to control how the Tokens context is set up.</remarks>
public Action<DbContextOptionsBuilder>? Tokens { get; set; }

/// <summary>
/// Gets or sets the delegate used to configure options for the Authentication DbContext.
/// If not set, default option will implement.
/// </summary>
/// <remarks>Assign a delegate to customize the configuration of the Authentication DbContext, such as
/// specifying the database provider or connection string. This property is typically used during application
/// startup to control how the Authentication context is set up.</remarks>
public Action<DbContextOptionsBuilder>? Authentication { get; set; }

internal Action<DbContextOptionsBuilder> Resolve(Action<DbContextOptionsBuilder>? specific)
=> specific ?? Default ?? throw new InvalidOperationException("No database configuration provided for UltimateAuth EFCore. Use options.Default or configure specific DbContext options.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using CodeBeam.UltimateAuth.Authentication.EntityFrameworkCore.Extensions;
using CodeBeam.UltimateAuth.Authorization.EntityFrameworkCore.Extensions;
using CodeBeam.UltimateAuth.Authorization.Reference.Extensions;
using CodeBeam.UltimateAuth.Credentials.EntityFrameworkCore.Extensions;
using CodeBeam.UltimateAuth.Credentials.Reference.Extensions;
using CodeBeam.UltimateAuth.Sessions.EntityFrameworkCore.Extensions;
using CodeBeam.UltimateAuth.Tokens.EntityFrameworkCore.Extensions;
using CodeBeam.UltimateAuth.Users.EntityFrameworkCore.Extensions;
using CodeBeam.UltimateAuth.Users.Reference.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;

namespace CodeBeam.UltimateAuth.EntityFrameworkCore;

/// <summary>
/// Provides extension methods for registering UltimateAuth with Entity Framework Core-based persistence using reference
/// domain implementations.
/// </summary>
public static class UltimateAuthEntityFrameworkCoreExtensions
{
/// <summary>
/// Registers UltimateAuth with Entity Framework Core based persistence using reference domain implementations.
/// </summary>
/// <param name="services">The service collection.</param>
/// <param name="configureDb">
/// A delegate used to configure the <see cref="DbContextOptionsBuilder"/> for all UltimateAuth DbContexts.
///
/// This is required and must specify a database provider such as:
/// <list type="bullet">
/// <item><description>UseSqlServer</description></item>
/// <item><description>UseNpgsql</description></item>
/// <item><description>UseSqlite</description></item>
/// </list>
/// </param>
/// <returns>The updated <see cref="IServiceCollection"/>.</returns>
/// <remarks>
/// This method wires up all Entity Framework Core stores along with reference domain implementations.
///
/// Example:
/// <code>
/// services.AddUltimateAuthServer()
/// .AddEntityFrameworkReference(options =>
/// {
/// options.UseSqlServer("connection-string");
/// });
/// </code>
///
/// Note:
/// This method does not configure migrations automatically. You are responsible for managing migrations.
/// </remarks>
public static IServiceCollection AddEntityFrameworkReference(this IServiceCollection services, Action<DbContextOptionsBuilder> configureDb)
{
services
.AddUltimateAuthUsersEntityFrameworkCore(configureDb)
.AddUltimateAuthUsersReference()
.AddUltimateAuthCredentialsEntityFrameworkCore(configureDb)
.AddUltimateAuthCredentialsReference()
.AddUltimateAuthAuthorizationEntityFrameworkCore(configureDb)
.AddUltimateAuthAuthorizationReference()
.AddUltimateAuthSessionsEntityFrameworkCore(configureDb)
.AddUltimateAuthTokensEntityFrameworkCore(configureDb)
.AddUltimateAuthAuthenticationEntityFrameworkCore(configureDb);

return services;
}

/// <summary>
/// Adds and configures Entity Framework Core-based UltimateAuth services and related references to the specified
/// service collection.
/// </summary>
/// <remarks>This method registers all required UltimateAuth services for users, credentials,
/// authorization, sessions, tokens, and authentication using Entity Framework Core. It should be called during
/// application startup as part of service configuration.</remarks>
/// <param name="services">The service collection to which the UltimateAuth Entity Framework Core services and references will be added.</param>
/// <param name="configure">A delegate that configures the options for UltimateAuth Entity Framework Core integration.</param>
/// <returns>The same service collection instance, enabling method chaining.</returns>
public static IServiceCollection AddEntityFrameworkReference(this IServiceCollection services, Action<UAuthEfCoreOptions> configure)
{
var options = new UAuthEfCoreOptions();
configure(options);

services
.AddUltimateAuthUsersEntityFrameworkCore(options.Resolve(options.Users))
.AddUltimateAuthUsersReference()
.AddUltimateAuthCredentialsEntityFrameworkCore(options.Resolve(options.Credentials))
.AddUltimateAuthCredentialsReference()
.AddUltimateAuthAuthorizationEntityFrameworkCore(options.Resolve(options.Authorization))
.AddUltimateAuthAuthorizationReference()
.AddUltimateAuthSessionsEntityFrameworkCore(options.Resolve(options.Sessions))
.AddUltimateAuthTokensEntityFrameworkCore(options.Resolve(options.Tokens))
.AddUltimateAuthAuthenticationEntityFrameworkCore(options.Resolve(options.Authentication));

return services;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>0.1.0-preview.1</Version>
<InformationalVersion>0.1.0-preview.1</InformationalVersion>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\authentication\CodeBeam.UltimateAuth.Authentication.InMemory\CodeBeam.UltimateAuth.Authentication.InMemory.csproj" />
<ProjectReference Include="..\..\src\authorization\CodeBeam.UltimateAuth.Authorization.InMemory\CodeBeam.UltimateAuth.Authorization.InMemory.csproj" />
<ProjectReference Include="..\..\src\authorization\CodeBeam.UltimateAuth.Authorization.Reference\CodeBeam.UltimateAuth.Authorization.Reference.csproj" />
<ProjectReference Include="..\..\src\credentials\CodeBeam.UltimateAuth.Credentials.InMemory\CodeBeam.UltimateAuth.Credentials.InMemory.csproj" />
<ProjectReference Include="..\..\src\credentials\CodeBeam.UltimateAuth.Credentials.Reference\CodeBeam.UltimateAuth.Credentials.Reference.csproj" />
<ProjectReference Include="..\..\src\sessions\CodeBeam.UltimateAuth.Sessions.InMemory\CodeBeam.UltimateAuth.Sessions.InMemory.csproj" />
<ProjectReference Include="..\..\src\tokens\CodeBeam.UltimateAuth.Tokens.InMemory\CodeBeam.UltimateAuth.Tokens.InMemory.csproj" />
<ProjectReference Include="..\..\src\users\CodeBeam.UltimateAuth.Users.InMemory\CodeBeam.UltimateAuth.Users.InMemory.csproj" />
<ProjectReference Include="..\..\src\users\CodeBeam.UltimateAuth.Users.Reference\CodeBeam.UltimateAuth.Users.Reference.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Microsoft.Extensions.DependencyInjection;
using CodeBeam.UltimateAuth.Credentials.InMemory.Extensions;
using CodeBeam.UltimateAuth.Credentials.Reference.Extensions;
using CodeBeam.UltimateAuth.Users.InMemory.Extensions;
using CodeBeam.UltimateAuth.Users.Reference.Extensions;
using CodeBeam.UltimateAuth.Authorization.InMemory.Extensions;
using CodeBeam.UltimateAuth.Authorization.Reference.Extensions;
using CodeBeam.UltimateAuth.Sessions.InMemory.Extensions;
using CodeBeam.UltimateAuth.Tokens.InMemory.Extensions;
using CodeBeam.UltimateAuth.Authentication.InMemory.Extensions;

namespace CodeBeam.UltimateAuth.InMemory;

/// <summary>
/// Provides extension methods for registering in-memory implementations of UltimateAuth user, credential,
/// authorization, session, token, and authentication services, along with their reference services, in the dependency
/// injection container.
/// </summary>
/// <remarks>These methods are intended for scenarios such as testing or development where in-memory storage is
/// sufficient. For production environments, consider using persistent storage implementations.</remarks>
public static class UltimateAuthInMemoryExtensions
{
/// <summary>
/// Registers in-memory implementations of UltimateAuth user, credential, authorization, session, token, and
/// authentication services, along with their reference services, in the dependency injection container.
/// </summary>
/// <remarks>This method is intended for scenarios such as testing or development where in-memory storage
/// is sufficient. For production environments, consider using persistent storage implementations.</remarks>
/// <param name="services">The service collection to which the in-memory UltimateAuth services will be added.</param>
/// <returns>The same instance of <see cref="IServiceCollection"/> that was provided, to support method chaining.</returns>
public static IServiceCollection AddInMemoryReference(this IServiceCollection services)
{
services
.AddUltimateAuthUsersInMemory()
.AddUltimateAuthUsersReference()
.AddUltimateAuthCredentialsInMemory()
.AddUltimateAuthCredentialsReference()
.AddUltimateAuthAuthorizationInMemory()
.AddUltimateAuthAuthorizationReference()
.AddUltimateAuthSessionsInMemory()
.AddUltimateAuthTokensInMemory()
.AddUltimateAuthAuthenticationInMemory();

return services;
}
}
Loading
Loading