[null,null,["最后更新时间 (UTC):2025-03-24。"],[],[],null,["# Authenticating requests in AMP for Email\n\nDynamic personalized email content often requires authenticating the user.\nHowever, to protect user data all HTTP requests made from inside AMP emails\nwithin Gmail are proxied and stripped of cookies.\n\nTo authenticate requests made from AMP emails, you may use\n[access tokens](#access_tokens).\n\nAccess tokens\n-------------\n\nYou can use access tokens to authenticate the user. Access tokens are\nsupplied and checked by the email sender. The sender uses the tokens to ensure\nthat only those with access to the AMP email can make the requests contained\nwithin that email. Access tokens must be cryptographically secure and time- and\nscope-limited. They are included within the URL of the request.\n\nThis example demonstrates using `\u003camp-list\u003e` to display authenticated data: \n\n \u003camp-list src=\"https://example.com/endpoint?token=REPLACE_WITH_YOUR_ACCESS_TOKEN\"\n height=\"300\"\u003e\n \u003ctemplate type=\"amp-mustache\"\u003e\n ...\n \u003c/template\u003e\n \u003c/amp-list\u003e\n\nSimilarly when using `\u003camp-form\u003e`, place your access token in the `action-xhr`\nURL. \n\n \u003cform action-xhr=\"https://example.com/endpoint?token=REPLACE_WITH_YOUR_ACCESS_TOKEN\" method=\"post\"\u003e\n \u003cinput type=\"text\" name=\"data\"\u003e\n \u003cinput type=\"submit\" value=\"Send\"\u003e\n \u003c/form\u003e\n\n| **Note:** Email clients typically strip the AMP mime part on reply / forward. \n|\n| Also, Gmail only considers an AMP part to be useable for 30 days after it is received so the lifetime of your access token should be set to 31 days.\n\n### Example\n\nThe following example considers a hypothetical note-taking service that lets\nlogged-in users to add notes to their account and view them later. The service\nwants to send an email to a user, `jane@example.com`, that includes a list of\nnotes they previously took. The list of the current user's notes is available\nat the endpoint `https://example.com/personal-notes` in JSON format.\n\nBefore sending the email, the service generates a cryptographically secure\nlimited-use access token for `jane@example.com: A3a4roX9x`. The access token is\nincluded in the field name `exampletoken` inside the URL query: \n\n \u003camp-list src=\"https://example.com/personal-notes?exampletoken=A3a4roX9x\" height=\"300\"\u003e\n \u003ctemplate type=\"amp-mustache\"\u003e\n \u003cp\u003e{{note}}\u003c/p\u003e\n \u003c/template\u003e\n \u003c/amp-list\u003e\n\nThe endpoint `https://example.com/personal-notes` is responsible for validating\nthe `exampletoken` parameter and finding the user associated with the token.\n\nFor more information, see\n[Limited use access tokens](/workspace/gmail/markup/actions/limited-use-access-tokens).\n| **Note:** A conventional web application could query the user notes endpoint with an XMLHttpRequest (XHR), and a cookie could provide the endpoint with the user's identity. In AMP for email, however, this approach doesn't work because all HTTP requests are anonymized in Gmail AMP emails. Instead, AMP must identify the user in the URL itself."]]