Encountering the error "Invalid parameter: redirect_uri" while attempting to authenticate with KeyCloak using NODE.JS

In my Node.JS (express) project, I am utilizing a helpful NPM package called keycloak-connect to establish a connection with a keycloak server.
While trying out the default protection mechanism for a specific route:

app.get( '/about', keycloak.protect(), function(req,resp) {
    resp.send( 'Page: ' + req.params.page + '<br><a href="/logout">logout</a>');
} );

I am successfully redirected to keycloak, but encounter an error message stating: "Invalid parameter: redirect_uri"

The query string I'm using is: (xx used as placeholder)

https://xx.xx.xx.xx:8443/auth/realms/master/protocol/openid-connect/auth?client_id=account&state=aa11b27a-8a0b-4a3b-89dc-cb8a303dbde8&redirect_uri=http%3A%2F%2Flocalhost%3A3002%2Fabout%3Fauth_callback%3D1&response_type=code

This is how my keycloak.json file looks like: (xx used as placeholder)

{
  "realm": "master",
  "realm-public-key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwS00kUaH6OoERNSkFUwxEBxx2SsqmHu9oVQiPs6nlP9fNQm0cK2lpNPphbLzooZL6kivaC4VzXg20F3zY7jRDc4U/XHgXjZVZUXxJ0NeCI5ESDo00EV9xh9XL3xvXslmG0YLWpywtQSYc+XcGDkz87edokbHQIIlQc2sgoVKIKpajZyrI5wnyMhL8JSk+Mdo2T9DeNnZxPkauiKBwWFJReBO51gsoZ49cbD39FRa8pLi8W0TtXoESIf/eGUSdc3revVFR7cjzHUzxF0p0WrLsTA1aBCLkt8yhnq88NqcKsW5mkxRmhLdw20ODTdsmRtm68rjtusMwifo/dZLJ9v5eQIDAQAB",
  "auth-server-url": "https://xx.xx.xx.xx:8443/auth",
  "ssl-required": "external",
  "resource": "account",
  "credentials": {
    "secret": "9140d4e6-ed05-4899-a3c0-a9cf94ab407d"
  },
  "use-resource-role-mappings": true
}

Configuration details of keycloak:

https://i.stack.imgur.com/ns3kO.jpg

https://i.stack.imgur.com/O7rbb.jpg

Answer №1

It appears that a port was mistakenly added to your client URLs in the settings tab.

For example:

root url: https://demo.server.biz:443/cxf

Simply remove the port:

root url: https://demo.server.biz/cxf

This same correction should be applied to both Valid Redirect URIs and Web Origins.

1 Update

https://i.stack.imgur.com/eUDnY.png

2 Update with your URL

https://i.stack.imgur.com/UvSa3.png

Answer №2

In order to ensure secure communication with the node server, I had to set up https calls by configuring it as shown below:

var fs = require('fs');
var https = require('https');
.....
const HOST = 'your_site.com';
const PORT = process.env.PORT || 3001;

const key = fs.readFileSync('./certs/private.pem');
const cert = fs.readFileSync('./certs/public.pem');
const https_options = {
    key: key,
    cert: cert
};
var serverKeycloak = https.createServer(https_options, appKeyCloak);
serverKeycloak.listen(PORT, HOST);
...

This setup enables the adapter to automatically send https requests to Keycloak for enhanced security.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Create personalized access tokens through Azure Active Directory (AD)

Currently, I am working on a Next.js application that requires users to log in using their Azure ID. Once logged in, I need to verify the email and other details from the token on my Node.js backend before sending a custom token to the frontend for addit ...

Encountering Error: Unable to create new component as PriorityQueue is not recognized as a constructor

While trying to create a new component using Angular CLI with the command ng g c navbar, I encountered an unusual error message: core_1.PriorityQueue is not a constructor TypeError: core_1.PriorityQueue is not a constructor at new TaskScheduler (/h ...

Having difficulties executing a duplicated project on the local system

I recently cloned Clement Mihailescu's Pathfinding Visualizer Tutorial onto my computer and upgraded nvm to version 16.2.0 and npm to 7.15.1. Following the instructions in the ReadMe file, I tried running the following command: In the project directo ...

Sending a POST request in Node.js and Express may result in the request body being empty or undefined

Here is a snippet of my Typescript code: import express = require('express'); const app: express.Application = express(); const port: number = 3000; app.listen(port, () => { console.log("The server is now running on port" + port); ...

Is there a way to modify the maximum size limit for a POST request package?

I am encountering an issue while attempting to send an array of bytes using a POST request. In my server-side implementation, I am utilizing Node.js and Express.js. Unfortunately, I am receiving error code 413 or the page becomes unresponsive ('Payloa ...

Encountering an Issue with NPM Run Production in PostCSS

I keep encountering the same error whenever I attempt to execute 'npm run production'. The remainder of the error consists of a compilation of 'node_modules' packages where this issue is also present. ERROR in ./resources/assets/sass/ap ...

Error encountered during npm installation for hexo

Just posted my last inquiry! After following the advice to create a npm folder in the appdata/roaming directory, I attempted to install HEXO using npm with npm install -g hexo However, I encountered a strange error which is shown below I am unable t ...

Troubleshooting an expressjs server in parallel with electron

I have managed to successfully run an ExpressJS server alongside Electron by following the instructions provided in this post: Run Node.js server file automatically after launching Electron App However, I am facing an issue where there is no output from t ...

Error in JavaScript with Laravel Mix/NPM.js: The variable twemoji.parse cannot be found or is undefined

Greetings everyone, Currently, I am using Laravel Mix to integrate Twemoji and other modules through Node. Unfortunately, I am encountering console errors indicating that the dependencies are not loading correctly. One example of this error is: TypeError ...

Challenge in resolving a promise returned by the find() function in mongodb/monk

I've encountered an issue where the simple mongodb/monk find() method isn't working for me. I am aware that find() returns a promise and none of the three ways to resolve it seem to be successful. Can someone point out what mistake I might be mak ...

Retrieving data from various schemas using Node.js

I am managing two schemas, one for employees (parent) and the other for assessments (child). Each assessment is linked to an employee ID with a pass percentage. Here are some sample data: employees : [ { "_id": 12345, "name": "David", "eval ...

Using middleware in Express to handle GET requests

Can the request object sent to any route be accessed globally in Express, without having to explicitly access it in a .get method or similar? ...

What makes this code run synchronously?

function foo(cb) { if (!someAuditCondition) { return cb(new Error(...)); // <- Despite this part being synchronous, the rest of the function is asynchronous. } doSomeAsynAction(function (err, data) { if (err) { return cb(err); } cb( ...

There was an issue with the specified entry-point "auth0/angular-jwt" as it is missing required dependencies

I am currently working on an Angular project with the following versions: @angular-devkit/architect 0.901.1 @angular-devkit/core 9.1.1 @angular-devkit/schematics 9.1.1 @schematics/angular 9.1.1 @schematics/update 0.901.1 rx ...

What are the steps for scheduling asynchronous tasks using Promises in Node.js?

As a beginner in Javascript, I am struggling to understand how to execute my functions sequentially. My goal is to use Promises to accomplish this task. I am currently following a tutorial on creating a chat bot for Facebook Messenger. Essentially, I want ...

Testing events using mocha for unit testing

Are you uncertain about the best way to test this code using mocha and chai? module.exports = function trackCustomDyEvents(events){ let $; trackEvents(); function trackEvents() { events.forEach((event) => { $(document).on(event.type, even ...

Are the dependencies of a Node module not updating properly after being updated or installed?

I recently integrated react-highcharts into my application. After using npm install react-highcharts, the installation was successful, but with a warning message: found 1 high severity vulnerability, run `npm audit fix` to fix them, or `npm audit` for deta ...

When executing mocha tests within my project, I face difficulty terminating the process once the tests are completed

Currently, I am utilizing mocha for test automation purposes. Below is the testcase that I have created: const mysql_service = require('../../router/mysql_service') const chai = require('chai') var chaiAsPromised = require("chai-as-p ...

Personalize your commit message when utilizing npm version patch

Can the commit message be personalized when using npm version patch? I would prefer to modify it to :up-arrow: @VERSIONNUMBER ...

"Tips for SunPass Finesse: Navigating ESLint Errors When Committing Code on

While attempting to commit changes to my dev branch in Gitlab, I encountered errors related to ESLint which caused the commit to be aborted. To troubleshoot, I cloned the repository from the dev branch, made changes, and installed dependencies using &apos ...