简体   繁体   English

外部 IDP 的 Keycloak 外部登录页面

[英]Keycloak external login page for external IDP

In our spring boot app, we are using keycloak and we configured multiple external IDP.在我们的 spring boot 应用程序中,我们使用 keycloak 并配置了多个外部 IDP。 Everything is working successfully on browser based.一切都在基于浏览器的平台上成功运行。 The login page that is provided by keycloak is showing direct grant option in addition to login with IDPs then if user clicks to login using IDP, he is redirected to IDP's login page then our keycloak receives the token. keycloak 提供的登录页面除了使用 IDP 登录外,还显示直接授权选项,如果用户单击使用 IDP 登录,他将被重定向到 IDP 的登录页面,然后我们的 keycloak 会收到令牌。

What I want to change in that flow is that instead of showing user login page of keycloak I want to show him login page from my app(my FE) which is dealing with my BE api.我想在该流程中更改的是,我不想显示 keycloak 的用户登录页面,而是想显示我的应用程序(我的 FE)中处理我的 BE api 的登录页面。 My BE would dealing with KC.我的 BE 会处理 KC。 then If user select to login with IDP I want to get the redirect url from KC to pass it to my FE.然后如果用户选择使用 IDP 登录,我想从 KC 获取重定向 url 以将其传递给我的 FE。 Then after getting the token I want to redirect user to my FE immediately.然后在获得令牌后我想立即将用户重定向到我的 FE。

In other words I don't want users to access KC directly this should be throughout my BE换句话说,我不希望用户直接访问 KC 这应该贯穿我的整个 BE

Your client applications should never have access to users credentials.您的客户端应用程序永远不应访问用户凭据。

I'd consider things an other way arround (I make assumptions on your setup because you didn't give much details about it):我会考虑另一种方式(我对你的设置做出假设,因为你没有提供太多细节):

  • provide Keycloak with a custom theme to match your client application(s) look & feel为 Keycloak 提供自定义主题以匹配您的客户端应用程序的外观
  • probably change your Spring backend configuration from client to resource-server .可能将您的 Spring 后端配置从client更改为resource-server In OAuth2 wording, REST APIs are resource-server, not clients.在 OAuth2 的措辞中,REST API 是资源服务器,而不是客户端。
  • probably switch from 302 (redirect to Spring's oauth2Login ) for unauthorized request to 401 (which is the standard HTTP status for unauthorized request)对于未经授权的请求,可能从 302(重定向到 Spring 的oauth2Login )切换到 401(这是未经授权请求的标准 HTTP 状态)
  • probably, in your SPA client(s), use one of certified OIDC client libs to handle authorization-code flow with PKCE, silent token refreshing before it expires, HTTP interceptor to insert access token, route guards with auto-login,... My favorite for Angular is angular-auth-oidc-client可能,在您的 SPA 客户端中,使用经过认证的 OIDC 客户端库之一来处理带有 PKCE 的授权代码流、令牌过期前的静默刷新、用于插入访问令牌的 HTTP 拦截器、具有自动登录功能的路由保护,...我最喜欢的 Angular 是angular-auth-oidc-client

If I'm right about your REST API being configured with spring-boot-starter-oauth2-client and if you don't know yet how to configure it with spring-boot-starter-oauth2-resource-server , you can refer to Spring official doc or to this tutorials i wrote.如果我关于你的 REST API 是用spring-boot-starter-oauth2-client配置的是正确的,如果你还不知道如何用spring-boot-starter-oauth2-resource-server配置它,你可以参考Spring 官方文档或我写的本教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM