nhibernate / nhibernate.aspnet.identity Goto Github PK
View Code? Open in Web Editor NEWASP.NET Identity Provider for NHibernate
Home Page: http://nhibernate.info/NHibernate.AspNet.Identity/
License: MIT License
ASP.NET Identity Provider for NHibernate
Home Page: http://nhibernate.info/NHibernate.AspNet.Identity/
License: MIT License
In: Create ();
var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(**context.Get<ApplicationDbContext>()**));
As removed ApplicationDbContext class, what should I spend?
I prefer to use Fluently.Configure() but i couldn't get MappingHelper.GetIdentityMappings() to work with it. Any thoughts on how this can be accomplished?
I'm trying to implement AspNet.Identity in my WebAPI2 application which uses NHibernate as the ORM. I think this project is a great step in the right direction for me.
I created a Web project, followed the quick-start guide, and I was left with some errors and warnings. I've created a Wiki page that has the additional steps I've had to follow to remove the errors and warnings. One of which, I'm not quite sure how to fix. Please advise if I'm going in the completely wrong direction 😄.
https://github.com/milesibastos/NHibernate.AspNet.Identity/wiki/Quick-Start-Updates
My scenario was this:
I have an ApplicationUser class which derives from IdentityUser. I would like to use a table-per-hierarchy inheritance model (all classes in the same table) in order not to generate unnecessary tables in the db.
However, it's not possible to achieve by using the MappingHelper class. Although, I can provide an additional type to map, I have no control over the mapping. For example, I needed to generate the discriminator column in the IdentityUserMap and then provide discriminator value in the ApplicationUserMap.
Moreover, the schema that gets generated for the ApplicationUser table is not very good - no foreign keys or indexes. I suppose this is because I can't supply ClassMapping to the ConventionModelBuilder so it uses some basic conventions only to map property to columns.
Would you consider providing a way to pass not only additional types to map, but also additional mapping types themselves (e.g. classes deriving from ClassMapping)? This way I could extend your mappings and provide mine as well.
I am trying to use your wonderful NHibernate.AspNet.Identity
I have everything working fine so far, but I am getting an error using external login providers
var user = await UserManager.FindAsync(loginInfo.Login);
Unable to cast object of type 'NHibernate.Linq.NhQueryable1[Microsoft.AspNet.Identity.UserLoginInfo]' to type 'System.Linq.IQueryable
1[NHibernate.AspNet.Identity.IdentityUserLogin]'.
Member Account at the JetBrains Open Source Support Program
Thank you for taking the time to submit your membership form. The review board will evaluate your request over the next few days. We will make every effort to take care of this promptly and will notify you as soon as the review board has come to a decision.
If you experience any problem receiving our response in a timely way, please contact JetBrains Team at [email protected].
Hi,
there is the following error when I try to retrieve user informations
NHibernate.Exceptions.GenericADOException: Failed to execute multi query[SQL: select applicatio0_.applicationuser_key as Id6_0_, identityro2_.Id as Id9_1_, applicatio0_1_.AccessFailedCount as AccessFa2_6_0_, applicatio0_1_.Email as Email6_0_, applicatio0_1_.EmailConfirmed as EmailCon4_6_0_, applicatio0_1_.LockoutEnabled as LockoutE5_6_0_, applicatio0_1_.LockoutEndDateUtc as LockoutE6_6_0_, applicatio0_1_.PasswordHash as Password7_6_0_, applicatio0_1_.PhoneNumber as PhoneNum8_6_0_, applicatio0_1_.PhoneNumberConfirmed as PhoneNum9_6_0_, applicatio0_1_.TwoFactorEnabled as TwoFact10_6_0_, applicatio0_1_.UserName as UserName6_0_, applicatio0_1_.SecurityStamp as Securit12_6_0_, applicatio0_.Name as Name11_0_, applicatio0_.Surname as Surname11_0_, identityro2_.Name as Name9_1_, case when identityro2_1_.applicationrole_key is not null then 1 when identityro2_.Id is not null then 0 end as clazz_1_, roles1_.UserId as UserId0__, roles1_.RoleId as RoleId0__ from ApplicationUser applicatio0_ inner join AspNetUsers applicatio0_1_ on applicatio0_.applicationuser_key=applicatio0_1_.Id left outer join AspNetUserRoles roles1_ on applicatio0_.applicationuser_key=roles1_.UserId left outer join AspNetRoles identityro2_ on roles1_.RoleId=identityro2_.Id left outer join ApplicationRole identityro2_1_ on identityro2_.Id=identityro2_1_.applicationrole_key where upper(applicatio0_1_.UserName)=?;
↵select applicatio0_.applicationuser_key as Id6_0_, claims1_.Id as Id10_1_, applicatio0_1_.AccessFailedCount as AccessFa2_6_0_, applicatio0_1_.Email as Email6_0_, applicatio0_1_.EmailConfirmed as EmailCon4_6_0_, applicatio0_1_.LockoutEnabled as LockoutE5_6_0_, applicatio0_1_.LockoutEndDateUtc as LockoutE6_6_0_, applicatio0_1_.PasswordHash as Password7_6_0_, applicatio0_1_.PhoneNumber as PhoneNum8_6_0_, applicatio0_1_.PhoneNumberConfirmed as PhoneNum9_6_0_, applicatio0_1_.TwoFactorEnabled as TwoFact10_6_0_, applicatio0_1_.UserName as UserName6_0_, applicatio0_1_.SecurityStamp as Securit12_6_0_, applicatio0_.Name as Name11_0_, applicatio0_.Surname as Surname11_0_, claims1_.ClaimType as ClaimType10_1_, claims1_.ClaimValue as ClaimValue10_1_, claims1_.UserId as UserId10_1_, claims1_.UserId as UserId0__, claims1_.Id as Id0__ from ApplicationUser applicatio0_ inner join AspNetUsers applicatio0_1_ on applicatio0_.applicationuser_key=applicatio0_1_.Id left outer join AspNetUserClaims claims1_ on applicatio0_.applicationuser_key=claims1_.UserId where upper(applicatio0_1_.UserName)=?;
↵select applicatio0_.applicationuser_key as Id6_, applicatio0_1_.AccessFailedCount as AccessFa2_6_, applicatio0_1_.Email as Email6_, applicatio0_1_.EmailConfirmed as EmailCon4_6_, applicatio0_1_.LockoutEnabled as LockoutE5_6_, applicatio0_1_.LockoutEndDateUtc as LockoutE6_6_, applicatio0_1_.PasswordHash as Password7_6_, applicatio0_1_.PhoneNumber as PhoneNum8_6_, applicatio0_1_.PhoneNumberConfirmed as PhoneNum9_6_, applicatio0_1_.TwoFactorEnabled as TwoFact10_6_, applicatio0_1_.UserName as UserName6_, applicatio0_1_.SecurityStamp as Securit12_6_, applicatio0_.Name as Name11_, applicatio0_.Surname as Surname11_, logins1_.UserId as UserId0__, logins1_.LoginProvider as LoginPro2_0__, logins1_.ProviderKey as Provider3_0__ from ApplicationUser applicatio0_ inner join AspNetUsers applicatio0_1_ on applicatio0_.applicationuser_key=applicatio0_1_.Id left outer join AspNetUserLogins logins1_ on applicatio0_.applicationuser_key=logins1_.UserId where upper(applicatio0_1_.UserName)=?;
↵select applicatio0_.applicationuser_key as Id6_, applicatio0_1_.AccessFailedCount as AccessFa2_6_, applicatio0_1_.Email as Email6_, applicatio0_1_.EmailConfirmed as EmailCon4_6_, applicatio0_1_.LockoutEnabled as LockoutE5_6_, applicatio0_1_.LockoutEndDateUtc as LockoutE6_6_, applicatio0_1_.PasswordHash as Password7_6_, applicatio0_1_.PhoneNumber as PhoneNum8_6_, applicatio0_1_.PhoneNumberConfirmed as PhoneNum9_6_, applicatio0_1_.TwoFactorEnabled as TwoFact10_6_, applicatio0_1_.UserName as UserName6_, applicatio0_1_.SecurityStamp as Securit12_6_, applicatio0_.Name as Name11_, applicatio0_.Surname as Surname11_ from ApplicationUser applicatio0_ inner join AspNetUsers applicatio0_1_ on applicatio0_.applicationuser_key=applicatio0_1_.Id where upper(applicatio0_1_.UserName)=?;
↵] ---> System.InvalidOperationException: A Command è già associato un DataReader aperto, che deve essere chiuso.
I'm trying to get this into my project but the 3 step quick start doesn't seem to work? Is there an example solution of this already implemented? Any help please.
In your documentation, you state that you should pass the connectionstring name, however, the code tells a different story... It requires an ISession to be passed...
I can see that passing an ISession is preferable, however, the documentation should match... it may also be useful to have the store create it's own session, but that would likely be a change.
I think it'd be good if the following dependencies were removed:
I was considering using this nuget package, but when I saw these packages referenced I was reluctant to install.
IdentityUser.cs, line 69
I am using the code that you have on the Sample folder for version 2.2.0. What I am doing is trying to export the sql squema to a file same as you do for the sqlite version.
This is the squema that I am getting.
create table AspNetUsers (
Id VARCHAR(255) not null,
AccessFailedCount INTEGER,
Email VARCHAR(255),
EmailConfirmed TINYINT(1),
LockoutEnabled TINYINT(1),
LockoutEndDateUtc DATETIME,
PasswordHash VARCHAR(255),
PhoneNumber VARCHAR(255),
PhoneNumberConfirmed TINYINT(1),
TwoFactorEnabled TINYINT(1),
UserName TEXT not null unique,
SecurityStamp VARCHAR(255),
primary key (Id)
)
Any Idea on what can be the problem ?
Also in Remove/Add Roles a call to Context.Update(user) is missing.
UserStore and Role Store could be more efficient if they used the new async data access features available in NHibernate 5.
I'm having some trouble installing the package via NuGet with the PMC returning
Install-Package : Could not install package 'NHibernate.AspNet.Identity 1.0.2001'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.5', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
I'm using VS2013 Professional on Windows 8.1,
This is the only missing part of the EF provider. What do you think?
First i would like to thank you for creating this library.
I am planning to use this library for my project but i read some comment regarding this library
http://stackoverflow.com/questions/21243269/using-nhibernate-aspnet-identity
I hope that in next you may give an example to demonstrate how to use your library (for nhibernate) to replace "Microsoft.Asp.Net.EntityFramework"
Thanks you
I get this error:
An exception of type 'NHibernate.HibernateException' occurred in NHibernate.dll but was not handled in user code
Additional information: BLOB/TEXT column 'UserName' used in key specification without a key length
using this config:
Private Function CreateConfig() As FluentConfiguration
Dim fConfig As FluentConfiguration
fConfig = Fluently.Configure _
.Database(MySQLConfiguration.Standard _
.ConnectionString(NhDataProvider.DEFAULT_CONNECTION_STRING).AdoNetBatchSize(100)) _
.ExposeConfiguration(Sub(cfg) cfg.AddDeserializedMapping(MappingHelper.GetIdentityMappings({GetType(ApplicationUser)}), Nothing))
Return fConfig
It seems this is handled by the MappingHelper, and I'm not sure what the fix is. Any help would be much appreciated!
I am used to the EF Identity setup, where IdentityUser
is generic, so I can declare ApplicationUser: IdentityUser<int....
, but now replacing the EF Identity with your NHIbernate Identity has replaced the generic IdentityUser
with one that has string
hard coded as the key. How do I use an int
key?
It seems to me that the two are incompatible, it fails with:
[MissingMethodException: Method not found: 'Void NHibernate.Mapping.ByCode.IComponentElementMapper
1.Property(System.Linq.Expressions.Expression
1<System.Func2<!0,!!0>>)'.] NHibernate.AspNet.Identity.IdentityUserMap.<.ctor>b__8(IComponentElementMapper
1 comp) +0
NHibernate.Mapping.ByCode.Impl.CustomizersImpl.PropertyContainerCustomizer1.RegisterSetMapping(Action
1 collectionMapping, Action`1 mapping, MemberInfo[] members) +410
NHibernate.AspNet.Identity.IdentityUserMap..ctor() +3421
[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +197
System.Activator.CreateInstance() +132
NHibernate.Mapping.ByCode.ModelMapper.AddMapping() +52
NHibernate.AspNet.Identity.Helpers.MappingHelper.GetIdentityMappings(Type[] additionalTypes) +487
Given the fact that correctly supported Nhibernate 5 would require updating the solution to, at least, .NET 4.6.2 I would suggest to set the dependency on nuget to Nhibernate < 5.0.0 to prevent users from breaking their solution.
I think your documentation might not be completely up to date following the latest update to Visual Studio tools. If you build a Cloud ASP.NET application and use the default values (MVC and WebAPI), you get more errors in the console. You need to change things in IdentityConfig.cs, AccountController.cs, StartupAuth.cs, etc.
Also the ApplicationDbContext class that you ask to delete from IdentityModel.cs is used in a bunch of other places and I'm not sure what to replace it with.
BLOB/TEXT column 'UserName' used in key specification without a key lengthUnsuccessful: create table AspNetUsers (Id VARCHAR(255) not null, AccessFailedCount INTEGER, Email VARCHAR(255), EmailConfirmed TINYINT(1), LockoutEnabled TINYINT(1), LockoutEndDateUtc DATETIME, PasswordHash VARCHAR(255), PhoneNumber VARCHAR(255), PhoneNumberConfirmed TINYINT(1), TwoFactorEnabled TINYINT(1), UserName TEXT not null unique, SecurityStamp VARCHAR(255), primary key (Id))
Using MySQL as db.
Only found out using NHProfiler. Any idea? Result is that it doesnt create the tables required for Identity to work
Hi,
I get the following build error after restoring all packages using nuget restore. It doesn't redirects to a line or anything.
Error :
"Error occurred: System.ArgumentNullException: Value cannot be null.
Parameter name: path
at System.IO.Directory.GetParent(String path)
at GitVersion.ConfigurationProvider.GetConfigFilePath(String gitDirectory) in c:\BuildAgent\work\68ea6bfb44e5afb\GitVersionCore\Configuration\ConfigurationProvider.cs:line 51
at GitVersion.ConfigurationProvider.Provide(String gitDirectory, IFileSystem fileSystem) in c:\BuildAgent\work\68ea6bfb44e5afb\GitVersionCore\Configuration\ConfigurationProvider.cs:line 13
at GitVersionTask.WriteVersionInfoToBuildLog.InnerExecute() in c:\BuildAgent\work\68ea6bfb44e5afb\GitVersionTask\WriteVersionInfoToBuildLog.cs:line 54
at GitVersionTask.WriteVersionInfoToBuildLog.Execute() in c:\BuildAgent\work\68ea6bfb44e5afb\GitVersionTask\WriteVersionInfoToBuildLog.cs:line 31 NHibernate.AspNet.Identity
"
Can you guys please help me out with this one.
Thanks for all the great work on this!
I just upgraded from v .2001 to v .2002, and there appears to no longer be an IdentityUserLoginMap. I tried removing it, but now I'm getting missing mapping errors at runtime.
Looking through the commit logs, it appears you removed it on purpose and merged the mapping in to IdentityUserMap. However, the readme still references IdentityUserLoginMap so I'm not sure.
Am I missing something here?
I've used this assembly with Sharp Architecture before without problems.
But now I have some Issues.
The first that I resolved was the implementation in Castle Windsor installer of ISession.
But now and it is the issue with the highest priority:
I can't make work the automapping of Sharp.
I've completed the steps with the older versions but the mappings for Nhibernate.Aspnet.Identity does not appears on the solution.
When I use the userstore for a Query.. (login, register, etc) I got this error
Interceptor.OnPrepareStatement(SqlString) returned null or empty SqlString.
This means that the entities on the assembly are no mapped.
Please can you give an advice about this.
Thanks
I'd like to change the User ID in NHibernate.AspNet.Identity.IdentityUser from a string (GUID) to an Int32.
There's some info about this for the normal Asp.Net identity stuff but it doesn't seem to be applicable here. Is this possible at all? What's the best way to go about it?
Hi,
I created a fork of your project and I implemented everything for Identity 2.0(based on ef implemenation). If you're interested I can create a pull request. The only thing is I still use the string Id of V1.
Thanks for the initial project.
Laurent
I'm working on console app with owin. I can not create new Application Instance;
var storage = new WebSessionStorage(HttpContext.Current.ApplicationInstance); Current is null because not work on owin. Does anyone have any suggestions?
Please Update the nuget references
Hi. Does anyone know if there plans for NHibernate.AspNet.Identity to support .NET core now that NHibernate supports it?
(see http://nhibernate.info/blog/2018/03/17/nhibernate-5-1-released.html for more info)
These two classes are preventing me from implementing generic stores - these look to be pre-compiled was this intentional? And if so how would I go about with an inherited role/user from Identity
?
I mean here: https://github.com/nhibernate
I'm using this package for test project but saving claim (facebook data) doesn't work.
for example in Startup.Auth.cs
Provider = new FacebookAuthenticationProvider()
{
OnAuthenticated = (context) =>
{
// All data from facebook in this object. rawUserObjectFromFacebookAsJson
var fbUserJson = context.User;
var fbUser = JsonConvert.DeserializeObject<SeFacebookUserObject>(fbUserJson.ToString());
// Only some of the basic details from facebook
// like id, username, email etc are added as claims.
// But you can retrieve any other details from this
// raw Json object from facebook and add it as claims here.
// Subsequently adding a claim here will also send this claim
// as part of the cookie set on the browser so you can retrieve
// on every successive request.
context.Identity.AddClaim(new Claim("fb:access_token", context.AccessToken));
context.Identity.AddClaim(new Claim("fb:email", context.Email));
context.Identity.AddClaim(new Claim("fb:name", context.Name));
return Task.FromResult(0);
}
}
};
app.UseFacebookAuthentication(facebookOptions);
does not any effect to claim table.
Out of curiosity - why do you use TransactionScopes?
In my mind, they only stand in the way of sharing the ISession/Transaction that I already have in my app anyway. This is because when the transaction scope is completed the current session's transaction is no longer usable.
Basically, my scenario is this:
I already have an app/website with ISession open per request. I also have the current transaction obtained by calling Session.BeginTransaction which I commit or rollback at the end of the request. Naturally, I would like to reuse the same transaction for identity management so that all my work is committed or rolled back together. However, I cannot do so because my current transaction gets enlisted into the transaction scope and gets committed for me inside the UserStore.
Good morning.
Could you please provide the package for .net 4.5. We´re getting this error.
Could not install package 'NHibernate.AspNet.Identity 1.0.2003'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.5', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
BR
André
Exception:
{"The following types may not be used as proxies:\nProofs.Mono.OAuth2.Web.Models.ApplicationUser: method GenerateUserIdentityAsync should be 'public/protected virtual' or 'protected internal virtual'\nProofs.Mono.OAuth2.Web.Models.ApplicationUser: method get_Email should be 'public/protected virtual' or 'protected internal virtual'\nProofs.Mono.OAuth2.Web.Models.ApplicationUser: method set_Email should be 'public/protected virtual' or 'protected internal virtual'"}
An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
The NHibernate.AspNet.Identity
uses the old AspNet.Identity
.
Now in Asp .Net Core we have AspNetCore.Identity
, there is any plans to support it?
var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
throws
Invalid object name 'ApplicationUser'.
var myEntities = new[] {
typeof(ApplicationUser)
};
string connectionString = "Data Source=XXXXXXXXXXX";
var configuration = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString(connectionString))
.ExposeConfiguration(cfg =>
{
cfg.AddDeserializedMapping(MappingHelper.GetIdentityMappings(myEntities), null);
});
var factory = configuration.BuildSessionFactory();
var session = factory.OpenSession();
var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(session));
I am attempting to test this project by registering a new user. Whenever I do, I get this error: Store does not implement IUserEmailStore.
However, I can see with NH Profiler that a query is being run against the database to check for this user. Is this a .NET issue or an issue with this specific library?
Code:
UserManager = new UserManager(new UserStore(session));
The only properties i have access to are "MyProperty". I can't access Id, Email, username, etc. Is there a way around this without hitting the tables directly through nhibernate?
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.