社会认证——在 FE 或 BE 方面更好?

Social authentication - better to do on FE or BE side?

如果我们要做社交认证(比如Facebook或者Google),那么哪一方最好整合它。后端侧还是前端侧?对于后端,我们有 NodeJS,其中我们可以使用 PassportJS 来完成,对于前端,我们有 Angular2 .0 也有插件可以做到这一点。我有点困惑这段代码应该放在哪一边。如果有人对此有任何看法,请告诉我。

我猜您正在尝试实施 Oauth2,实际上这取决于您的应用程序要求。

例如,如果您将使用 Authorization Code Flow 遵循 Oauth2 授权,您需要在客户端和服务器端实施授权。

但是,如果您要使用 Implicit Flow 遵循 Oauth2 授权,您需要仅在客户端实施授权。

我的建议是阅读这篇文章以了解有关 Oauth2 流程的详细信息Oauth2 Flows Explained

Implicit grant (section 4.2)

The implicit grant is similar to the authorization code grant with two distinct differences.

It is intended to be used for user-agent-based clients (e.g. single page web apps) that can’t keep a client secret because all of the application code and storage is easily accessible.

Secondly instead of the authorization server returning an authorization code which is exchanged for an access token, the authorization server returns an access token.