对网站中 Facebook 整合的担忧。访问令牌

Concerns about Facebook integration in website. access-token

首先我用的是快递和护照。我想知道我是否采用这种方法,为什么我不需要包括在开发者网站上阅读的 javascript "SDK"。我有点困惑为什么 passport 不讨论 SDK。我猜是因为 SDK 用于客户端,还有另一种方法可以用 Oauth 做同样的事情,这就是 passport-facebook 使用的方法。我想了解更多详情。

还有关于访问令牌。

在护照中我做了这样的事情:

function(accessToken, refreshToken, profile, done){

...

newUser.facebook.token = accessToken;

This gets an "acccesToken" like this = EAAYrf9ixTA0BAPkSlXymZA3y2QwkDIlAB84XXCjQH2qxEgZAaP8kdZBqWZApZAd5ZCqyD4te6YkZAYTpMPGujYq88fRZC2HcrcgfzLBiFyIMXrRUpssNxW470SJ7muNkiZCKEDoejiSZBgvtJkQen8rnr2nctEvfzfUm

我想知道这是否对每个用户都不同?

It 说有 4 种不同的类型 "access-tokens" 上面的是哪一种?你怎么知道的?

此外,我以为我在 SDK 指南中读到它会在 cookie 中设置 accessToken,但我没有看到它 这就是我做 console.log(req.session)

时得到的结果
  cookie:
   { path: '/',
     _expires: null,
     originalMaxAge: null,
     httpOnly: true },
  passport: { user: '5760703f8fd744e020920980' } }
  1. 为什么我不需要带有 PassportJS 的 Facebook Javascript SDK?

Facebook 的客户端 SDK 允许您直接从 Facebook 获取身份验证 (FB.api('/me')) 和会话数据 (FB.getLoginState) 并将其设置在客户端的 cookie 中。使用 Passport 时,当您在路由和会话数据中自动调用 passport.authenticate 时,passport.js 会处理身份验证调用,但所有这些都来自服务器端,并且您的代码更少。

此外,Facebook 只会为网络登录提供短期访问令牌,但会为服务器请求提供长期访问令牌。

  1. 每个用户的访问令牌是否不同?

它是独一无二的吗?是的。我没有看到它明确说明,但 Facebook 说:

One important aspect to understand about access token is that they are portable. Once you have an access token you can use it to make calls from a mobile client, a web browser, or from your server to Facebook's servers. If a token is obtained on a client, you can ship that token down to your server and use it in server-to-server calls. If a token is obtained via a server call, you can also ship that token up to a client and then make the calls from the client.

我认为您可能真正要问的是 它是否持久,以及 the answer is no。它们将过期并重新生成。

Short-lived tokens usually have a lifetime of about an hour or two, while long-lived tokens usually have a lifetime of about 60 days. You should not depend on these lifetimes remaining the same - the lifetime may change without warning or expire early.

  1. 它是哪种类型的访问令牌,您是怎么知道的?

这是一个User Access Token。 Passport 处理用户登录和用户身份验证以及 returns 用户个人资料信息,而不是与其他 3 种令牌类型相关的任何信息。

The user token is the most commonly used type of token. This kind of access token is needed any time the app calls an API to read, modify or write a specific person's Facebook data on their behalf. User access tokens are generally obtained via a login dialog and require a person to permit your app to obtain one.

  1. SDK 说 accessToken 是在 cookie 中设置的。

Passport并没有在session中显式存储accessToken,它一般会存储一个用户唯一的标识符,比如user._id,当passport.session()调用passport.serializeUser时,这样调用 passport.deserializeUser 时可以找到用户对象。您可以在“What does passport.session() middleware do?”中阅读更多内容。