问题描述
我有一个带有 keycloak 适配器保护 https://example.com(使用 SSL)的 nodejs express 应用程序
我的 keycloak 适配器是这样配置的: 注意两个 URL 中的 httpS。
现在我面临一个问题,当用户成功登录(通过 keycloak)时,他会看到“无效参数:redirect_uri”错误消息。
使用我在转到 https://example.com(使用 SSL)后看到的浏览器开发工具,用户被重定向到 https://sso.example.com/auth/realms/myrealm/protocol/openid-connect/auth?client_id=my-client-id&state=22f41ed3-ddc6-4758-970b-d876cf631ded&redirect_uri=http%3A%2F%2Fexample.com%2F%3Fauth_callback%3D1&scope=openid&response_type=code
上面链接中的关键点是redirect_uri=http%3A%2F%2Fexample.com%2F%3Fauth_callback%3D1&scope=openid&response_type=code
。在这里我们可以看到 redirect_uri
没有 SSL。它是 http 而不是 https。
这就是我保护域根的方式:
const server = express()
server.set('trust proxy','loopback')
server.use(keycloak.middleware({}))
const keycloak = new Keycloak({ store: memoryStore },KEYCLOAK_CONfig) // KEYCLOAK_CONfig is the json config below
(...)
server.get('/',keycloak.protect('private-user'),(req: Request,res: Response) => {
// Set the cookie
res.cookie(ConfigService.CONfig_COOKIE_KEY,JSON.stringify(ConfigService.CONfig),{ httpOnly: false })
res.sendFile(path.join(__dirname,'build','index.html'))
return res
})
我的keycloak配置是:
{
realm: 'myrealm','auth-server-url': 'https://sso.example.com/auth/','ssl-required': 'external',resource: 'my-client-id','verify-token-audience': false,credentials: { secret: 'super-secret-credential' },'use-resource-role-mappings': true,'confidential-port': 443,'bearer-only': false,'enable-cors': true,'cors-max-age': 1000,'enable-basic-auth': false,'expose-token': true,'disable-trust-manager': false,'allow-any-hostname': false,'token-minimum-time-to-live': 10,'min-time-between-jwks-requests': 10,'connection-pool-size': 20,'public-key-cache-ttl': 86400
}
redirect_uri
必须使用 SSL。如何强制 keycloak 在 redirect_uri 中使用 https (SSL)?
将 http://example.com(非 SSL)添加到 Valid Redirect URIs
不是一种选择。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)