zds
zds

Reputation: 964

How to organize communication in an asp.net web application using separate authorization server, web api, ui?

The requirements

The problems

The main problem is that the resources of api like \projects\12345, \users\, \projects\123456\users, etc. may also be needed as claims in IS. For example, api module reads the access token of authorized user and see the claim projects that equals ["222", "12345"], so the resource \projects\12345 or \projects\123456\users are allowed for that user. Users are identities in IS and resources in api at the same time. Projects are claims in IS and resources in api at the same time.

I thought of book-keeping these entities that are represented in both modules through the ids (guids). But ids won`t solve all the problems.

Some of them are:

Could you, please, explain how modern systems coupe with the per resource access?

Thank you for your time.

Upvotes: 1

Views: 330

Answers (1)

Athanasios Kataras
Athanasios Kataras

Reputation: 26372

First you need to make sure what a claim is.

Claim is not a permission or a role, it's what the user is. Based on what the user is, then you can assume the permissions.

https://learn.microsoft.com/en-us/aspnet/core/security/authorization/claims?view=aspnetcore-3.0

A claim is a name value pair that represents what the subject is, not what the subject can do.

So starting from that, you can get the claims and do the following.

Let's say that a user is the owner of a project. When the new project is created, the project api can update the identity server and add a claim to the user saying he is the owner.

In your apis the owner of a project has a set of permissions and based in those, access to specific resources

In the DDD Domain driven design world, a little bit of data duplication does not matter. So duplicating the possible claims that your application needs in terms of roles (again, not ids but a mapping of one or more claims to specific roles) is not a bad practice.

When you update some kind of claim from your api, you should do so in a transactional way. Think first if you need the email to be saved in both. You will get the user data from the claims anyway on every request. Is it even something you need as a claim? If not have it in your api only.

Communication between apis is organized in many ways. If you need transactions or eventual consistency is something you should also consider. Communicating with events or queues is the microservices way to go, with patterns like the SAGA being the coordinator.

Upvotes: 1

Related Questions