首页 > 解决方案 > 通过 Node.js 进行 AppEngine 身份验证

问题描述

我正在尝试编写一个 VSCode 扩展,用户可以使用谷歌帐户登录到谷歌 AppEngine,我需要获取他们的SACSIDcookie 来发出 appengine 请求。

所以我在打开一个浏览器窗口

https://accounts.google.com/ServiceLogin?service=ah&passive=true&continue=https://appengine.google.com/_ah/conflogin%3Fcontinue%3Dhttp://localhost:3000/

(由 生成google.appengine.api.users.create_login_url

用户登录并被重定向到我的本地网络服务器

localhost:3000/_ah/conflogin/?state={state}

现在我尝试将请求转发到我的 AppEngine 应用程序(因为它知道如何解码 state 参数),所以我请求

https://my-app.appspot.com/_ah/conflogin/?state= {state}

基本上只是用实际的应用程序替换 localhost 。

但它不起作用,大概是因为域不同。我认为这是出于安全考虑。

有什么办法可以使这项工作?

标签: google-app-enginegoogle-authentication

解决方案


不理想,但我发现的唯一解决方案是在我的 GAE 实例上设置一个端点来执行重定向。然后我可以将其设置为继续 url,当我开始身份验证过程时

https://accounts.google.com/ServiceLogin?service=ah&passive=true&continue=https://appengine.google.com/_ah/conflogin%3Fcontinue%3D https://my-app.appspot.com/redirect?to =http://localhost:3000


推荐阅读