Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create options pattern for providing an XmlRepository for storing Data Protection keys. #59971

Open
1 task done
MrNathanStiles opened this issue Jan 21, 2025 · 2 comments
Open
1 task done
Labels
area-dataprotection Includes: DataProtection

Comments

@MrNathanStiles
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

There are several options for key persistence but none are generic. It would be beneficial to have a IXmlRepositoryProvider or something like what we have with ILoggerProvider. I think the existing option, KeyManagementOptions.XmlRepository, allows this but that property isn't really an option. The issue @ #2505
exposes the problem in the comment @ #2505 (comment)
We have no way to resolve services to be used as an XmlRepository

Describe the solution you'd like

Implement options pattern to provide an XmlRepository.

Additional context

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically label Jan 21, 2025
@martincostello martincostello added area-dataprotection Includes: DataProtection and removed needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically labels Jan 21, 2025
@justindbaur
Copy link
Contributor

This is how PersistKeysToDbContext works while getting access to services:

public static IDataProtectionBuilder PersistKeysToDbContext<TContext>(this IDataProtectionBuilder builder)
where TContext : DbContext, IDataProtectionKeyContext
{
builder.Services.AddSingleton<IConfigureOptions<KeyManagementOptions>>(services =>
{
var loggerFactory = services.GetService<ILoggerFactory>() ?? NullLoggerFactory.Instance;
return new ConfigureOptions<KeyManagementOptions>(options =>
{
options.XmlRepository = new EntityFrameworkCoreXmlRepository<TContext>(services, loggerFactory);
});
});

Would that work for your use?

@MrNathanStiles
Copy link
Author

Yes that does work. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-dataprotection Includes: DataProtection
Projects
None yet
Development

No branches or pull requests

3 participants