What could be the ways to handle user features based on subscription tiers in Blazor?

Viewed 142

I was thinking about ways to handle nicely parts/pages/features of a Blazor WebApp based on which subscription tiers a user belongs.

First that came in mind is the native use of <AuthorizeView> with Roles as the main distinguiscer(so other than the normal "user" role it could be concatenated with "professional", "business" or "enterprise".

But I was wondering: is there any other alternative?

2 Answers

I'd suggest you to use the newer, and recommended, policy-based authorization with Blazor. Role-based authorization had been popular in Asp.Net, and it is becoming obsolete. It is enabled in .NET Core mainly because of compatibility reasons. But even Role-based authorization, in .NET Core, is implemented via claims.

The way to go is policy-based authorization. It is much easier to manage than Role-based authorization... and you can easily integrate it with the AuthorizeView component and the Authorize attribute. There are other issues with the Role-based authorization, which is demanding and requires you to write code, as for instance, Blazor expects to get a list of roles as in the following: Authorize[Roles="role1, role2, role3"], while identity server sends a single claim which is made of three roles. Consequently, you'll need to extract the roles and provide it to Blazor in the form of a list. This requires lots of work, and knowledge. OK..., I won't confuse you any further. Just forget about roles.

I would 100% use roles. You can give a person multiple roles, so you could do tiers, or even component-membership: "Unlock X page, unlock Y feature"

Related