# 获取合作方令牌

> 用 client_id 与 secret 换取应用级的合作方令牌,后续用它为每位用户签发用户令牌。

POST
  `https://ikho.cn/developer/api/oauth/partner/access-token`
  [试一试](/docs/embedded/playground/)

  
## 鉴权

  

  
    `Authorization`
    string
    header
    必填
    
  

  HTTP Basic 认证,值为 `Basic base64(client_id:secret)`。`client_id` 与 `secret` 在开通时由对接工程师提供。

  

  

  
    `Content-Type`
    string
    header
    必填
    默认 `application/x-www-form-urlencoded`
  

  请求内容类型。

  

  
## 请求体

  本接口无请求体,凭证通过 `Authorization` 头传入。

  
## 响应

  

  
    `access_token`
    string
    
    
    
  

  合作方访问令牌。

  

  

  
    `refresh_token`
    string
    
    
    
  

  用于在令牌到期前换取新的合作方访问令牌。

  

  

  
    `token_type`
    string
    
    
    
  

  令牌类型,固定为 `bearer`。

  

  

  
    `expires_in`
    integer
    
    
    
  

  访问令牌有效期,单位为秒。

  

  

  cURLPython
  

  

  bash
    
  

  
```
curl -X POST "https://ikho.cn/developer/api/oauth/partner/access-token" \
  -u "$CLIENT_ID:$CLIENT_SECRET" \
  -H "Content-Type: application/x-www-form-urlencoded"
```

  ts
    
  

  
```
import base64, requests

client_id = "your_client_id"
client_secret = "your_client_secret"
basic = base64.b64encode(f"{client_id}:{client_secret}".encode()).decode()

resp = requests.post(
    "https://ikho.cn/developer/api/oauth/partner/access-token",
    headers={
        "Authorization": "Basic " + basic,
        "Content-Type": "application/x-www-form-urlencoded",
    },
)
print(resp.json()["access_token"])
```

  

  200 响应示例
    
  

  
```
{
  "access_token": "eyJhbGciOiJSUz...",
  "refresh_token": "eyJhbGci...",
  "token_type": "bearer",
  "expires_in": 7200
}
```
