I've asked a similar question before but did not get an answer to help me understand how custom storage providers for ASP.NET Core Identity work, so I'm going to try asking the question in a different way.
Assuming I have a custom storage provider implemented for ASP.NET Core 2.2, what code in my implementation would allow the [Authorize]
attribute to check if user has a role? For example, if an action has [Authorize (Role = "Manager")]
, what is the code that goes into my custom tblRoles
in the database based on the "Manager"
value in the attribute?
To be clear, I'm not asking for the specific logic that accesses the database and checks if user has a role. I'm asking where would that logic be?
To me, it seems like it would be in the CustomRoleStore
class, but the methods there never execute unless I explicitly call them. And if I need to explicitly call them, then why do I need a CustomRoleStore
? I might as well just make my own service that handles user authorization for each action and not complicate my code with Identity.
Sorry that this question is all over the place, but I feel I'm missing some key points on how Identity handles authorization, and it's hard to know what to exactly ask to gain understanding.
I did more research and found a great series of tutorials: https://www.youtube.com/watch?v=Fhfvbl_KbWo&list=PLOeFnOV9YBa7dnrjpOG6lMpcyd7Wn7E8V
In the 4th video at 20:13, the Role
in [Authorize]
attribute is explained. The [Authorize]
attribute uses the role value and simply compares it to the role claim of the identity.
From what I understand, that's really it and implementation of custom storage providers isn't directly related to this.