1
0
mirror of https://github.com/bitwarden/server synced 2026-01-06 10:34:01 +00:00

Add recipe for getting emergency access invites

This commit is contained in:
Hinton
2025-10-11 10:26:13 -07:00
parent 45ba8f83df
commit 1137857eba
4 changed files with 33 additions and 11 deletions

View File

@@ -0,0 +1,28 @@
using Bit.Core.Auth.Enums;
using Bit.Core.Auth.Models.Business.Tokenables;
using Bit.Core.Tokens;
using Bit.Infrastructure.EntityFramework.Repositories;
namespace Bit.Seeder.Recipes;
public class EmergencyAccessInviteRecipe(
DatabaseContext db,
IDataProtectorTokenFactory<EmergencyAccessInviteTokenable> dataProtectorTokenizer)
{
public RecipeResult Seed(string email)
{
var invites = db.EmergencyAccesses
.Where(ea => ea.Email == email).ToList().Select(ea =>
{
var token = dataProtectorTokenizer.Protect(
new EmergencyAccessInviteTokenable(ea, hoursTillExpiration: 1)
);
return $"/accept-emergency?id={ea.Id}&name=Dummy&email={ea.Email}&token={token}";
});
return new RecipeResult
{
Result = invites,
};
}
}

View File

@@ -13,22 +13,16 @@ builder.Services.AddControllers();
// Configure GlobalSettings from appsettings
var globalSettings = builder.Services.AddGlobalSettingsServices(builder.Configuration, builder.Environment);
// Data Protection
// Common services
builder.Services.AddCustomDataProtectionServices(builder.Environment, globalSettings);
// Repositories
builder.Services.AddTokenizers();
builder.Services.AddDatabaseRepositories(globalSettings, forceEf: true);
// Identity Services
builder.Services.AddScoped<Microsoft.AspNetCore.Identity.IPasswordHasher<Bit.Core.Entities.User>, Microsoft.AspNetCore.Identity.PasswordHasher<Bit.Core.Entities.User>>();
// RustSDK Services
// Seeder services
builder.Services.AddSingleton<Bit.RustSDK.RustSdkService>();
// Seeder Services
builder.Services.AddScoped<Bit.Seeder.Factories.UserSeeder>();
// Recipe Service
builder.Services.AddScoped<IRecipeService, RecipeService>();
var app = builder.Build();