abpframework / abp-samples

Sample solutions built with the ABP Framework
https://abp.io
MIT License
1.21k stars 1.25k forks source link

ConcurrentLogin Example #243

Open dmolon opened 1 year ago

dmolon commented 1 year ago

Hello!

The ConcurrentLogin Example is currently using IdentityServer, could you please update it to use OpenIddict?

Thanks!

maliming commented 1 year ago

hi

Their implementation is almost the same.

dmolon commented 1 year ago

hi

Their implementation is almost the same.

Hi, @maliming.

We managed to make the code work with OpenIddict, and now we have a question about how to implement this in a microservices solution since it requires the code below in each OnApplicationInitialization method of the microservices. Our question is whether we need to make all microservices aware of Identity and place this code in each one of them, or if there is a more centralized way to do this.

Sorry for taking up your time, and thank you very much!

       app.Use(async (httpContext, func) =>
        {
            var currentUser = httpContext.RequestServices.GetRequiredService<ICurrentUser>();
            if (currentUser.IsAuthenticated)
            {
                var claimToken = currentUser.GetConcurrentLoginToken();
                var userManager = httpContext.RequestServices.GetRequiredService<IdentityUserManager>();
                var user = await userManager.FindByIdAsync(currentUser.Id.ToString());
                if (claimToken != user.GetProperty("ConcurrentLogin").ToString())
                {
                    //Cookies
                    if (httpContext.User.Identity != null && httpContext.User.Identity.AuthenticationType == "Identity.Application")
                    {
                        await httpContext.RequestServices.GetRequiredService<AbpSignInManager>().SignOutAsync();
                        await httpContext.ChallengeAsync("Identity.Application");
                    }

                    //JWT
                    if (httpContext.User.Identity != null && httpContext.User.Identity.AuthenticationType == "AuthenticationTypes.Federation")
                    {
                        await httpContext.ChallengeAsync(JwtBearerDefaults.AuthenticationScheme);
                    }

                    //Other

                    return;
                }
            }

            await func();
        });
maliming commented 1 year ago

microservices solution

Are you using the abp microservice? eg eShopOnAbp?

dmolon commented 1 year ago

microservices solution

Are you using the abp microservice? eg eShopOnAbp?

We've created a microsservice solution using ABP Suite.

maliming commented 1 year ago

hi

The ConcurrentLogin doesn't work for the microservice solution.