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

SignInWithoutSpecifyingTenant - Issue with Persistent User Sessions After Removing Tenant Selector #265

Open
martingagne opened this issue Jan 23, 2024 · 3 comments

Comments

@martingagne
Copy link

I have implemented the approach to remove the tenant selector as shown in the sample at SignInWithoutSpecifyingTenant. While the code works as expected and the tenant selector is successfully removed, I am encountering an issue with user sessions. Users are not staying logged in for an extended period, typically being logged out after 20-30 minutes of activity. This requires frequent re-logins, approximately a couple of times per hour.

Steps to Reproduce

  • Followed the implementation as per the SignInWithoutSpecifyingTenant sample.
  • Successfully removed the tenant selector.
  • Logged into the application.
  • After 20-30 minutes of usage, the session expires, and the user is logged out.

Environment

  • ABP Framework version: 7.4.0
  • User's browser and version: Firefox 121.0.1
  • Server environment (e.g., Windows/Linux, .NET Core version): Windows 11

How do I control the duration of the session? Ideally I would like the session to last at least a day. @maliming, is this something you can help me with?

@realLiangshiwei
Copy link
Member

@martingagne
Copy link
Author

Thank you @realLiangshiwei. I tried this and I am still having the same issue. I added the ExpireTimeSpan in the ConfigureServices of the WebModule, is this the right location?

    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        var hostingEnvironment = context.Services.GetHostingEnvironment();
        var configuration = context.Services.GetConfiguration();

        PreConfigure<AbpOpenIddictAspNetCoreOptions>(options =>
        {
            if (hostingEnvironment.IsProduction())
            {
                // https://documentation.openiddict.com/configuration/encryption-and-signing-credentials.html
                options.AddDevelopmentEncryptionAndSigningCertificate = false;
            }
        });

        PreConfigure<OpenIddictServerBuilder>(options =>
        {
            if (hostingEnvironment.IsProduction())
            {
                options.AddEncryptionCertificate(LoadCertificate("..."));
                options.AddSigningCertificate(LoadCertificate("..."));
            }
        });

        Configure<AbpAspNetCoreMultiTenancyOptions>(options =>
        {
            options.MultiTenancyMiddlewareErrorPageBuilder = async (context, exception) =>
            {
                // Handle the exception.
                Debugger.Break();

                // Return true to stop the pipeline, false to continue.
                return true;
            };
        });

        Configure<AbpTenantResolveOptions>(options =>
        {
            options.TenantResolvers.Clear();
            options.TenantResolvers.Add(new CurrentUserTenantResolveContributor());
        });

        // HttpClient
        context.Services.AddHttpClient();

        ConfigureAuthentication(context);
        ConfigureUrls(configuration);
        ConfigureBundles();
        ConfigureAutoMapper();
        ConfigureVirtualFileSystem(hostingEnvironment);
        ConfigureNavigationServices(context.Services);
        ConfigureAutoApiControllers();
        ConfigureSwaggerServices(context.Services);

        // Cookie Expiration. This impact login/logout.
        context.Services.ConfigureApplicationCookie(options =>
        {
            options.ExpireTimeSpan = TimeSpan.FromHours(48);
        });
    }

@realLiangshiwei
Copy link
Member

It works for me
image

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