Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConcurrentLogin Example #243

Open
dmolon opened this issue Jun 20, 2023 · 5 comments
Open

ConcurrentLogin Example #243

dmolon opened this issue Jun 20, 2023 · 5 comments

Comments

@dmolon
Copy link

dmolon commented Jun 20, 2023

Hello!

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

Thanks!

@maliming
Copy link
Member

hi

Their implementation is almost the same.

@dmolon
Copy link
Author

dmolon commented Jun 21, 2023

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
Copy link
Member

microservices solution

Are you using the abp microservice? eg eShopOnAbp?

@dmolon
Copy link
Author

dmolon commented Jun 22, 2023

microservices solution

Are you using the abp microservice? eg eShopOnAbp?

We've created a microsservice solution using ABP Suite.

@maliming
Copy link
Member

hi

The ConcurrentLogin doesn't work for the microservice solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants