微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

nodejs Keycloak 适配器使用 ssl 强制 redirect_uri

如何解决nodejs Keycloak 适配器使用 ssl 强制 redirect_uri

我有一个带有 keycloak 适配器保护 https://example.com(使用 SSL)的 nodejs express 应用程序

我的 keycloak 适配器是这样配置的:

enter image description here

注意两个 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 举报,一经查实,本站将立刻删除。