# 单点登录

单一登录（SSO）是一种认证方法，使用户可以通过使用一组凭据在多个应用程序和网站上进行安全认证。

## 它是如何工作的？

您让用户创建他们的SSID以及从这些SSID生成身份令牌。要登录到您的服务，他们只需输入身份令牌的ID。

在后台，您检查身份令牌（这些是NFT）是否真的属于用户，如果是的话，从身份令牌中获取SSID。

要从身份令牌获取SSID，您需要查询SSI合约的**metadata**函数，并传递身份令牌ID

```solidity
// 示例代码
ISSI(ssiContract).metadata(identity_token_id)
```

这将返回一个具有以下格式的元数据对象

```solidity
struct SSIData {
    uint senderProfileId;
    uint receiverProfileId;
    uint auditorProfileId;
    uint deadline;
    string question;
    string answer;
    ProofType proofType;
}
```

要获取实际的SSID，您需要在验证问题是否真的是SSID之后，获取答案变量

```solidity
// 完整代码
function getSSID(uint _identity_token_id) external returns(string memory) {
    SSIData memory data = ISSI(ssiContract).metadata(identity_token_id)
    require(keccak256(abi.encodePacked(data.question)) == keccak256(abi.encodePacked("ssid")))
    return data.answer
}
```

您将使用从用户身份令牌中收集的SSID数据作为其标识符，并在执行该快速检查后登录他们。


---

# Agent Instructions: 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:

```
GET https://docs.payswap.org/zhong-guo-ren/use-cases/ssi/single-sign-on.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
