I am trying to test login in react js application using keycloak but getting Access Denied. Please help me to find the cause. Any details needed I will provide.
Below is the simple reactjs application -
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Hello World Simple App</title>
</head>
<body>
<div>Hello World!</div>
</body>
</html>
index.js
const express = require("express");
const KeycloakMultirealm = require("keycloak-connect-multirealm");
const app = express();
const config = {};
const keycloakConfig = {
"auth-server-url": "http://localhost/auth",
"public-client": true,
"ssl-required": "none",
resource: "usermanagement-lite",
clientId: "usermanagement-lite",
};
const keycloak = new KeycloakMultirealm(config, keycloakConfig);
app.use(keycloak.middleware());
app.get("/", keycloak.protect(), (req, res) => {
res.sendFile("index.html", { root: __dirname });
});
app.listen(3000);
package.json
{
"name": "my-project",
"version": "1.0.0",
"description": "Demo",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"author": "Bishal",
"license": "ISC",
"dependencies": {
"express": "^4.18.2",
"keycloak-connect": "^11.0.3",
"keycloak-connect-multirealm": "^2.1.0",
"path": "^0.12.7",
"pem": "^1.14.8"
}
}
I am using node 18.16.1 and nginx as localhost for this application. I am trying to get keycloak login page before getting Hello World page but it is throwing me Access Denied. Please help!