Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tetsuo13/aspnetcore.dataprotection.mysql
An extension library to assist with ASP.NET data protection using MySQL
https://github.com/tetsuo13/aspnetcore.dataprotection.mysql
asp-net-core data-protection
Last synced: about 3 hours ago
JSON representation
An extension library to assist with ASP.NET data protection using MySQL
- Host: GitHub
- URL: https://github.com/tetsuo13/aspnetcore.dataprotection.mysql
- Owner: tetsuo13
- License: mit
- Created: 2023-08-04T00:56:53.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-15T00:28:43.000Z (23 days ago)
- Last Synced: 2024-11-05T04:07:09.919Z (2 days ago)
- Topics: asp-net-core, data-protection
- Language: C#
- Homepage:
- Size: 56.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# ASP.NET Core Data Protection for MySQL
[![Continuous integration](https://github.com/tetsuo13/AspNetCore.DataProtection.MySql/actions/workflows/ci.yml/badge.svg)](https://github.com/tetsuo13/AspNetCore.DataProtection.MySql/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![AspNetCore.DataProtection.MySql](https://img.shields.io/nuget/v/AspNetCore.DataProtection.MySql.svg)](https://www.nuget.org/packages/AspNetCore.DataProtection.MySql/)An ASP.NET Core [Data Protection](https://learn.microsoft.com/en-us/aspnet/core/security/data-protection/introduction) provider for MySQL using [MySqlConnector](https://mysqlconnector.net/).
## Getting Started
```csharp
using AspNetCore.DataProtection.MySql;
using Microsoft.Extensions.DependencyInjection;public void ConfigureServices(IServiceCollection services)
{
services.AddDataProtection()
.PersistKeysToMySql();
}
```The schema for the `DataProtectionKeys` table is below. This table has to be created ahead of time as this library won't automatically create it. The table name can be changed (and supplied to the overloaded `.PersistKeysToMySql()` method) however the column names are expected to match the default schema.
```sql
CREATE TABLE DataProtectionKeys (
Id BIGINT NOT NULL AUTO_INCREMENT,
FriendlyName TEXT NULL,
Xml TEXT NULL,PRIMARY KEY CLUSTERED (Id ASC)
) DEFAULT CHARSET=utf8
COMMENT = 'Cryptographic keys for the data protection system';
```Note: See [key storage providers in ASP.NET Core](https://learn.microsoft.com/en-us/aspnet/core/security/data-protection/implementation/key-storage-providers) for other providers.
## Configuration
The overload to `.PersistKeysToMySql()` accepts a parameter to customize behavior:
```csharp
services.AddDataProtection()
.PersistKeysToMySql(options =>
{
// Change the default table name to something else.
options.TableName = "AlternateTableName";
});
```There are no options available to configure how it should connect to the database as it assumes that `MySqlConnection` has already been registered as a service dependency. As a result, it will request a `MySqlConnector` object from the service registry and run with it.
An example of how to register `MySqlConnector` as a service:
```csharp
var connectionString = configuration.GetValue("ConnectionStrings:ConnectionString");services.AddTransient(container =>
{
return new MySqlConnection(connectionString);
});
```## License
See [LICENSE](LICENSE) for more information.