-
-
Notifications
You must be signed in to change notification settings - Fork 534
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
Tokens are too big - Not understand why #2239
Comments
Hey @lufo88ita, Hope you're doing well! 😃
3K characters sounds a bit high: I just tested that using the console+ASP.NET Core server sample sandboxes you can find in this repo and I'm getting a 2.1K character-long access token with encryption enabled, 1.1K characters with encryption disabled (JWE definitely adds some overhead 😄).
There's sadly no miracle solution, but here's a few remarks:
Hope it will help 😃
Thanks! Merry Christmas to you and your teammates and thanks again for sponsoring the project! 🎄 🎁 |
That's exactly what I need. I will test it when I return in office. I will close the ticket, I already get all the information I need!
We already force them to use introspection, so this is not a problem. ;-) Many thanks! P.S. EDIT For missing quote |
My pleasure. Feel free to reopen if you need additional details when returning to the office 😃 All the best. |
Unfortunately I must reopen the issue, because I forgot a point. I tried in development with this approach
I use also a symmetric key for the encryption. Consider the tokens contains the following claims: The approach reduce the size of the idtoken (~800 characters, from 1.1k -300 characters), reduce the size of the accesstoken (~1.7k, from 2.1k -400 characters), reduce a lot the size of the refresh token, but it remain a bit large (~2.2k, from 3.2k, -1000 (!) characters). But it doesn't matter if these size are what you expect, just need a confirmation that the size of the refresh token is not wrong. Is it correct that is the biggest one of the three? Also: I use 8kb as max header size as empirical value. Is it safe to have these sizes for the tokens? |
Happy New Year! 🎉
Yes: refresh tokens contain all the claims that you originally added when calling
Refresh tokens are never used in headers (only in request forms/JSON responses), so a specific header size limit will have no impact. Request form limits are generally high enough not to require any specific tweak, even when having large refresh tokens. |
Happy new year too :-D
Ok, I understand now.
Apologize me, I know refresh token are used only in the body of a POST. I refer to the accesstoken, but you answer to this as well :-D Thanks. Now: maybe I found a problem with a dependency you use (also in 6.0.0): inside is called but the class Microsoft.IdentityModel.Tokens.X509SecurityKey accept only RSA key as described in this issue :-( Inside the class at Row 49:
Row 72 as well: So if I use a certificate with ECDSA it does not populate the private/public key and this implicate that we cannot use a certificate with ecdsa. Just to be explicit: this is not a problem with openiddict, it's a problem with a dependency!!!! I guess the only alternative (for now) is using a symmetrical key to encrypt and sign the tokens (as alternative to RSA) |
Yeah, not sure why IdentityModel still doesn't support ECDSA certificates or why that PR isn't merged yet... it's really a long-time demand. That said, you don't have to use certificates: OpenIddict also supports "raw" RSA or ECDSA keys (i.e that are not extracted from a X.509 certificate). Working with such keys wasn't very convenient in previous .NET versions, but recent .NET releases offer very useful APIs to import/export ECDSA keys using standard formats (e.g PEM). You can easily generate an ECDSA key and export the private key using the PEM format: using var algorithm = ECDsa.Create(ECCurve.NamedCurves.nistP521);
var pem = algorithm.ExportECPrivateKeyPem(); And you can easily re-import it and inject it in OpenIddict's configuration: var algorithm = ECDsa.Create(); // Note: do not dispose the instance.
algorithm.ImportFromPem(pem);
options.AddSigningKey(new ECDsaSecurityKey(algorithm)); Cheers. |
Ok, all works like a charm. Regards, |
My pleasure! Thanks again for sponsoring the project! ❤️ |
Confirm you've already contributed to this project or that you sponsor it
Version
5.8.0
Question
Hi Kevin,
as a reminder:
I need an advice to reduce the size of the tokens (access token, id token, refresh token): they are long more than 4000 characters and the server refuse to process a token that big.
I put in the tokens about 15 claims (max 20 characters for claim) so I don't think that is the problem. I tried to leave only one claim (email) and the tokens size is over 3000 characters still.
So I guess, but I am not sure, the problem is in the encryption.
In dev environment we use this:
While on the staging machine (the software is not in production yet :-) ) we use a RSA 2048 bit certificate.
Any advice? Is the correct way of encrypt the tokens? We miss somthing we can use to reduce the size?
Happy Holydays :-D
The text was updated successfully, but these errors were encountered: