简体   繁体   English

Spring Boot、React 和 OpenId Connect

[英]Spring Boot, React and OpenId Connect

We have a use case where we are implementing OpenId Connect in a Spring Boot (backend) + React (frontend) application.我们有一个用例,我们在 Spring Boot(后端)+ React(前端)应用程序中实施 OpenId Connect。 We are implementing Authorization code flow.我们正在实施授权代码流程。
The backend and frontend are on separate domain.后端和前端位于不同的域中。
Here is the flow that happens:这是发生的流程:

  1. The backend returns the generated URL which can be open by the React App for login (redirecting to Cognito in our case - but it can be anything) - or even this URL can be generated on the Frontend itself - since the clientId will be exposed in the URL anyway后端返回生成的 URL 可以由 React App 打开以进行登录(在我们的例子中重定向到 Cognito - 但它可以是任何东西) - 或者甚至这个 URL 可以在前端本身生成 - 因为 clientId 将暴露在URL 无论如何
  2. The user logs in, a request is sent to the redirect uri, where the Authorization Code is used to get an access token, id token and refresh token用户登录,向redirect uri发送请求,其中Authorization Code用于获取access token、id token和refresh token
  3. When this ends, we have the tokens but how do we transfer them to the React App in the other domain?当这一切结束时,我们有了令牌,但我们如何将它们转移到另一个域中的 React App? I assume redirection and passing the tokens as query parameters makes sense - something like return "redirect://http://www.yourfrontenddomain.com?access_token" + tokenValue;我假设重定向和传递令牌作为查询参数是有意义的——比如return "redirect://http://www.yourfrontenddomain.com?access_token" + tokenValue;

Am i missing something here or my approach is fine?我在这里遗漏了什么或者我的方法很好吗?
Using Implicit flow here would be easier - but this is less secure and only recommended for Javascript apps - here we have a mix of Backend + Frontend.在这里使用隐式流会更容易——但这不太安全,并且只推荐用于 Javascript 应用程序——这里我们有后端 + 前端的组合。
Thanks a lot in advance非常感谢提前

Ok it seems i was not understanding the concepts correctly.好的,看来我没有正确理解这些概念。 Authorization code flow with PCKE is exactly made for this use case - to be used in SPA's or Mobile clients. PCKE 的授权代码流正是为这个用例而设计的——用于 SPA 或移动客户端。 By using that flow, we can just use Spring Security and just validate the tokens on the backend (without generating them or anything)通过使用该流程,我们可以只使用 Spring Security 并只在后端验证令牌(不生成它们或任何东西)

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

相关问题 Spring 启动连接 AWS java.net.ConnectException:连接被拒绝 - Spring boot connect AWS java.net.ConnectException: Connection refused 使用 OpenID Connect 的 AWS 跨账户角色 - AWS Cross-account Role with OpenID Connect 如何从 Spring Boot App 连接到运行在不同主机上的多个 Google spanner 数据库 - How to Connect to Multiple Google spanner DB running on different host from Spring Boot App 如何在没有 aws acceskey 和 secretkey 的情况下使用 spring 启动应用程序连接 aws secret manager - how to connect aws secret manager using spring boot application without aws acceskey and secretkey 在 AWS Cognito 中将外部身份验证服务器配置为 OpenID Connect 身份提供商 - Configure external auth server as OpenID Connect identity provider in AWS Cognito Identity Platform 登录 - 使用 OpenID connect provider 和 Code Flow - Identity Platform Sign In - using OpenID connect provider with Code Flow 来自 Spring 引导的 Amazon AppConfig - Amazon AppConfig from Spring Boot spring 开机编译找不到符号组件可以 - spring boot compilation cannot find symbol componentscan Spring 在 Google Cloud App Engine 上启动托管 - Spring Boot hosting on Google Cloud App Engine 主机 spring 启动 api 使用 aws lambda - Host spring boot api using aws lambda
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM