简体   繁体   English

服务器端Java Web应用程序中的Google OAuth2流

[英]Google OAuth2 Flow in Server Side Web Application in Java

I am facing an issue understanding the oauth2 flow. 我在理解oauth2流时遇到问题。 A user(identified by a user_id) initiates the GoogleAccounts connection in the browser.The request is passed to Servlet that sends Redirect String To Client (Javascript), which in turn redirects user to that Auth URL. 用户(由user_id标识)在浏览器中启动GoogleAccounts连接。请求被传递到Servlet,该Servlet将重定向字符串发送到客户端(Javascript),然后将用户重定向到该Auth URL。 On User Consent, the response is returned to callback url (mapped to a servlet). 在“用户同意”上,响应返回到回调URL(映射到Servlet)。 My Confusion here is when callback servlet is called,how do i identify to which user(user_id) does this authCode belong to? 我的困惑是当调用回调servlet时,如何识别此authCode属于哪个用户(user_id)? Do i have to use state param of oAuth2 ? 我是否必须使用oAuth2的状态参数?

Please help. 请帮忙。

As the comments suggest, the state param is your friend. 正如评论所暗示的那样, state参数是您的朋友。 The simplest way would be to simply set state=user_id . 最简单的方法是简单地设置state=user_id An alternate approach would be to start a server session and store the user ID in the session object. 另一种方法是启动服务器会话并将用户ID存储在会话对象中。 This latter approach assumes you have a relatively simple server, or your cluster supports shared sessions. 后一种方法假定您有一台相对简单的服务器,或者您的群集支持共享会话。

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

相关问题 使用 oauth2 和 Google / Azure 身份验证服务器在 java 应用程序中注销时出现问题 - Problem to logout in java app with oauth2 and Google / Azure auth server Java上的OpenID和Oauth2服务器 - OpenID and Oauth2 server on Java 带有Google Cloud Storage Java的Google OAuth2 - Google OAuth2 with Google Cloud Storage Java 在防火墙后面的Wildfly / Keycloak安全Web应用程序调用时使用oauth2保护Google App Engine应用程序的安全 - Securing a google app engine application with oauth2 on call from a Wildfly/Keycloak secured web application behind a firewall 在 Web 应用程序中使用 Spring Security 实现 Oauth2 - Implementing Oauth2 with spring security in web application Java Web应用程序流程 - Java Web Application Flow 如何使用谷歌 OAuth2 和 Java 将 GET 请求发送到 script.google.com web 页面? - How to send GET request with google OAuth2 and Java to script.google.com web page? OAuth2客户端和资源服务器在同一个应用程序中 - OAuth2 Client And Resource Server in same application Tomcat 7-Google Oauth2-ClassNotFoundException-Java-Eclipse - Tomcat 7 - Google Oauth2 - ClassNotFoundException - Java - Eclipse 使用Java和Oauth2对Google云端硬盘进行身份验证 - Authenticating to Google Drive with Java and Oauth2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM