> For the complete documentation index, see [llms.txt](https://docs.coda.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.coda.co/https-coda-payments.gitbook.io-zhong-wen-coda-private-technical-documentation/codapay/hou-duan-api-ji-cheng/direct-card-api-ji-cheng/ru-men-zhi-nan/ru-he-sheng-cheng-jwt-ling-pai.md).

# 如何生成 JWT 令牌

*有关 JWT 令牌的更多详细信息，请点击*[*此处*](https://jwt.io/)*查看。*

JWT（或 JSON Web Token）是一种可以从有效负载生成的令牌，它提供了一种在各方之间安全传输信息的简便方法。

您可以使用 jwt 库（<https://jwt.io/libraries> ）生成一个. 然后，传递一个包含数据编码信息的标头值，以及一个包含您的数据的有效负载。

令牌头部应包含以下信息：

* alg：这是要使用的签名算法。对于您向 Coda 发送的请求，请始终使用**HS256。**
* 类型：这是您要生成的令牌类型。对于您向 Coda 发出的请求，请始终使用“ **JWT** ”。

令牌有效载荷应包含以下信息：

* partner\_id：这是 Coda 提供给您的合作伙伴 ID。
* iat：令牌创建时间（UTC 时区）

请注意，生成的令牌有效期**为 5 分钟**。

*注意：这是用于生成授权的令牌标头，而不是您发送给 Coda 的请求标头。请勿在发送给 Coda 的请求标头中暴露 partnerId。*

#### 例子 <a href="#example" id="example"></a>

**标题：算法和秘密**

```
{
   "alg":"HS256",
   "typ":"JWT",
}
```

**JWT 令牌：有效载荷：数据**

```
{
  "partner_id": "1234567890",
  "iat": 1512203223
}
```

该有效载荷还用于生成 JWT 令牌。

要生成 JWT，您可以先对令牌头和有效负载进行编码，然后从客户端密钥生成签名并将它们组装起来：

```
key = '*yourclientsecret*'

unsignedToken = *encodeBase64Url(header) + '.' + encodeBase64Url(payload)*

signature = *HMAC-SHA256(key, unsignedToken)*

JWT = *unsignedToken + ‘.’ + signature*
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.coda.co/https-coda-payments.gitbook.io-zhong-wen-coda-private-technical-documentation/codapay/hou-duan-api-ji-cheng/direct-card-api-ji-cheng/ru-men-zhi-nan/ru-he-sheng-cheng-jwt-ling-pai.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
