NikiforovAll / keycloak-authorization-services-dotnet

Authentication and Authorization with Keycloak and ASP.NET Core 🔐
https://nikiforovall.github.io/keycloak-authorization-services-dotnet/
MIT License
434 stars 103 forks source link

Add function to fetch list of user's permissions #127

Open pbolduc opened 1 month ago

pbolduc commented 1 month ago

We have a number of applications that use bespoke versions of the keycloak authorization code in .NET to do policy enforcement. I would like to migrate to use your library. However, we have a requirement to be able to fetch the user's current permissions. These permissions are fetched from the web UI application via an authenticated API. The permissions are used for security/feature trimming based on the permissions. The data access and update APIs are still protected with policy enforcement.

I have an implementation that fetches the user's permssions. This function returns a list of resources and the associated scopes.

public record Resource
{
    public string Id { get; set; } = string.Empty;
    public string Name { get; set; } = string.Empty;

    public string[] Scopes { get; set; } = [];
}

I would like to submit a pull request with these changes to your repository. Where should I add this code. It would seem logical to add a method to IAuthorizationServerClient / AuthorizationServerClient.

NikiforovAll commented 1 month ago

I think it is already implemented, please take a look:

https://nikiforovall.github.io/keycloak-authorization-services-dotnet/protection-api/protected-resource-client.html

https://nikiforovall.github.io/keycloak-authorization-services-dotnet-docs/api-reference/Keycloak.AuthServices.Sdk.Protection.Models.ResourceResponse.html?q=ResourceResponse