api.auth

revokeSession()

api.auth.revokeSession(id) → Promise<{ ok: true }>

账户的会话结束 由ID 。 一台停止签名的机器 签名。

DELETE /api/auth/sessions/:idfreesame account only
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

参数

idstring必填

代号: ID,你的来自 api.session().

返回值

{ ok: true }
{"ok": True}

错误

代码状态触发条件
session_not_found404此账户的任何活动会议都无法包含此代号 。

属于另一个账户的届会也回答同样的问题 404搜索范围被覆盖到打电话者,因此一个账户无法发现或结束另一个会话,拒绝则没有说明该身份是否存在于别处。

两次取消两次

第二个呼呼回答 404,而不是 { ok: true }:只有活动会话匹配。当您想要的只是会话消失时, 404 成功就是成功。

import { IaGenifyError } from "iagenify";

async function ensureRevoked(api, id) {
  try {
    await api.auth.revokeSession(id);
    return "revoked";
  } catch (err) {
    if (err instanceof IaGenifyError && err.status === 404) return "already gone";
    throw err;
  }
}
from iagenify import IaGenifyError

def ensure_revoked(api, session_id):
    try:
        api.auth.revoke_session(session_id)
        return "revoked"
    except IaGenifyError as error:
        if error.status == 404:
            return "already gone"
        raise

撤销自己的会话

没有什么能阻止你,通过身份 api.session() 给您, 客户端的会话结束。 效果是 logout()”从另一个方向——同样的事情也随之而来,即下一次呼叫交换关键和继续。

const mine = await api.session();
await api.auth.revokeSession(mine.id);   // same effect as api.auth.logout()
mine = api.session()
api.auth.revoke_session(mine["id"])   # same effect as api.auth.logout()

另一会话的ID来自

不是来自 SDK。此资源以 ID 结束一届会议;它不列举。实际上,它留下了两种诚实的模式。

  • 记录会议地点。 一个在启动时知道自己的代号的过程 可以在操作员的工具读取的地方发布
  • 换成是取消钥匙 当您无法命名会话时, 请指定密钥—— 机器也无法返回, 而这通常是实际目标 。
// At boot, each worker records who it is
const me = await api.session();
await registry.set(`worker:${process.env.HOSTNAME}`, me.id);

// Later, from your operator tool
const id = await registry.get(`worker:${host}`);
if (id) await api.auth.revokeSession(id);
import os

# At boot, each worker records who it is
me = api.session()
registry.set(f"worker:{os.environ['HOSTNAME']}", me["id"])

# Later, from your operator tool
session_id = registry.get(f"worker:{host}")
if session_id:
    api.auth.revoke_session(session_id)
取消会话时不撤销会话背后的密钥

一个仍然保持关键交换程序的进程在新的会话下再次保留并返回,当机器不应返回时,就撤销它持有的钥匙——并首先撤销钥匙。

命令,当你同时做

// Key first: it closes the door.
await api.keys.revoke(keyId);

// Session second: it removes whoever is already inside.
await api.auth.revokeSession(sessionId);
# Key first: it closes the door.
api.keys.revoke(key_id)

# Session second: it removes whoever is already inside.
api.auth.revoke_session(session_id)

逆向,有一个窗口, 仍然有效的键交换一个新的会话, 机器在你完成之前就回来了 。