I'm implementing a Nodejs backend API's.
(我正在实现Nodejs后端API。)
Some of them are need to authenticate before access. (其中一些需要在访问之前进行身份验证。)
for that I choose keycloak server as identity server. (为此,我选择keycloak服务器作为身份服务器。)
I used npm keycloak-connect library to integrate node server and the keycloak server. (我使用npm keycloak-connect库来集成节点服务器和keycloak服务器。)
Now the authentication are woking fine. (现在身份验证正常。)
problem is when I logout from keycloak server by using ' http://localhost:8080/auth/realms/test-realm/protocol/openid-connect/logout ' this API.
(问题是当我通过使用' http:// localhost:8080 / auth / realms / test-realm / protocol / openid-connect / logout '此API从keycloak服务器注销时 。)
keycloak server says token is not valid anymore. (keycloak服务器说令牌不再有效。)
But when I used the same taken to access Node server it takes that token as valid token. (但是,当我使用相同的方法访问节点服务器时,它将该令牌作为有效令牌。)
'use strict';
const Keycloak = require('keycloak-connect');
const express = require('express');
var cors = require('cors')
const app = express();
app.use(cors())
var keycloakConfig ={
"realm": "test-realm",
"auth-server-url": "http://localhost:8080/auth",
"ssl-required": "external",
"resource": "test-dev-api",
"public-client": true,
"confidential-port": 0
}
var keycloak = new Keycloak({},keycloakConfig);
app.use( keycloak.middleware( { logout: '/logout'} ));
app.get('/secured-echo', keycloak.protect(), function(req,resp) {
resp.send("Secured Hello");
});
//unprotected route
app.get('/echo', function(req,resp) {
console.log(keycloakConfig)
console.log(keycloak)
resp.json({"say": "hello"});
});
app.listen(4000, function () {
console.log('Listening at port:4000');
});
ask by Padmasankha translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…