Node.js Authentication with Key cloak server

246 views
Skip to first unread message

Shreyansh jain

unread,
Oct 26, 2021, 12:47:17 AM10/26/21
to Keycloak User
I am using below code for keycloak inside my NodeJS application but once I use keycloak.protect() inside function it is not working. 

app.get('/testPage', testFunction);

function testFunction(req, res) {
    keycloak.protect(), function (req, res) {
        res.render('index', {
            result: JSON.stringify(JSON.parse(req.session['keycloak-token']), null, 4),
            event: '1. Authentication\n2. Login'
        });
    }
}
URL: http://localhost:port/testPage   Not working 

When I used app.get('/loginPage',
    keycloak.protect(), function (req, res) {}); it is working fine. Please let me know what is the issue?

How I can use inside the function this keycloak.protect() method.

URL: http://localhost:port/testPage   working 




app.get('/loginPage',
    keycloak.protect(), function (req, res) {
        res.render('index', {
            result: JSON.stringify(JSON.parse(req.session['keycloak-token']), null, 4),
            event: '1. Authentication\n2. Login'
        });
    }
);

Reply all
Reply to author
Forward
0 new messages