How does an authorized attribute work in Web API?
How does an authorized attribute work in Web API?
906
31-Dec-2023
Updated on 23-Jan-2025
Khushi Singh
23-Jan-2025In Web API the [Authorize] attribute is used to limit access to controllers or certain actions depending on the user’s authentication levels. It makes sure that initiated and/or approved clients are only drawn to specific interfaces or terminus of the API.
How It Works
Authentication: [Authorize] attribute is responsible for examining if the request has been made by an authenticated user. Authentications guarantees that the user is indeed whom they claim to be (for instance by tokens, cookies or credentials).
Authorization: After confirming the identity the attribute checks whether the user has the appropriate privileges or roles to use the resource. For example, it can limit users with certain roles like “Admin,” or “Manager.”