We are a developing an AngularJS single page application with an ASP.NET Web Api 2 REST API. We are using OWIN middleware and OAuth.
Our system consists of clients and users:
- Clients are organisations/companies.
- Users are employees of those companies. Users belong to a client.
At the moment, we are using the following check in every controller:
[Route("api/clients/{clientId}/orders/{orderId}")]
public IHttpActionResult GetOrder(int clientId, int orderId)
{
if(UserComponent.GetUser(User.Identity.Name).ClientId != clientId)
{
return NotFound();
}
// Get order
return Ok(orderModel);
}
See below sequence for more detail (refer to diagram):
Getting a token for the user (also returns clientId).
Accessing a client resource. User/client authorization:
a. The user is authorized to access client resources, or
b. The user is NOT authorized to access client resources.
Essentially, a user from client A should not be able to access a resource from client B.
What is the best way to authorize users against client resources?
Can we somehow defer this to OWIN (perhaps by using claims)?