Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CH02 - Invoke Service return 403 but myrole is added to access_token #19

Open
jockexa opened this issue Oct 11, 2023 · 5 comments
Open

Comments

@jockexa
Copy link

jockexa commented Oct 11, 2023

I have a bit of a strange issue where "myrole" is added to the access_token but Invoke Service function still return "403 - Access Denied"

"Show Access Token"
image

Text after pressing "Invoke Service" button at http://localhost:8000/
image

@fluke777
Copy link

fluke777 commented Nov 6, 2023

Seeing the same issues. Did you manage to resolve it?

@fluke777
Copy link

fluke777 commented Nov 7, 2023

Staring for a bit into the source code of keycloak-node-connect I think I figured out the issue in my case. Since it was something I created it might not be the same in your case but maybe it helps someone else.

The issue was I changed this line

app.get("/secured", keycloak.protect("realm:myrole"), function (req, res) {

to this

app.get("/secured",` keycloak.protect("myrealm:myrole"), function (req, res) {

Since I thought the realm has to be the name of the realm. But it is a description where the role should be looked for. The algorithm of the keycloak protector is here and the check for the role Token.prototype.hasRole that is uses is here.

Here is the working function with couple of printouts that might help you debug.

app.get("/secured", keycloak.protect("realm:myrole"), function (req, res) {
  let tok = req.kauth.grant.access_token;

  console.log(tok.hasRole("realm:myrole"));

  res.setHeader("content-type", "text/plain");
  res.send("Secret message!");
});

@bjorntj
Copy link

bjorntj commented Jan 16, 2024

I am having the same issue, any solutions?

@borisekm
Copy link

borisekm commented Feb 25, 2024

For me the problem was that in docker it wasn't working but running npm start directly was OK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants