0

我第一次尝试独立的基础设施。通过独立的基础设施,我的意思是我有 2 个独立的应用程序:

  1. 仅用作 API 服务的 Rails 应用程序
  2. 处理所有前端内容的 Angular 应用程序

目前这是一个非常简单的过程(因为我正在了解更多关于集成 2 个应用程序的信息)。我知道平台之间的通信应该通过某种基于令牌的身份验证等来保护。我查看了devise_token_authng-token-auth

我很困惑,因为我目前不会向任何外部方开放我的 API。因此,我希望能够使用我的 API 的唯一系统是我自己的(一组密钥)。

我是否正确地说我将使用 devise_token_auth 生成我的密钥,然后将其添加到服务器和客户端的环境变量中?由于这些值当前是静态的(不是用户特定的)

4

2 回答 2

1

您可以使用基于令牌的身份验证系统来保护您的后端免受不需要的请求,在每次身份验证(使用登录名/密码)之后,您的后端将生成一个令牌并将其发送到您的客户端应用程序,该应用程序将在本地存储它(本地存储)。使用角度拦截器,您可以轻松拦截所有客户端请求并将令牌注入每个请求的标头中,最后您的背部必须检查每个请求中令牌的存在和有效性。

https://github.com/lynndylanhurley/devise_token_auth似乎是您在服务器端的问题的响应,再加上(如果您不想自己实现)https://github.com/lynndylanhurley/ng- token-authhttps://github.com/sahat/satellizer(我更喜欢这个),你可以构建一个非常稳固的系统。

于 2015-09-07T14:04:19.383 回答
1

Definition of authentication is something like "confirming that a user is who he says he is". Since you won't have any users, auth is not applicable here.

One might argue that "user" in your case is the angular client and therefore, external users (other apps/scripts), not knowing the token, will be rejected. However, access token being public knowledge too, it does not add any protection against spam or whatever you were trying to achieve with this mechanism.

So, don't bother with it.

于 2015-09-07T14:23:42.947 回答