简体   繁体   English

OAuth2与Node.js

[英]Oauth2 with nodejs

I develop a web application with nodeJs. 我用nodeJs开发一个Web应用程序。 Most of the functions auth protected. 大多数功能均受auth保护。 I use Oauth2 (Google, Twitter) to authorize users to use the application. 我使用Oauth2(Google,Twitter)授权用户使用该应用程序。

I must create an Android application, what communicate with my backend over http after the user authenticated with Google account in the Android app. 我必须创建一个Android应用程序,在用户通过Android应用程序中的Google帐户进行身份验证后,该应用程序通过http与我的后端进行通信。

What is the best practice for that? 最佳做法是什么?

I think OAuth2 would be good for this job. 我认为OAuth2可以胜任这项工作。 But how? 但是如何?

您可能要考虑使用PassportJS (以防您将ExpressJS用作Web应用程序框架)。

you can't really use oauth in this case. 在这种情况下,您不能真正使用oauth。 as this How can I verify a Google authentication API access token? 这样, 如何验证Google身份验证API访问令牌? explains, you should not share authentications. 说明,您不应共享身份验证。

Instead, you should have your mobile app use a separate authentication for backend requests. 相反,您应该让您的移动应用对后端请求使用单独的身份验证。 You could have them login once, generate some secret token you can store in the phone so they don't need to login each time. 您可以让他们登录一次,生成一些可以存储在手机中的秘密令牌,这样他们就不必每次都登录。 That token is protected by the google login anyway. 该令牌仍然受到Google登录名的保护。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM