获取"参数无效:redirect_uri"使用KeyCloak

时间:2016-05-09 12:17:50

标签: node.js npm keycloak

我使用Node.JS(express)和一个名为keycloak-connect的NPM连接到一个keycloak服务器。
当我实现所描述的默认机制来保护路由时:

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

我确实被引用了keycloak,但有以下错误:&#34; 参数无效:redirect_uri &#34;

我的查询字符串为:(xx用于演示)
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

我的keycloak.json是:(xx用于演示)

{
  "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
}

keycloak配置:

enter image description here

enter image description here

2 个答案:

答案 0 :(得分:14)

我猜您在客户端设置标签中为客户端网址添加了一个端口。

e.g。

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

只需删除端口

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

同样适用于Valid Redirect URIsWeb Origins

1更新

enter image description here

2使用您的网址

进行更新

enter image description here

答案 1 :(得分:0)

我不知道您是否会继续怀疑,但我必须通过以下方式通过https调用配置节点服务器:

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);
...

然后适配器自动将https发送给密钥斗篷