Role-Based Access Control
noun
say it: “AR-bak” /ˈɑrbæk/ or “ROHL-bayst AK-ses kun-TROHL” /roʊl beɪst ˈæksɛs kənˈtroʊl/
Deciding what each user may do by their role, such as member or admin, instead of person by person.
What is role-based access control in an API?
Role-based access control (RBAC) gives permissions by role: each user has a role, such as member or admin, and each rule says which roles may do what. An API checks the role in the user's token before it runs a route.
function requireRole(...roles) {
return (req, res, next) =>
roles.includes(req.user.role) ? next() : res.status(403).json({ error: "Not allowed" });
}
app.delete("/events/:id", requireRole("admin"), deleteEvent);
In a sentence
- “With role-based access control, only admins may delete events.”
- “Adding a moderator role took one line, because the API uses role-based access control.”
Level: Journeyman · More REST API terms at this level
Updated