Facebook OAuth AccessToken 过期

发布于 2024-12-13 17:24:01 字数 241 浏览 0 评论 0原文

我需要有关 Facebook OAuth 的帮助。我正在尝试为我的网页制作一个 Facebook 新闻提要小工具。我所做的是,我创建了一个 Facebook 登录页面,获取了验证码,然后获取了访问令牌。访问令牌中有一个到期参数。

我的问题是,令牌过期后会发生什么?是否成为新的token人再次登录。我想将其存储在数据库中,以便我可以在浏览网页时随时访问它。

如果我使用访问令牌,它还会过期吗?或者如果在给定的有效期内未使用它是否会过期?

I need help with Facebook OAuth. I am trying to make a facebook news feed gadget for my webpage. What I did is, I created a facebook login page, got the verification code, and then got the access token. There is an expiry parameter in the access token.

My question is, what happens when the token gets expired? Does it become a new token person logs in again. I want to store it in a database, so I can access it anytime I navigate through the webpage.

If I use the access token, will it still get expired? Or does it expire if its not been used for the given expiration time?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

咿呀咿呀哟 2024-12-20 17:24:01

您最初问题的答案是,访问令牌仅在用户登录时有效。因此,是的,每次登录您的站点时都需要检索新的 access_token。 身份验证流程文档对此进行了详细说明。

为了获得没有过期(或有效期较长)的访问令牌,您需要让用户授权 offline_access。这应该在您的范围内设置。

以下是本文档offline_access 权限的描述>:

离线访问 - 使您的应用能够随时代表用户执行授权请求。默认情况下,大多数访问令牌会在短时间内过期,以确保应用程序仅在用户主动使用应用程序时才代表用户发出请求。此权限使我们的 OAuth 端点返回的访问令牌长期有效。

然而,这不会让您永远访问。如果用户更改密码或取消对您的应用程序的授权,您将需要让用户重新授权以获得新的 access_token。如果您尝试使用过期的访问令牌,将返回错误消息。这就是为什么拥有一个能够应对此类不测事件的流程非常重要。

The answer to your initial question, is that an access token is only valid whilst the user is logged in. So yes, a new access_token will need to be retrieved every time they log in to your site. This is detailed in the authentication flow documentation.

In order to get an access token which is does not have an expiry (or has a long validity period), you will need to get the user to authorise the offline_access. This should be set in your scope.

Here's a description of the offline_access permission from this documentation:

offline access - Enables your app to perform authorized requests on behalf of the user at any time. By default, most access tokens expire after a short time period to ensure applications only make requests on behalf of the user when the are actively using the application. This permission makes the access token returned by our OAuth endpoint long-lived.

This will not however, give you access forever. If the user changes their password, or deauthorises your application, you will need to get the user to reauthorise it to get a new access_token. If you try to use an out of date access token, an error message will be returned. That's why it's important to have a flow which will allow for such eventualities.

世界如花海般美丽 2024-12-20 17:24:01

据我所知,您可以通过在用户执行 fconnect 时请求随时访问我的信息权限(offline_access)来实现此目的。

From my knowledge you can achieve this by asking for access my information anytime permission (offline_access) while a user does fconnect.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文