Coder Social home page Coder Social logo

mrahhal / mr.aspnet.identity.entityframework6 Goto Github PK

View Code? Open in Web Editor NEW
42.0 6.0 21.0 110 KB

EntityFramework 6 provider + InMemory providers for Asp.Net Core Identity.

License: MIT License

PowerShell 3.81% C# 96.16% CoffeeScript 0.03%
ef6 identity

mr.aspnet.identity.entityframework6's Introduction

MR.AspNet.Identity.EntityFramework6

Build status NuGet version License

EntityFramework 6 provider + InMemory providers for Asp.Net Core Identity.

What is this?

All you have to do in your app:

  • Remove everything EF Core related, this means: Microsoft.EntityFrameworkCore.Tools, Microsoft.EntityFrameworkCore.SqlServer, Microsoft.EntityFrameworkCore.InMemory and Microsoft.AspNetCore.Identity.EntityFramework. And instead add the following: EntityFramework and MR.AspNet.Identity.EntityFramework6.
  • Replace all EF Core namespaces with their EF6 counterparts.

MR.AspNet.Identity.EntityFramework6 NuGet version

The port of Microsoft.AspNetCore.Identity.EntityFramework to work under EF6.

MR.AspNet.Identity.EntityFramework6.Key.Int NuGet version

An implementation that uses an int as the primary key for users and roles.

MR.AspNet.Identity.EntityFramework6.InMemory NuGet version

Contains in memory implementations of IUserStore and IRoleStore to be used in unit tests.

MR.AspNet.Identity2.EntityFramework6.InMemory NuGet version

Contains in memory implementations of IUserStore and IRoleStore for identity 2 to be used in unit tests.

Note: In memory stores have a dependency on MR.Patterns.Repository for the in memory repository implementation.

MR.AspNet.Identity.EntityFramework6.Models NuGet version

Contains the models. This package has no dependencies.

Samples

Check out the samples in the samples/ directory.

EF6 migrations for Asp.Net Core?

Check out Migrator.EF6.

Release notes

3.0.6

  • Minor fixes.

3.0.5

  • Separate models into different package: MR.AspNet.Identity.EntityFramework6.Models. #17

3.0.3

  • Minor fixes.

3.0.2

  • Implement additional interfaces in the stores.

3.0.1

  • Switched to reference Microsoft.Extensions.Identity.Core. #11

3.0.0

  • Support Asp.Net Core Identity 2.0.

2.1.0

This release is for .Net Core 1.1.0

mr.aspnet.identity.entityframework6's People

Contributors

ckalan avatar mrahhal avatar nphmuller avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

mr.aspnet.identity.entityframework6's Issues

Sample or concise documentation for setting up User Store- Getting TypeLoadException while setting up User Store

I am facing difficulty in setting up User Store using this library. There is no sample or usage guide that clearly showcase how to setup user store. My code is as follows:

ApplicationUser.cs

public class ApplicationUser : IdentityUser<int,ApplicationUserLogin,ApplicationUserRole,ApplicationUserClaim>, IEntity<int>
    {
   }

ApplicationRole.cs

public class ApplicationRole : IdentityRole<int,ApplicationUserRole,IdentityRoleClaim<int>>, IEntity<int>
    {
      

    }

ApplicationUserRole, ApplicationUserLogin,ApplicationUserClaim classes

 public class ApplicationUserRole : IdentityUserRole<int> { }
    public class ApplicationUserClaim : IdentityUserClaim<int> { }
    public class ApplicationUserLogin : IdentityUserLogin<int> { }

MyDbContext.cs

public class MyDbContext: IdentityDbContext<ApplicationUser, ApplicationRole,int,ApplicationUserLogin,ApplicationUserRole,ApplicationUserClaim,IdentityRoleClaim<int>>
    {


        public MyDbContext(string connectionString):base(connectionString)
        {

        }
}

and UserStore is this:

public class ApplicationUserStore : UserStore<ApplicationUser,ApplicationRole,ApplicationUserRole,ApplicationUserClaim,ApplicationUserLogin,IdentityRoleClaim<int>,MyDbContext,int>
    {
        public ApplicationUserStore(MyDbContext context) : base(context)
        {

        }
    }

I am getting following run time exception:

System.ArgumentException: GenericArguments[0], 'ApplicationUser', on 'MR.AspNet.Identity.EntityFramework6.UserStore3[TUser,TRole,TContext]' violates the constraint of type 'TUser'. ---> System.TypeLoadException: GenericArguments[0], ApplicationUser', on 'MR.AspNet.Identity.EntityFramework6.UserStore8[TUser,TRole,TUserRole,TUserClaim,TUserLogin,TRoleClaim,TContext,TKey]' violates the constraint of type parameter 'TUser'.

What is going on here, and what am I doing wrong? Any samples, usage guide or solution appreciated?

Please note I have also tried this using int package i.e I have also tried using IdentityUserInt, IdentityRoleInt etc, but same exception.

please assist with adding claims when a user is authenticated.

I have tried the mechanisms here
http://benfoster.io/blog/customising-claims-transformation-in-aspnet-core-identity

to add extra claims to an authenticated user.

  • in the first method, using ClaimsTransformer in the overridden method context.Principal.Identity.IsAuthenticated is never true.
  • in the second method, I am unable to resolve the RoleManager<IdentityRole> roleManager, parameter to the AppClaimsPrincipalFactory class.

Do you have any idea what methods to override to create additional claims when a user is authenticated?

Thanks!

edit
I have looked at the code for UserClaimsPrincipalFactory and it seems like the right place to edit the claims when the user is authenticated. So perhaps I really just need assistance with providing the RoleManager dependency for RoleManager<MR.AspNet.Identity.EntityFramework6.IdentityRole> that the UserClaimsPrincipalFactory needs?

PasswordSignInAsync hangs (deadlock?)

Hi,
I'm trying use your project with a new .NET Core Application with Identity 3 and .NET framework to connect to an Oracle database. I was able to create new users with CreateAsync, but the application seems to hang when I try to log in with PasswordSignInAsync. It seems to be a deadlock issue. Aside from using Oracle database providers and your project, I didn't change much on anything from the out of the box project.

I'm still very new to all of this. Do you have any recommendations?

Thanks much in advance!

Package version 3.0.2

Hello @mrahhal,
Can you please publish the nuget package for version 3.0.2.
Version 3.0.1 is not working with the latest version of Identity 3 due to the missing UserTokens store.
I got this to work by downloading the source code and importing the project into my solution, but it is a dirty workaround.

Thank you!

Change Key type to int

I tried to change Key type to int. here is my custom classes

public class ApplicationUser : IdentityUser<int, CustomUserLogin, CustomUserRole, CustomUserClaim>
{
}

public class CustomUserRole : IdentityUserRole<int> { }

public class CustomUserClaim : IdentityUserClaim<int> { }

public class CustomRoleClaim : IdentityRoleClaim<int> { }

public class CustomUserLogin : IdentityUserLogin<int> { }

public class CustomRole : IdentityRole<int, CustomUserRole, CustomRoleClaim>
{
    public CustomRole()
    {
    }

    public CustomRole(string name)
    {
        Name = name;
    }
}

public class CustomUserStore : UserStore<ApplicationUser, ApplicationRole, CustomUserRole, CustomUserClaim, CustomUserLogin, CustomRoleClaim, ApplicationDbContext, int>
{
    public CustomUserStore(ApplicationDbContext context)
        : base(context)
    {
    }
}

public class CustomRoleStore : RoleStore<ApplicationRole, CustomUserRole, CustomRoleClaim, ApplicationDbContext, int>
{
    public CustomRoleStore(ApplicationDbContext context)
        : base(context)
    {
    }
}

and in startup class:

services.AddScoped(_ => new ApplicationDbContext("Server=.;Database=AspCoreEf6;Trusted_Connection=True;MultipleActiveResultSets=true"));
services.AddIdentity<ApplicationUser, ApplicationRole>().AddEntityFrameworkStores<ApplicationDbContext>();

when I run project i get this error:

GenericArguments[0], 'AspCoreEf6.Models.ApplicationUser', on 'MR.AspNet.Identity.EntityFramework6.UserStore`3[TUser,TRole,TContext]' violates the constraint of type 'TUser'.

I don't know how to change UserStore and RoleStore and use CustomUserStore and CustomRoleStore.

TUser Constraint violation problem when running aspnet core app

Hello there,
I just tried to run my application for the first time and this is the inner exception I got. It doesn't let me start the application at all. It just stops and gives me this exception.

For context, my system is Windows 10 Home, VS 2015 Update 3, project is created against the full .NetFramework 4.6.1 and all the packages are updated to v1.1.0.
The error occurs here:

services.AddIdentity<ApplicationUser, IdentityRole>()
    .AddEntityFrameworkStores<SchoolDb>()
    .AddDefaultTokenProviders();

This is the exception that gets produced when I try to run the application.

GenericArguments[0], 'SwiftSkool.Models.ApplicationUser', on  'MR.AspNet.Identity.EntityFramework6.UserStore`8[TUser,TRole,TUserRole,TUserClaim,TUserLogin,TRoleClaim,TContext,TKey]' violates the constraint of type parameter 'TUser'.

Ambiguous call between AspNetCore.Identity.IdentityBuilder and MR.AspNet.Identity.EntityFramework6.IdentityEntityFrameworkExtensions.AddEntityFrameworkStores<TContext>

Merry Christmas,
I really appreciate what you did creating the MR.*.Int package. I have a problem in my StartUp class with an error which is the subject of this post. This is the section that shows the red squiggly in my startup:

services.AddIdentity<ApplicationUser, IdentityRole>() .AddEntityFrameworkStores<SchoolDb>() .AddDefaultTokenProviders();
Not sure what I need to do here but was wondering if you could help in any way. Thanks

FindByIdAsync in UserStore takes 'string' Ids by default (even when inherited from UserStoreInt)

Here is my UserStoreInt implementation,

public class UserStore : UserStoreInt<DbContext>
    {       
        public UserStore(DbContext context)
            : base(context)
        {
        }
    }

And I am accessing FindByIdAsync method in some repository as:

await _userStore.FindByIdAsync(userId) //datatype of userId is int

On checking the definition of FindByIdAsync here, I found that the parameter of the function has 'string' hardcoded.

I think it should have TKey instead of string because, UserStoreInt also implements this method. I realized that you have called "ConvertIdFromString" inside that method, but that rarely would work in real scenarios because the one using int as type will have to explicitly convert Ids to string and then in your method, it will reconvert to int.

I can make that small change and send a PR. Need your confirmation.

Production Use

Hi @mrahhal

Thanks for the EF6 provider.

What is the status of the project, can we use it in the production code?

EntityFramework 6 and Mysql.Data.Entity

Hello, I have a problem with LockoutEnd property which is of DateTimeOffest type.
But MySQL can't support this DateTime format. Is it possible to create a branch with DateTime and not DateTimeOffest specially for MySQL Connector?

I can't compile your project source.
Thanks a lot.

Bastien

ASP.NET RTM Compatibility

The latest version doesn't work with the new RTM release of ASP.NET. Getting this error when calling services.AddIdentity:

Additional information: Could not load type 'Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionExtensions' from assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.

Seems like its linked to this change aspnet/DependencyInjection#412

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.