3

我阅读了 Youtube 开发者网站上的文档,它没有谈论任何有效性。
OAuth 2.0 标准是否定义了任何有效期,或者授权令牌在用户手动撤销之前是否有效?OAuth 规范
定义令牌应 在授予后不久过期,那么它会在我获得访问和刷新令牌后过期吗?我可以将此访问令牌用于所有未来的 API 请求还是需要定期获取新令牌?

4

2 回答 2

1

我假设您在谈论授权代码,您在这里混合了一些术语。

来自OAuth 2.0 草案

授权代码必须在发布后不久过期,以降低泄漏风险。建议的最大授权代码生命周期为 10 分钟。客户端不得多次使用授权码。如果一个授权码被多次使用,授权服务器必须拒绝该请求并且应该(如果可能的话)撤销之前基于该授权码发布的所有令牌。

使用一次获取访问令牌后,不能再次使用。您也不需要定期检索授权码。仅当您没有用户的访问令牌但想要请求他的数据时,您才这样做。

您的访问令牌有时会过期。您可以通过查看expires_in随它发送的值,或者通过向 API 发出请求并返回访问令牌过期错误来了解何时。然后,您可以使用刷新令牌获取新的访问令牌,而无需用户参与。

于 2012-09-12T09:31:00.240 回答
1

Very useful step-by-step guide about how to get access and fresh tokens and save them for future use using YouTube OAuth API v3. PHP server-side YouTube V3 OAuth API video upload guide. The good thing is, you do not need to worry about the expiry of the tokens, as the script in this guide checks, saves, and updates the token in a txt file for future access.

{"access_token":"XXXXXXXXX","token_type":"Bearer", "expires_in":3600, "refresh_token":"XXXXXXX", "created":000000}

We use at http://presentationtube.com and it works fine with thousands of users.

于 2015-04-09T19:10:32.790 回答