nest-keycloak-connect icon indicating copy to clipboard operation
nest-keycloak-connect copied to clipboard

ResourceGuard always results in 403 Forbidden Error?

Open IRuFFeYI opened this issue 2 years ago • 0 comments

I try to use Keycloak as Authorization Services. I want to secure the endpoints of my REST API with resources, scopes and permissions.

The problem is, I get a 403 Forbidden Resource Error on every request. I try to explain my whole configuration with a lot of images. Am I missing something or have I misunderstood something?

Keycloak Configuration

Configuration of the client: image

My test rescource: image

My policy: image

My permission: image

Evaluation To test my configuration I use the internal evaluation tool. I have the user: "testcustomer" who is member of the group: Testproject. Therefore he should have access to the resource. The evaluation shows, it's working correctly: image

REST API:

In my NestJs REST API I'm using the nest-keycloak-connect-package.

This is the configuration of the KeycloakModule: image

My Test-Controller image

My understanding of the package: When a user (in this case the testcustomer) sends a request to the API to the following URI: "http://localhost:3002/api/test/test", the resource from Keycloak is associated with it. And the testcustomer is authorized to call this endpoint. Other users who are not in the Testproject group will get a 403 Forbidden response.

The problem is that I always get a 403 error no matter if my user is in the group and it doesn't even matter if the resource exists in Keycloak at all.

Note: General authentication or even authorization via roles works.

IRuFFeYI avatar Oct 14 '22 10:10 IRuFFeYI