Replies: 1 comment
-
I am happy with the proposed @Hanlder implementation as it will simplify and get rid of a lot of boiler plate code. My thoughts on the the @authorize decorator: The proposed implementation for basic and Role based handlers is very good. For configurable Authorization rules, I would prefer to introduce Claims and Policy based Authorization where a developer can register any Authorization policy and claims for any custom requirement. Example: [Authorize(Policy:['delete']] where the developer registered policy for 'delete' would kick in. Or suppose database roles are used instead of token based roles, a developer can register an Authorization policy for [Authorize(Policy:['admin']] |
Beta Was this translation helpful? Give feedback.
-
The
@Handler
decoratorToday we have command handlers, which use the
@Handles(Command)
decorator to become handlers of a given command. In these command handler function there are 2 repeating patterns of code that do the followingGiven that the above formula is typical for the majority of cases, we can omit a lot of boiler plate using annotations on the command itself. Something like this:
This would create a command handler behind the scenes that would look like this:
Should you want to do something more specific, you can always write your own handler and use the
@Handles
decorator as normal.The
@Authorize
decoratorSimilarly, an
@Authorize
decorators can be used on commands directly, here are some of the different scenarios that should cover most – if not all the cases.Basic Authorization
We could have a simple decorator that ensures only authenticated users can trigger certain commands.
Role-Based Authorization
Extending the decorator to accept roles could help in ensuring that only users with certain roles can execute specific commands.
Configurable Authorization Rules
By utilizing decorator factories, we can create customizable authorization decorators. This would provide a flexible way to enforce complex authorization rules based on various criteria.
Function-Based Authorization
We could enable passing of authorization-checking functions to the decorator, allowing for complex, logic-based authorization checks.
These decorators would work hand in hand with the
@Handler
decorator setup, making authorization checks more declarative and reducing boilerplate.Beta Was this translation helpful? Give feedback.
All reactions