我可以使用 passport-google 回调来验证 android/ios 用户吗?
Can I use the passport-google callback to authenticate android/ios users?
我有一个 node.js 服务器,它使用 google-passport-oauth2 进行身份验证。我的 server-side 代码看起来像来自 the documentation 的代码:
app.get('/auth/google',
passport.authenticate('google', { scope:
[ 'https://www.googleapis.com/auth/plus.login',
, 'https://www.googleapis.com/auth/plus.profile.emails.read' ] }
));
app.get( '/auth/google/callback',
passport.authenticate( 'google', {
successRedirect: '/auth/google/success',
failureRedirect: '/auth/google/failure'
}));
我认为 /auth/google
重定向到 google 的登录,当收到权限时,google 配置文件和令牌被发送到回调 /auth/google/callback
。
现在我正在制作一个 android 应用程序,它想要使用此 API 进行身份验证。我正在使用 directions for integrating Google Sign-In to do the authentication on google's end. Now my android app has the profile and token and wants to verify it with my server。
我试过用 passport-google-token
and passport-google-id-token
来做这件事(不确定有什么区别...),但不知何故没有奏效。现在我正在寻找其他可能性,比如 Google 客户端 API 库 node.js,但它看起来很笨重。然后是 tokeninfo 端点,它涉及额外的请求和更多的延迟。或者我应该看看 express-jwt
?
突然间,我想知道...我不能将令牌从我的 android 应用程序传递到位于 auth/google/callback
的服务器吗?这会让事情变得简单一些。我认为这一定是白日梦,因为我还没有找到任何关于这样做的信息。但是如果可能的话,我应该如何格式化请求中的 token/profile 数据以便 passport.authenticate()
方法识别它? (JSON, 表单数据, headers)
如果无法做到这一点,我正在采纳有关 well-documented 节点令牌验证库的建议...
我仍然不知道如何重用 google-passport-oauth2
路由,但我确实弄清楚了如何使用 passport-google-id-token 来验证 Google 的 idToken。
The post request to this route should include a JSON object with the
key id_token set to the one the client received from Google (e.g.
after successful Google+ sign-in).
但它仅在作为查询字符串发送时有效(GET 或 POST 有效)。
https://localhost:8888/auth/googletoken?id_token=xxxxxxxxxx
我有 a feeling 这不是最安全的方法,但我必须稍后处理。
编辑:事实证明,没有客户端 ID(在您的应用程序中),令牌是无用的,因此可以通过查询字符串发送它。
编辑 2:google-id-token
开发者之一 has reminded me 认为 JSON 只有在安装了 body-parser
后才会收到。
我有一个 node.js 服务器,它使用 google-passport-oauth2 进行身份验证。我的 server-side 代码看起来像来自 the documentation 的代码:
app.get('/auth/google',
passport.authenticate('google', { scope:
[ 'https://www.googleapis.com/auth/plus.login',
, 'https://www.googleapis.com/auth/plus.profile.emails.read' ] }
));
app.get( '/auth/google/callback',
passport.authenticate( 'google', {
successRedirect: '/auth/google/success',
failureRedirect: '/auth/google/failure'
}));
我认为 /auth/google
重定向到 google 的登录,当收到权限时,google 配置文件和令牌被发送到回调 /auth/google/callback
。
现在我正在制作一个 android 应用程序,它想要使用此 API 进行身份验证。我正在使用 directions for integrating Google Sign-In to do the authentication on google's end. Now my android app has the profile and token and wants to verify it with my server。
我试过用 passport-google-token
and passport-google-id-token
来做这件事(不确定有什么区别...),但不知何故没有奏效。现在我正在寻找其他可能性,比如 Google 客户端 API 库 node.js,但它看起来很笨重。然后是 tokeninfo 端点,它涉及额外的请求和更多的延迟。或者我应该看看 express-jwt
?
突然间,我想知道...我不能将令牌从我的 android 应用程序传递到位于 auth/google/callback
的服务器吗?这会让事情变得简单一些。我认为这一定是白日梦,因为我还没有找到任何关于这样做的信息。但是如果可能的话,我应该如何格式化请求中的 token/profile 数据以便 passport.authenticate()
方法识别它? (JSON, 表单数据, headers)
如果无法做到这一点,我正在采纳有关 well-documented 节点令牌验证库的建议...
我仍然不知道如何重用 google-passport-oauth2
路由,但我确实弄清楚了如何使用 passport-google-id-token 来验证 Google 的 idToken。
The post request to this route should include a JSON object with the key id_token set to the one the client received from Google (e.g. after successful Google+ sign-in).
但它仅在作为查询字符串发送时有效(GET 或 POST 有效)。
https://localhost:8888/auth/googletoken?id_token=xxxxxxxxxx
我有 a feeling 这不是最安全的方法,但我必须稍后处理。
编辑:事实证明,没有客户端 ID(在您的应用程序中),令牌是无用的,因此可以通过查询字符串发送它。
编辑 2:google-id-token
开发者之一 has reminded me 认为 JSON 只有在安装了 body-parser
后才会收到。