The Web Application Security Hub

Welcome to this hub for modern web application security. This page dives deep into the realm of…

Member-only story

Claims Transformation in .NET 6

--

OAuth2 is a great protocol to authenticate people. And it does just that: Authentication. So.. What about authorization?

Implementing authorization in an API is pretty straightforward. And there are several ways to do it. In many projects, authorization and business logic tend to get mixed up. As a result, the code of the average, simple API endpoint gets more complex. And as a result, features get harder to implement and the application becomes less secure. So, needless to say: Don’t mix the two. But how do you do that?

To authorize means to apply a policy to a person in the context of him/her trying to access a resource. To be able to apply a policy that makes sense in your business context, you’ll probably need relevant domain-specific information about the person. But an access_token doesn’t contain that information by default. So, assuming we don’t want to put that information in the token, where do we put that? And how would that work?

Default claims you can use for authorization

When a user has authenticated and invokes an API endpoint with his/her access token, ASP.NET turns the token into a ClaimsIdentity. This ClaimsIdentity is available in your controller when you type:

--

--

The Web Application Security Hub
The Web Application Security Hub

Published in The Web Application Security Hub

Welcome to this hub for modern web application security. This page dives deep into the realm of OAuth2/OpenID Connect and cloud-native applications. Our mission is clear: to make security comprehensible, accessible, and affordable for every web-developer out there!

Albert Starreveld
Albert Starreveld

Written by Albert Starreveld

Passionate about cloud native software development. Only by sharing knowledge and code can we take software development to the next level!

Responses (2)