> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 续订 User Store ID 密钥

> 在 Microsoft Store 服务中的 User Store ID 密钥 30 天有效期到期前进行续订，让你的后端能继续对调用进行身份验证。

本文介绍如何续订 User Store ID 密钥。

当你[生成 User Store ID 密钥](/publishing/xstore-commerce/xstore-requesting-userstoreid#step-4-create-a-user-store-id-key)时，其有效期为 30 天。在该期间内，该密钥可用于对 Microsoft Store 服务的调用进行身份验证。你可以在过期前续订它，以为同一个 Microsoft Entra 应用程序客户端 ID 和用户身份生成新密钥。

## 先决条件

若要续订 User Store ID 密钥，你需要以下密钥/令牌：

* 具有受众 URI 值 `https://onestore.microsoft.com` 的 Microsoft Entra ID 访问令牌
* 已[在你的应用客户端代码中生成](/publishing/xstore-commerce/xstore-requesting-userstoreid#step-4-create-a-user-store-id-key)的已过期 Microsoft Store ID 密钥。

有关更多信息，请参阅[为服务到服务身份验证请求 User Store ID](/publishing/xstore-commerce/xstore-requesting-userstoreid)。

## 请求

### 请求语法

| 密钥类型          | 方法     | 请求 URI                                                     |
| ------------- | ------ | ---------------------------------------------------------- |
| `Collections` | `POST` | `https://collections.mp.microsoft.com/v6.0/b2b/keys/renew` |
| `Purchase`    | `POST` | `https://purchase.mp.microsoft.com/v6.0/b2b/keys/renew`    |

### 请求头

| 头                | 类型       | 说明                                                                  |
| ---------------- | -------- | ------------------------------------------------------------------- |
| `Host`           | `string` | 必须设置为 `collections.mp.microsoft.com` 或 `purchase.mp.microsoft.com`。 |
| `Content-Length` | `number` | 请求正文的长度。                                                            |
| `Content-Type`   | `string` | 指定请求和响应类型。目前唯一支持的值是 `application/json`。                             |

### 请求正文

| 参数              | 类型       | 说明                          | 是否必需 |
| --------------- | -------- | --------------------------- | ---- |
| `serviceTicket` | `string` | Microsoft Entra ID 服务访问令牌。  | 是    |
| `key`           | `string` | 已过期的 Microsoft Store ID 密钥。 | 是    |

### 请求示例

```syntax theme={null}
POST https://collections.mp.microsoft.com/v6.0/b2b/keys/renew HTTP/1.1
Content-Length: 2774
Content-Type: application/json
Host: collections.mp.microsoft.com

{
    "serviceTicket": "eyJ0eXAiOiJKV1QiLCJhb...",
    "Key": "eyJ0eXAiOiJKV1QiLCJhbG..."
}
```

## 响应

### 响应正文

| 参数    | 类型       | 说明                                                                              |
| ----- | -------- | ------------------------------------------------------------------------------- |
| `key` | `string` | 刷新后的 User Store ID 密钥，可用于后续对 Microsoft Store collections API 或 purchase API 的调用 |

### 响应示例

```syntax theme={null}
HTTP/1.1 200 OK
Content-Length: 1646
Content-Type: application/json
MS-CorrelationId: bfebe80c-ff89-4c4b-8897-67b45b916e47
MS-RequestId: 1b5fa630-d672-4971-b2c0-3713f4ea6c85
MS-CV: xu2HW6SrSkyHyFh.0.0
MS-ServerId: 030011428
Date: Tue, 13 Sep 2019 07:31:12 GMT

{
    "key":"eyJ0eXAi..."
}
```

## 错误代码

| Code | Error        | Inner error code             | 说明                                                                           |
| ---- | ------------ | ---------------------------- | ---------------------------------------------------------------------------- |
| 401  | Unauthorized | `AuthenticationTokenInvalid` | Microsoft Entra ID 访问令牌无效。在某些情况下，`ServiceError` 包含更多详情，例如令牌过期或缺少 `appid` 声明。 |
| 401  | Unauthorized | `InconsistentClientId`       | User Store ID 密钥中的 `clientId` 声明与 Microsoft Entra ID 访问令牌中的 `appid` 声明不匹配。   |

## 参考 API 文档

* [XStore（API 内容）](/reference/system/xstore/xstore_members)

## 另请参阅

[商务（概述）](/publishing/xstore-commerce/xstore-commerce-overview)

[从你的服务管理产品](/publishing/xstore-commerce/xstore-authenticating-service)

[为服务到服务身份验证请求 User Store ID](/publishing/xstore-commerce/xstore-requesting-userstoreid)

[使用 X-token 或 OAuth 2.0 从你的服务请求 User Store ID](/publishing/xstore-commerce/xstore-requesting-userstoreid-oauth)

[使用 Microsoft Store API 对你的服务进行身份验证](/publishing/xstore-commerce/xstore-authenticating-service)

[Microsoft.StoreServices 库 (GitHub)](https://github.com/microsoft/Microsoft-Store-Services)

[Microsoft.StoreServices 示例 (GitHub)](https://github.com/microsoft/Microsoft-Store-Services-Sample)

[XStore（API 参考）](/reference/system/xstore/xstore_members)
