linq2db / linqtodb.identity Goto Github PK
View Code? Open in Web Editor NEWThis project forked from aspnet/identity
ASP.NET Core Identity provider that uses LinqToDB.
Home Page: https://linq2db.github.io/
License: MIT License
This project forked from aspnet/identity
ASP.NET Core Identity provider that uses LinqToDB.
Home Page: https://linq2db.github.io/
License: MIT License
Tracks list of tasks to to:
All stores methods needs to be rewritten like:
public int SomeMethod(...)
{
using(var db = _factory.GetConnection())
return SomeMethod(db, ....);
}
protected virtual int SomeMethod(DataConnection db, ...)
{
...
}
Hello,
I have been trying to use UserManager and RoleManager. I have implemented my identity classes that have int primary key.
For instance, when I would like to use UserManager FindByIdAsync method, it is still required string userId parameter, but I want to user int parameter. How can I change this ? Actually, I have not customized UserManager ord UserStore before.
Here is my AppUser class.
public class AppUser : IdentityUser<int>, IEntity
{
[Required, Identity]
[Key]
public override int Id { get => base.Id; set => base.Id = value; }
public DateTime CreatedDate { get; set; }
public DateTime? ModifiedDate { get; set; }
public int? CreatedBy { get; set; }
public int? ModifiedBy { get; set; }
public int? StatusId { get; set; }
}
Here is my AddLinqToDBStores implementation.
``
/// <summary>
/// Adds authentication service
/// </summary>
/// <param name="services">Collection of service descriptors</param>
public static void AddDevPlatformAuthentication(this IServiceCollection services, IConfiguration configuration)
{
services.AddIdentity<AppUser, AppRole>(options =>
{
options.Password.RequireDigit = true;
options.Password.RequiredLength = 4;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireUppercase = true;
options.Password.RequireLowercase = false;
options.User.RequireUniqueEmail = true;
options.SignIn.RequireConfirmedEmail = false;
//TODO
//options.User.RequireUniqueEmail = true;
//options.Lockout.MaxFailedAccessAttempts = 5;
//options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(3);
}).AddLinqToDBStores<int, AppUserClaim, AppUserRole, AppUserLogin, AppUserToken, AppRoleClaim>(new
IdentityConnectionFactory(new SqlServerDataProvider(ProviderName.SqlServer, SqlServerVersion.v2017), "SqlServerIdentity", DataSettingsManager.LoadSettings().ConnectionString))
.AddUserStore<LinqToDB.Identity.UserStore<int, AppUser, AppRole, AppUserClaim, AppUserRole, AppUserLogin, AppUserToken>>()
.AddUserManager<UserManager<AppUser>>()
.AddRoleManager<RoleManager<AppRole>>()
.AddDefaultTokenProviders();
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie();
// Uncomment the following lines to enable logging in with third party login providers
JwtTokenDefinitions.LoadFromConfiguration(configuration);
services.ConfigureJwtAuthentication();
services.ConfigureJwtAuthorization();
}
_userManager.FindByIdAsync() as I said, I need to use an int parameter for all userManager method.
How can I handle it ?
Best Regards
Reorder type parameters in
I have this code
using (var transaction = new TransactionScope())
{
IdentityResult result = await userManager.CreateAsync(user, model.Password);
Execution goes inside userManager.CreateAsync
, and freeze. No exception, no result.
I tried adding support for Enum.HasFlag method to linq2db like follows:
LinqToDB.Linq.Expressions.MapMember((Enum e, Enum e2) => e.HasFlag(e2), (Expression<Func<Enum, Enum, bool>>)((t, flag) => (Sql.ConvertTo<int>.From(t) & Sql.ConvertTo<int>.From(flag)) != 0));
I'm getting the following exception when executing this: Expression of type 'MyEnum' cannot be used for parameter of type 'System.Enum' of method 'Int32 From[Enum](System.Enum)
I'm not sure if I'm doing it right or this is a bug.
TContext & TConnecion type parameters should be removed from the whole project
how LinqToDB.Identity in mvc 5 (not core)
Shouldn't we increase major version on breaking changes? see : http://semver.org
From a quick look at the code I saw that the users TKey is hard coded as string, is that correct?
However, is there an easy way to use an int? Or do I have to re-implement the interfaces myself?
commit 0d68b8a
src/LinqToDB.Identity/
IdentityLinqToDbBuilderExtensions.cs стр. 74
builder.Services.TryAdd(GetDefaultServices(builder.UserType, builder.RoleType, typeof(TContext), typeof(TKey)));
Возможно должна быть:
builder.Services.TryAdd(GetDefaultServices(builder.UserType, builder.RoleType, typeof(TContext), typeof(TConnection), typeof(TKey)));
I use default Identity classes.
And this initialization at sturtup. Users and Roles have int id.
.AddLinqToDBStores<int>(dataBaseFactory)
.AddUserManager<UserManager<User>>()
.AddRoleManager<RoleManager<UserGroup>>()
I tried to
var roles = await userManager.GetRolesAsync(user);
Throw exceprion
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1
userRole
INNER JOIN
AspNetRolesrole_1
ON
userRole.
RoleId=
role' at line 4
The issue I found is that when I'm using IdentityUser when I insert into the database (or generate the table) the Id column doesn't get setup properly, and when I register a new user an Id isn't getting created from a sequence because it doesn't have the IdentityAttribute.
In order to work around this issue I've had to use the FluentMappingBuilder
to add the Identity attribute to the Id field. Like so:
MappingSchema.GetFluentMappingBuilder().Entity<IdentityUser<int>>().HasIdentity(user => user.Id)
I'm still a bit new to Linq2Db so I'm not sure if there's a reason not to add that in all cases, however I think we should at least document that you might need to use the above snippet to configure your user properly.
Hello!
Is there any plans to upgrade Linq2db.Identity to use linq2db version 4.x?
The library Linq2db.Identity itself works well, but it stops from using newer version of other libraries - linq2db, Npgsql etc.
Upgrade to new version of linq2db is not so hard (couple of methods are changed), but there are some other things that need to pay attention:
Thank you!
I'm running the identity system against a MySQL DB and get SQL syntax errors for DateTimeOffset. MySQL does not support the datatype.
Found some related notes on the interwebs
A startup.cs run in one of your samples includes a block for generating Identity tables using DataConnection.CreateTable<>. Table names for Identity (and any that are generic types) come out as `1.
I filtered the `1 out in the create process, but it only creates issues later when the ORM tries to access the tables. I also tried filtering them out and then generating a data context to attempt to override the type name interpretation process, but had no luck, the LinqToDB.Identity namespaced objects are still being used to access the database.
SqlException: Invalid object name 'IdentityUserClaim`1'.
LinqToDB.Data.DataConnection.ExecuteReaderAsync(CommandBehavior commandBehavior, CancellationToken cancellationToken) in DataConnection.Async.cs
Would it be possible to change the way LinqToDb interprets type names so that no DB objects will not be created with `1 at the end of them?
AddLinqToDBStores methods should be rewritten to allow register own types easy, for now it is needed to write:
services
.AddSingleton<IConnectionFactory<MyDataContext,MyDataConnection>>(new IdentityConnectionFactory())
.AddScoped(typeof(IUserStore<User>), typeof(UserStore))
.AddScoped(typeof(IRoleStore<Role>), typeof(RoleStore));
Thanks for the awesome lib. I'm trying it out for a new project in .Net core 2.0 and run into the below error when adding the ".AddLinqToDBStores(new DefaultConnectionFactory())" statement.
I've pulled the example from the repo and it gives the same error message. Removing the line makes it build.
PS: I've removed the source and added the Nuget package to re-produce the error.
Can we get an updated release to support the new version of core?
I was able to setup this repo locally and get it working on 2.0 without much work, around 40 unit tests failed when I ran them, but I'm not sure if that's to be expected or not.
I can submit a pull request with my changes if that would speed things along.
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.