【发布时间】:2021-02-22 09:33:09
【问题描述】:
我有一个 React JS 应用程序,它向我的后端 API 发出这个请求。即
window.location = "https://my-server.com" + "/gmail/add_account";
无法为 window.location see this 设置 HTTP 标头
此服务器端点重定向到 Google OAuth 页面,该页面返回对我的 redirect_uri 的响应。
def add_account
# no auth headers sent here, because front-end has used window.location
gmail_service = GmailService.new
session[:uid] = params["uid"]
redirect_to gmail_service.generate_authorization_url()
end
def oauth_postback
# session object is {} here
# Since there are no authorization headers, I cannot identify my app's user
# How can I identify my app's user here?
end
我面临的问题是,当 OAuth 流向我的redirect_uri 发送响应时,它不返回包含任何authorization header,因此我无法确定我的应用程序的哪个用户启动了这个OAuth 流程。
我尝试在/gmail/add_account 端点中设置会话变量,效果很好。在此端点重定向到 OAuth 屏幕并且 Oauth 流向我的 Oauth redirect_uri 发送响应后,我的 session 对象是 {}。
如何实现此流程以便我知道哪个用户启动了此 OAuth 流程?
【问题讨论】:
标签: ruby-on-rails authentication oauth-2.0