Facebook OAuth2 中 access_token 的长度是多少?

发布于 2024-10-07 00:26:09 字数 142 浏览 0 评论 0 原文

我在 Google 和 StackOverflow 上搜索以找到问题的答案,但找不到。

我想将 access_token 存储到我的数据库中以供离线访问,并且我想确保指定列的正确长度。

我什至无法确定它只是一个数字还是数字和字符串的混合。

I searched on Google and StackOverflow to find a answer to my question but I can't find one.

I'd like to store the access_token to my database for offline access and I'd like to be sure to specify the correct length of my column.

I can't even find if it's just a number or a mix between number and strings.

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

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

发布评论

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

评论(7

心舞飞扬 2024-10-14 00:26:09

我在 Facebook 工作,对此我可以给出明确的答案。

请不要为访问令牌的存储设置最大大小。我们预计,当我们添加和删除数据并更改它们的编码方式时,它们会随着时间的推移而增长和缩小。

我们确实在一处给出了关于 255 个字符的指导。我已经更新了包含该信息的博客文章,并更新了我们的新访问令牌文档以包含有关大小的注释:

https://developers.facebook.com/docs/facebook-login/access-tokens/

抱歉造成混乱。

I work at Facebook and I can give a definitive answer about this.

Please don't put a maximum size on the storage for an access token. We expect that they will both grow and shrink over time as we add and remove data and change how they are encoded.

We did give guidance in one place about it being 255 characters. I've updated the blog post that had that information and updated our new access token docs to include a note about sizes:

https://developers.facebook.com/docs/facebook-login/access-tokens/

Sorry for the confusion.

听风念你 2024-10-14 00:26:09

随着 Facebook 最近转向加密访问令牌,访问令牌的长度最多可达 255 个字符。如果您将访问令牌存储在数据库中,则该列应该至少能够容纳 varchar(255)。以下是 2011 年 10 月 4 日 Facebook 开发者博客的摘录:

“启用加密访问令牌迁移后,访问令牌的格式已更改。新的访问令牌格式是完全不透明的,您不应依赖于代码中的格式。 varchar(255) 字段足以存储新令牌。”

完整博客文章:https://developers.facebook.com/blog/post/572

With Facebook's recent move to encrypted access tokens, the length of the access token can be up to 255 characters. If you're storing the access token in your database, the column should be able to accommodate at least varchar(255). Here's an excerpt from Facebook's Developer blog from October 4, 2011:

"With the Encrypted Access Token migration enabled, the format of the access token has changed. The new access token format is completely opaque and you should not take any dependency on the format in your code. A varchar(255) field will be sufficient to store the new tokens."

Full blog post here: https://developers.facebook.com/blog/post/572

习惯那些不曾习惯的习惯 2024-10-14 00:26:09

这个答案不再正确,我在 FB 的文档中找不到正确的值。我们收到的访问令牌长度超过 255 个字符。我们正在从 VARCHAR 转向 SMALLTEXT,以尝试面向未来的事情。

This answer is no longer correct, and I can't find a corrected value in FB's docs. We have been receiving access tokens that are longer than 255 characters. We're moving from VARCHAR to a SMALLTEXT instead to try to future-proof things.

倥絔 2024-10-14 00:26:09

来自OAuth 2.0 授权协议 的第 1.4 节 (草案-ietf-oauth-v2-22

访问令牌可以有不同的格式、结构和方法
基于的利用率(例如加密属性)
资源服务器安全要求。访问令牌属性和
用于访问受保护资源的方法超出了范围
本规范的一部分,并由配套规范定义。

我查找了“配套规范”,但没有找到任何相关内容,并在第 11.2.2 节中指出

o 参数名称:access_token
o 参数使用位置:授权响应、token响应
o 变更控制者:IETF
o 规范文件:[[ 本文件 ]]

这似乎表明 access_token 参数是在本规范中定义的。我猜参数是,但实际的访问令牌尚未完全充实。

更新:
本规范撰写的最新版本 (draft-ietf- oauth-v2-31)包含一个附录,更好地定义了 access_token 参数的预期内容

A.12。 “access_token”语法

“access_token”元素在第 4.2.2 节中定义,并且
第 5.1 节:

  访问令牌 = 1*VSCHAR

因此,本质上这意味着 access_token 的长度应至少为 1 个字符,但本规范中定义的长度没有限制。

注意他们定义 VSCHAR = %x20-7E

From section 1.4 of The OAuth 2.0 Authorization Protocol (draft-ietf-oauth-v2-22)

Access tokens can have different formats, structures, and methods
of utilization (e.g. cryptographic properties) based on the
resource server security requirements. Access token attributes and
the methods used to access protected resources are beyond the scope
of this specification and are defined by companion specifications.

I looked for the "companion specifications" but didn't find anything relevant and in section 11.2.2 it states

o Parameter name: access_token
o Parameter usage location: authorization response, token response
o Change controller: IETF
o Specification document(s): [[ this document ]]

Which seems to indicate that the access_token parameter is defined within this spec. Which I guess the parameter is but the actual access token isn't fully fleshed out.

Update:
The latest version of this writing of the specification (draft-ietf-oauth-v2-31) includes an appendix that defines better what to expect from the access_token parameter

A.12. "access_token" Syntax

The "access_token" element is defined in Section 4.2.2 and
Section 5.1:

  access-token = 1*VSCHAR

So essentially what this means is that the access_token should be at least 1 character long but there is no limit on how long defined in this specification.

Note they define VSCHAR = %x20-7E

寂寞清仓 2024-10-14 00:26:09

Facebook 访问令牌的长度可以超过 255 个字符。我遇到了很多错误,例如 ActiveRecord::StatementInvalid: PG::StringDataRightTruncation: ERROR: value too long for typecharacter Varying(255) 其中值是 facebook 访问令牌。不要使用string类型列,因为它的长度是有限的。您可以使用 text 类型列来存储标记。

Facebook access token can be longer than 255 characters. I had a lot of errors like ActiveRecord::StatementInvalid: PG::StringDataRightTruncation: ERROR: value too long for type character varying(255) where the value was facebook access token. Do not use string type column because its length is limited. You can use text type column to store tokens.

何以心动 2024-10-14 00:26:09

最近,我们的应用程序发现它们的长度超过 100 个字符。我仍在寻找文档,以便我可以为它们找出“安全”字段大小。

Recently, our app has been seeing them longer than 100 characters. I'm still looking for documentation so I can figure out a 'safe' field size for them.

情栀口红 2024-10-14 00:26:09

我将根据花费的时间更新答案。

从 OAuth2 文档中,

本规范未定义访问令牌字符串大小。客户应避免对价值大小做出假设。授权服务器应记录其发出的任何值的大小。

本文档第 4.2.2 节)

注意: Facebook 正在使用 OAuth2,如此页面所述。

所以现在,Facebook 的开发人员门户上似乎没有关于 OAuth 令牌长度的信息。 Yahoo 似乎使用 400 位长的令牌,因此最好假设 MySQL 中的 TEXT 列比 varchar 更安全。

I'll update the answer from the time spend.

From the OAuth2 documentation,

The access token string size is left undefined by this specification. The client should avoid making assumptions about value sizes. The authorization server should document the size of any value it issues.

(Section 4.2.2 of this document)

Note: Facebook is using OAuth2, as mentionned on this page.

So now, no informations seems to be available on the developers portail of Facebook about the length of the OAuth token. Yahoo seems to use a 400 bit long token, so it's best to assume that a TEXT column in MySQL is safer than a varchar.

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