受限使用的访问令牌
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
使用受限的访问令牌可防范请求仿冒和重放攻击,确保操作是由收到消息的用户执行的操作。可通过向请求参数添加唯一的令牌参数并在调用操作时验证该参数来实现。
token 参数应作为只能用于特定操作和特定用户的键生成。在执行请求的操作之前,您应检查令牌是否有效,且与您为用户生成的令牌是否一致。如果令牌匹配,则可以执行操作,然后令牌会在日后发出的请求中失效。
访问令牌应作为 HttpActionHandler 的 url
属性的一部分发送给用户。例如,如果您的应用在 http://www.example.com/approve?requestId=123
处理审批请求,则应考虑为其添加额外的 accessToken
参数,并监听发送到 http://www.example.com/approve?requestId=123&accessToken=xyz
的请求。
您必须提前生成组合 requestId=123
和 accessToken=xyz
,以确保无法根据 requestId
推断出 accessToken
。任何包含 requestId=123
但不含 accessToken
或 accessToken
不等于 xyz
的审批请求都应该被拒绝。此请求通过后,日后任何具有相同 ID 和访问令牌的请求也应被拒绝。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-25。
[null,null,["最后更新时间 (UTC):2025-07-25。"],[],[],null,["# Limited Use Access Tokens\n\nLimited-Use Access Tokens provide protection from request spoofing and [replay attacks](http://en.wikipedia.org/wiki/Replay_attack), ensuring that the action is performed by the user the message was sent to. Protection is achieved by adding a unique token parameter to the request parameters and verifying it when the action is invoked.\n\nThe token parameter should be generated as a key that can only be used for a specific action and a specific user. Before the requested action is performed, you should check that the token is valid and matches the one you generated for the user. If the token matches then the action can be performed and the token becomes invalid for future requests.\n\nAccess tokens should be sent to the user as part of the `url` property of the [HttpActionHandler](/workspace/gmail/markup/reference/types/HttpActionHandler). For instance, if your application handles approval requests at `http://www.example.com/approve?requestId=123`, you should consider including an additional `accessToken` parameter to it and listen to requests sent to `http://www.example.com/approve?requestId=123&accessToken=xyz`.\n\nThe combination `requestId=123` and `accessToken=xyz` is the one that you have to generate in advance, making sure that the `accessToken` cannot be deduced from the `requestId`. Any approval request with `requestId=123` and no `accessToken` or with a `accessToken` not equal to `xyz` should be rejected. Once this request gets through, any future request with the same id and access token should be rejected too."]]