Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/AdaskoTheBeAsT/AdaskoTheBeAsT.Identity.Dapper

Dapper implementation for Microsoft.Extensions.Identity.Stores
https://github.com/AdaskoTheBeAsT/AdaskoTheBeAsT.Identity.Dapper

Last synced: 3 months ago
JSON representation

Dapper implementation for Microsoft.Extensions.Identity.Stores

Awesome Lists containing this project

README

        

# AdaskoTheBeAsT.Identity.Dapper

Custom Dapper implementation for Microsoft.Extensions.Identity.Stores using Source Code Generators.
[https://learn.microsoft.com/en-us/aspnet/core/security/authentication/identity-custom-storage-providers?view=aspnetcore-7.0](https://learn.microsoft.com/en-us/aspnet/core/security/authentication/identity-custom-storage-providers?view=aspnetcore-7.0).

It allows to customize classes which are used by Microsoft Identity and generate Dapper code for them.
Schema of database needs to be created manually but queries are generated based automatically.
User can change schema from default 'dbo' to any other.
User can also skip NormalizedUserName, NormalizedEmail and NormalizedName columns in database and queries.

Sample using nuget within project is available here [Sample](https://github.com/AdaskoTheBeAsT/AdaskoTheBeAsT.Identity.Dapper/tree/main/samples/Sample.SqlServer2).

## Usage

1. In your project add nuget packages

```xml







```

1. Add following property groups to your project file

```xml


true

Generated

id

true

```

1. Add following item groups

```xml






```

1. To your project add following classes which inherits from Microsoft Identity classes

```csharp
using Microsoft.AspNetCore.Identity;

namespace Sample.SqlServer;

public class ApplicationRole
: IdentityRole
{
}

public class ApplicationRoleClaim
: IdentityRoleClaim
{
}

// attribute is optional
// if you want to use your own Id type you can use this attribute
// it is helpful when for example you want to store MSAL user id
// as your id
[InsertOwnIdAttribute]
public class ApplicationUser
: IdentityUser
{
[Column("IsActive")]
public bool Active { get; set; }
}

public class ApplicationUserClaim
: IdentityUserClaim
{
}

public class ApplicationUserLogin
: IdentityUserLogin
{
}

public class ApplicationUserRole
: IdentityUserRole
{
}

public class ApplicationUserToken
: IdentityUserToken
{
}
```

1. Recompile your project

1. You should see generated files in Generated folder

![Sample output](./doc/output.png)