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

Authentication Cookie #2

Open
BartoGabriel opened this issue Sep 20, 2022 · 0 comments
Open

Authentication Cookie #2

BartoGabriel opened this issue Sep 20, 2022 · 0 comments

Comments

@BartoGabriel
Copy link

BartoGabriel commented Sep 20, 2022

Hello. First of all thank you very much for the project, it is being very useful to me.

I wanted to propose saving the authentication information in the cache memory, taking advantage of the fact that the memory is already used to store the tokens. This would make the authentication cookies much smaller.

Code

            builder.Services
                .AddAuthentication(options =>
                {
                    options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                    options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;                    
                })
                .AddCookie(setup =>
                {
                    setup.SessionStore = new MemoryCacheTicketStore(TimeSpan.FromMinutes(60));
                    setup.ExpireTimeSpan = TimeSpan.FromMinutes(60);
                    setup.SlidingExpiration = true;
                })

Where MemoryCacheTicketStore would be in charge of saving the data in the cache and obtaining it. I can share the code.

Before:

image

After:

image

Secondly

You could stop using the session (AddSession), to handle the saving of tokens. With this approach of putting the SessionStore on the server side, the tokens could be saved in the user's claims and with a single cookie (the authentication one) all the user's data would be obtained.

What it wouldn't cover are users who aren't authenticated, but since they don't have a token it doesn't make sense to store anything.

Is my thinking correct or am I missing something?

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

1 participant