-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
✨ Improve authorization performance #1046
Comments
To add one more point: If I have an Authorize attribute with multiple Roles, like The quick fix would be to change But! The user and role information is already present in the So some refactoring might be justified? Or is there some specific issue you tried to avoid organizing code this way? I do remember some weird issues the ClaimsPrincipal not noticing Role changes, but that could have been because I was hacking directly into the database... |
Hi all!
I've been looking into the
IdentityService
and specifically theAuthorizeAsync
andIsInRolesAsync
method that I use extensively to authorize the current user's commands and queries.Each authorization is quite expensive since each request has to make at least one roundtrip to the database to fetch the user by id to create a
ClaimsPrincipal
. This of course is fine if we need to authorize any arbitrary user, but for the current user this seem unnecessary as we already have a claims principal - after all, that's where we extract the user id from in the first place in theCurrentUser
service.Would it not be better to use the claims principal we already have as much as possible? Especially for the
AuthorizationBehaviour
that might have a high hit rate.This could be solved in a few ways;
AuthorizeAsync
method to theIUser
service. I think this would be the nicest API, but for some reason does not work for me, as the application hangs (not crashes) when injectingIAuthorizationService
intoCurrentUser
.ClaimsPrincipal
property on theIUser
service, and add a newAuthorizeAsync
overload to theIdentityService
that accepts aClaimsPrincipal
instead of a user id.Do you see any issues with this approach, or have better proposals?
Thanks
The text was updated successfully, but these errors were encountered: