abp-samples icon indicating copy to clipboard operation
abp-samples copied to clipboard

ConcurrentLogin Example

Open dmolon opened this issue 2 years ago • 5 comments

Hello!

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

Thanks!

dmolon avatar Jun 20 '23 18:06 dmolon

hi

Their implementation is almost the same.

maliming avatar Jun 21 '23 08:06 maliming

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

dmolon avatar Jun 21 '23 14:06 dmolon

microservices solution

Are you using the abp microservice? eg eShopOnAbp?

maliming avatar Jun 22 '23 09:06 maliming

microservices solution

Are you using the abp microservice? eg eShopOnAbp?

We've created a microsservice solution using ABP Suite.

dmolon avatar Jun 22 '23 20:06 dmolon

hi

The ConcurrentLogin doesn't work for the microservice solution.

maliming avatar Jun 27 '23 11:06 maliming