Closed cybercoder closed 1 year ago
It seems to be realm role, try prefixing it with realm:
so it should be realm:admin
Closed due to no response. Just tell me if you had issues.
Having the same issue, any help? Thanks!
It seems to be realm role, try prefixing it with
realm:
so it should berealm:admin
Tried this, did not work..
For me worked:
you can check on which level you create roles if is realm roles or client roles
please refer to this:https://stackoverflow.com/questions/73653840/keycloak-and-nodejs-nestjs-wrong-role-mismatch response: 3
I needed to add the role to the client, but I've added the role to the realm wrongly.
In nest js this code will help, if the role is at the realm level:
@Get('/admin') @Scopes('delete') @Roles({ roles: ["realm:admin"] }) getAdmin(): string { return 'admin'; } If the role is at the client level:
@Get('/admin') @Scopes('delete') @Roles({ roles: ["admin"] }) getAdmin(): string { return 'admin'; }
I'm using in multi-tenant mode with
bearerOnly: true
I've registered the module like this:import:
and providers:
The log shows everything is correct but resources are denied due to mismatched role(s). The example controller:
The log shows:
As you see
"realm_access":{"roles":["default-roles-testrealm","offline_access","admin","uma_authorization"]}
But the role doesn't match.Keycloak version: 19.0.1 NestJS core and common version: 9.0.0 nest-keycloak-connect version: 1.9.0