Giter Site home page Giter Site logo

linq2db / linqtodb.identity Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aspnet/identity

46.0 46.0 9.0 4.27 MB

ASP.NET Core Identity provider that uses LinqToDB.

Home Page: https://linq2db.github.io/

License: MIT License

PowerShell 1.98% Shell 0.84% C# 97.18%
asp-net-core identity linq2db

linqtodb.identity's People

Contributors

ajaybhargavb avatar ajcvickers avatar analogrelay avatar brennanconroy avatar bricelam avatar chengtian avatar danroth27 avatar davidfowl avatar dougbu avatar eilon avatar grabyourpitchforks avatar halter73 avatar haok avatar hishamco avatar ili avatar juntaoluo avatar kichalla avatar kirthik avatar loudej avatar macewindu avatar ntaylormullen avatar pakrym avatar pranavkm avatar rynowak avatar sfadeev avatar tratcher avatar troydai avatar tugberkugurlu avatar vanillajonathan avatar yukozh 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  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

linqtodb.identity's Issues

Release 3.1.0

Tracks list of tasks to to:

  • move project to main linq2db repository and obsolete this one
  • update project to VS2019
  • update project to use C#9
  • update project to use NRT
  • automate build/testing/deploy using azure (integrate into existing pipelines)
  • address existing issues
  • check if we need to update code from https://github.com/dotnet/aspnetcore/tree/master/src/Identity

Rewrite stores

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, ...)
{
...
}

Customizing Identity UserManager and RoleManager

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

Transaction scope not working?

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.

How can I add support for Enum.HasFlag?

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.

Easy way to change the key type?

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)));

UserManager.GetRolesAsync(user) Error.

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 userRoleINNER JOINAspNetRoles role_1ONuserRole.RoleId=role' at line 4

Id field of IdentityUser is missing an IdentityAttribute

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.

Upgrade to linq2db version 4.x

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:

  1. Syncronize code with actual aspnet core Identity project (https://github.com/dotnet/aspnetcore/tree/main/src/Identity)
  2. Update to actual dotnet/c# versions

Thank you!

SqlServer DatabaseConnection.CreateTable<> Adds "`1"

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?

Rewrite AddLinqToDBStores

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));

Unable to resolve service for type Microsoft.AspNetCore.Identity.IUserStore

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.

ASP.NET Core 2.0 support

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.

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.