# I am a new learner and I have a small problem with roles

**URL:** https://forum.keycloak.org/t/i-am-a-new-learner-and-i-have-a-small-problem-with-roles/30169
**Category:** Miscellanaeous
**Created:** [June 29, 2025, 3:11pm UTC](https://forum.keycloak.org/t/i-am-a-new-learner-and-i-have-a-small-problem-with-roles/30169 "2025-06-29T15:11:52Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![taha](https://avatars.discourse-cdn.com/v4/letter/t/ea5d25/32.png) [@taha](https://forum.keycloak.org/u/taha)
#### Post date: [June 29, 2025, 3:11pm UTC](https://forum.keycloak.org/t/i-am-a-new-learner-and-i-have-a-small-problem-with-roles/30169/1 "2025-06-29T15:11:52Z")

</div>

I am a new learner, and I have a small problem with roles.

> **[Keycloak---Identity-and-Access-Management-for-Modern-Applications-2nd-Edition-ma...](https://github.com/taha2samy/Keycloak---Identity-and-Access-Management-for-Modern-Applications-2nd-Edition-main/tree/master/ch2)**
>
> Contribute to taha2samy/Keycloak---Identity-and-Access-Management-for-Modern-Applications-2nd-Edition-main development by creating an account on GitHub.

This is a simple example application using Keycloak that I am learning from. I am implementing it with both a frontend and a backend.

I successfully logged in, but the backend does not allow me to access a private page. The backend is supposed to check for a realm role named `myrole` to grant access to the page.

The role `myrole` exists, and I have added it, but the backend does not verify it and seems unable to recognize it, which is causing the issue.

At the same time, the role `myrole` is present in the JWT.

```javascript
var express = require('express');
var session = require('express-session');
var Keycloak = require('keycloak-connect');
var cors = require('cors');
var dns = require('node:dns');
const { isNumberObject } = require('node:util/types');

dns.setDefaultResultOrder('ipv4first');

var app = express();

app.use(cors());

var memoryStore = new session.MemoryStore();

app.use(session({
  secret: 'some secret',
  resave: false,
  saveUninitialized: true,
  store: memoryStore
}));

var keycloakConfig = {
  "realm": process.env.KEYCLOAK_REALM || "myrealm",
  "bearer-only": true,
  "auth-server-url": process.env.KEYCLOAK_URL || "http://localhost:8080/auth/",
  "ssl-required": "external",
  "resource": process.env.KEYCLOAK_CLIENT || "myclient",
  "confidential-port": 0
};

var keycloak = new Keycloak({ store: memoryStore }, keycloakConfig);

app.use(keycloak.middleware());

app.get('/secured', keycloak.protect('realm:myrole'), function (req, res) {
  res.setHeader('content-type', 'text/plain');
  res.send('Secret message!');
});

app.get('/public', function (req, res) {
  res.setHeader('content-type', 'text/plain');
  res.send('Public message!');
});

app.get('/', function (req, res) {
  res.send('<html><body><ul><li><a href="/public">Public endpoint</a></li><li><a href="/secured">Secured endpoint</a></li></ul></body></html>');
});

app.listen(3000, function () {
  console.log('Started at port 3000');
});

```

the frontend when i try to acess invoke service which need myrole permission it does not work

 ![image](https://global.discourse-cdn.com/free1/uploads/keycloak/original/2X/f/feea0bbd80ecf5071a87a94ab64f4b9546076c1e.png)

The frontend does not work when I click the “Invoke Service” button, which requires the `myrole` permission.

---

<div class="post-metadata">

### Author: ![taha](https://avatars.discourse-cdn.com/v4/letter/t/ea5d25/32.png) [@taha](https://forum.keycloak.org/u/taha)
#### Post date: [June 30, 2025, 9:15am UTC](https://forum.keycloak.org/t/i-am-a-new-learner-and-i-have-a-small-problem-with-roles/30169/2 "2025-06-30T09:15:16Z")

</div>

```javascript
app.get('/secured', keycloak.protect('realm:myrole'), function (req, res) {
  res.setHeader('content-type', 'text/plain');
  res.send('Secret message!');
});

```

I want to understand why this backend cannot read `'realm:myrole'`.

---

<div class="post-metadata">

### Author: ![taha](https://avatars.discourse-cdn.com/v4/letter/t/ea5d25/32.png) [@taha](https://forum.keycloak.org/u/taha)
#### Post date: [July 4, 2025, 8:38pm UTC](https://forum.keycloak.org/t/i-am-a-new-learner-and-i-have-a-small-problem-with-roles/30169/3 "2025-07-04T20:38:40Z")

</div>

hiiiiiiiii … 👋?
