0

We have an ASP.NET Core API that uses Windows Authentication and Claim based identity. The API has one Controller with multiple Actions. The Actions have different authorization policies.

[Authorize(Policy = "Read")]
[HttpGet]
public async Task<ActionResult<Item>> Read()
{ ... }

[Authorize(Policy = "Write")]
[HttpPost]
public async Task<ActionResult<Item>> Write(Item item)
{ ... }

In Startup.cs we have this:

services.AddAuthorization(options => {
  options.AddPolicy("Read", policy => policy.RequireClaim("OurReadType","OurReadValue"));
  options.AddPolicy("Write", policy => policy.RequireClaim("OurWriteType","OurWriteValue"));
});

We also have a front end that consumes this API. Everything works fine when the front end application accesses our API. Users have only access to read actions if they have the read claim and the same goes for write actions. When a user that has only the read claim tries to call a write action they'll get a 401 Unauthorized. This is all expected behavior. No problems so far.

The problem starts when we try to access our API from Postman. ONLY from Postman do we get 403 Forbidden errors.

Postman is configured to use NTLM Authentication using my personal username and password. And my account has both read and write claims.

If we remove the [Authorize(Policy = "Read")] annotation from an action, we no longer get the 403 error when calling that action using Postman. This makes me think that the problem is somewhere with postman and claims based authorization.

Does anybody have an idea of what the problem is? I'm fairly new to claims based identity and to using Windows authentication to this extent. So any help is appreciated.

Martijn
  • 739
  • 9
  • 26
  • When you consume the API via the front-end application, try to use F12 developer tool or fiddler to check the authentication in the request header, and compare the value with the request header in the postman. I assume when calling the API using postman, the request identity doesn't contain the claims. – Zhi Lv Oct 06 '21 at 06:06
  • Ill look into it thanks – Martijn Oct 06 '21 at 08:40

0 Answers0