网站授权工作流程
使用网站授权应用程序。
网站授权工作流程 (OAuth) 是从您自己的网站启动的。销售合作伙伴登录您的网站并选择 Authorize 您配置为启动授权的按钮。有关更多信息,请参阅以下步骤。
注意
The examples in the following steps are for a seller application that uses an OAuth authorization URI based on a Seller Central URL. For vendor applications, you can replace the Seller Central URL with a Vendor Central URL. For more information, refer to Construct an OAuth authorization URI.
Before you create a production website authorization workflow, test your authorization workflow while your application is in DRAFT
(version=beta
) status. For more information, refer to Step 2. After you've verified that your workflow functions correctly, you can convert it from draft to production.
第 1 步:设置 “授权” 按钮
Set up an Authorize button on your application website that the selling partner can select to initiate authorization for your application. When the selling partner selects the button, your website loads an OAuth authorization URI into the browser. Your website then redirects the selling partner to an Amazon sign-in page. After sign-in, your website redirects the selling partner to a consent page where they can approve your application to make calls to the Selling Partner API on their behalf. For more information, refer to Construct an OAuth authorization URI.
注意
如果您拥有多个地区的 OAuth 授权 URI,请务必设置您的 Authorize 相应的按钮。需要将销售合作伙伴重定向到其所在地区的卖家平台(适用于卖家)或供应商中心(适用于供应商)登录页面。
Authorize 按钮设置是一项一次性任务。
步骤 1. 销售伙伴从您的网站启动授权
-
卖家合作伙伴登录您的网站。如果卖家还没有账户,他们要完成注册流程。
-
The selling partner selects the Authorize button that you set up in Step 1.
-
您的应用程序将 OAuth 授权 URI 加载到浏览器中,并添加以下查询参数:
参数描述 redirect_uri
(Optional) A URI that redirects the browser to your application. This must be the OAuth redirect URI that you specified when you registered your application. If you don't include the redirect_uri
parameter, the default is the first OAuth redirect URI that you specified when you registered your application.state
您的应用程序生成的状态值。您的应用程序使用此值来维护此请求和响应之间的状态,从而帮助防范跨站点请求伪造攻击。
重要说明
由于 OAuth 信息是通过 URL 查询参数传递的,因此我们建议您:
- 确保状态令牌是短暂的,并且可以验证对您的用户来说是唯一的。
- Set the
Referrer-Policy: no-referrer
HTTP header, which prevents sensitive information leaking to websites that your website links to. For more information about cross-site request forgery and calculating a state parameter, refer to Cross-site Request Forgery.
如果你包括 version=beta
参数,工作流程会授权应用程序 DRAFT
状态。如果您不包含此参数,则工作流程会授权在销售合作伙伴应用商店上发布的应用程序。
例如:
https://sellercentral.amazon.com/apps/authorize/consent?application_id=appidexample&state=stateexample&version=beta
或者
https://sellercentral.amazon.com/apps/authorize/consent?application_id=appidexample&state=stateexample
销售伙伴进入卖家平台(针对卖家)或 Vendor Central(针对供应商)的登录页面。
第 3 步:销售合作伙伴同意申请授权
The selling partner signs in to Seller Central or Vendor Central, depending on the type of OAuth Authorization URI you constructed. For more information, refer to Construct an OAuth Authorization URI.
登录后,将显示同意页面。销售合作伙伴现在可以查看您的应用程序请求的数据访问权限。他们可以选择 Confirm 继续或 Cancel 未经授权退出。
第 4 步:亚马逊发送授权信息
亚马逊会简短地显示一个页面,表明我们授权您访问卖家合作伙伴的数据。同时,会执行以下操作:
-
亚马逊将您的 OAuth 重定向 URI 加载到浏览器中并添加以下查询参数:
注意
LWA 授权码将在五分钟后过期。请务必在 LWA 刷新令牌到期之前生成它。
请求示例:
https://client-example.com?state=state-example&selling_partner_id=sellingpartneridexample&spapi_oauth_code=spapioauthcodeexample -
您的应用程序可以验证状态值。
-
您的应用程序会保存
selling_partner_id
和spapi_oauth_code
价值观。 -
此时会显示网站的登录页面。
第 5 步:应用程序使用 LWA 授权码生成 LWA 刷新令牌
The Login with Amazon SDK for JavaScript can help you use an LWA authorization code to generate an LWA refresh token.
注意
LWA 授权码将在五分钟后过期。确保在 LWA 刷新令牌到期之前使用它来生成 LWA 刷新令牌。
使用 LWA 授权码生成 LWA 刷新令牌
-
Your application calls the Login with Amazon (LWA) authorization server (
https://api.amazon.com/auth/o2/token
) to use the LWA authorization code to generate an LWA refresh token. The call must include the following query parameters:参数描述 grant_type
请求的访问权限的类型。必须是 authorization_code
。code
The LWA authorization code that you received in Step 4. Amazon sends you the authorization information. redirect_uri
您的应用程序的重定向 URI。 client_id
Part of your LWA credentials. To get this value, refer to View your Application Information and Credentials. client_secret
Part of your LWA credentials. To get this value, refer to View your Application Information and Credentials. 请求示例:
POST /auth/o2/token HTTP/l.l Host: api.amazon.com Content-Type: application/x-www-form-urlencoded;charset=UTF-8 grant_type=authorization_code&code=SplxlOexamplebYS6WxSbIA&client_id=foodev&client_secret=Y76SDl2F -
LWA 授权服务器返回 LWA 刷新令牌。该响应包括以下元素。
参数描述 access_token
A token that authorizes your application to take certain actions on behalf of a selling partner. For more information, refer to Connecting to the Selling Partner API. token_type
返回的令牌类型。应该是 bearer。 expires_in
访问令牌失效之前的秒数。 refresh_token
A long-lived token that can be used to generate a new access token. For more information, refer to Connecting to the Selling Partner API. 响应示例:
{ "access_token":"Atza|IQEBLjAsAexampleHpi0U-Dme37rR6CuUpSR", "token_type":"bearer", "expires_in":3600, "refresh_token":"Atzr|IQEBLzAtAhexamplewVz2Nn6f2y-tpJX2DeX" } -
您的应用程序会保存
refresh_token
值。 -
浏览器会向销售伙伴显示一个页面,指示使用应用程序的后续步骤。
An LWA refresh token is a long-lived token that you use to generate an LWA access token. An access token obtained through this token generation must be included with calls to all SP-API operations except restricted operations and grantless operations, which use somewhat different authorization models. After an access token is issued it is valid for one hour. The same access token can be used for multiple API calls, until it expires.
To use a refresh token for an access token using a generated SDK, refer to Connecting to the Selling Partner API Using a Generated Java SDK. To manually use a refresh token to generate an access token, refer to Connecting to the Selling Partner API.
将测试授权工作流程转换为生产流程
从测试版转换为正式版有两种方法:
-
在销售合作伙伴应用商店中列出您的应用程序。这会自动将您的申请状态更改为
DRAFT
到PUBLISHED
。 -
將
version=beta
参数添加到 OAuth 授权 URI:
Updated 23 days ago