mrahhal / mr.aspnet.identity.entityframework6 Goto Github PK
View Code? Open in Web Editor NEWEntityFramework 6 provider + InMemory providers for Asp.Net Core Identity.
License: MIT License
EntityFramework 6 provider + InMemory providers for Asp.Net Core Identity.
License: MIT License
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
Hello, there is some new improvements to Identity, please update your project use to the latest version of the identity.
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
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.UserStore
3[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.
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'.
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
.
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.
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!
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
Hi @mrahhal
Thanks for the EF6 provider.
What is the status of the project, can we use it in the production code?
Hey;
We are seeing an issue with 2FA and I'm not sure if its an Identity change or an issue with this provider.
aspnet/Identity#1383 (comment)
Any thoughts?
Tokens property in IdentityUser is read-only and not initialized. This throws NullReference errors and also "Property does not have a setter" error during UserManager.SetAuthenticationToken method
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!
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.
ClaimsTransformer
in the overridden method context.Principal.Identity.IsAuthenticated
is never true.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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.