# 会话

Canonical URL: https://developers.iagenify.com/zh/sdk/concepts/sessions/
Language: zh

键被交换一次换为 JWT 并给您一个更新的标志。之后,键将留在您放放的地方,客户将自己续开会。

Status: 交换一次 · refreshed automatically

## 优先优先排序 {#flow}

在每个电话之前 客户会挑最便宜的东西

| 状态状态状态状态状态状态状态状态 | 发生什么 |
| --- | --- |
| 缓存 JWT 尚未过期的 | 使用时的正数 - 没有网络 |
| 过期, 但缓存了刷新牌 | 更新,后使用 |
| 刷新失败, 否则没有缓存 | 键交换 |
| 没有密钥, 没有缓存会话 | 在此之前很久 建筑商拒绝 |

过期时间由象征本身读取, 而不是从时间计时器中猜到, 所以一天睡着的过程 和忙碌的过程一样。

## 缓存的 {#cached}

```javascript
{ jwt, refreshToken, sessionId, storageId }
```

`storageId` 机器如何在重新启动时保持相同身份:它被送回到下一个交换台,所以同一机器被识别,而不是登记两次。

```javascript
await api.session();
// { id, storageId } — or null when nothing has been exchanged yet
```

## 首次同时拨打 {#dedup}

冷酷客户同时点火十通 交换一次 不是十通 重复由钥匙和钥匙 `appName`并且它在同一过程中将客户案例放在同一过程中——这就是使双重伤害变得无害的原因。

```javascript
// One exchange, ten calls
await Promise.all([
  api.getUser(),
  api.catalogue(),
  api.storage.list(),
  api.keys.list(),
  /* … */
]);
```

## 结束会议 {#ending}

```javascript
await api.auth.logout();            // this session
await api.auth.revokeSession(id);   // another one, by id
```

> **退出与取消密钥不同**
>
> 会话结束; 键仍然有效, 下次调用时又交换它。 要完全停止键, 请取消键 。

```python
# Stored in ~/.iagenify/session (or your session_path / storage)
{"jwt": ..., "refresh_token": ..., "session_id": ..., "storage_id": ...}
```

```python
api.session()
# {"id", "storageId"} — or None when nothing has been exchanged yet
```

```python
# One exchange, ten calls: the first call exchanges the key, the others reuse it
from concurrent.futures import ThreadPoolExecutor

with ThreadPoolExecutor() as pool:
    user, prices, storages, keys = pool.map(lambda call: call(), [
        api.get_user,
        api.catalogue,
        api.storage.list,
        api.keys.list,
    ])
```

```python
api.auth.logout()                    # this session
api.auth.revoke_session(session_id)  # another one, by id
```
