# 与SSO和 '~' 字符有关的问题

**URL:** <https://meta.discourse.org/t/issues-with-sso-and-character/351582>\
**Category:** Support\
**Created:** [2025年二月11日 03:28 UTC](https://meta.discourse.org/t/issues-with-sso-and-character/351582 "2025-02-11T03:28:44Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![sweetbeems](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@sweetbeems](https://meta.discourse.org/u/sweetbeems)\
**Post date:** [2025年二月20日 07:13 UTC](https://meta.discourse.org/t/issues-with-sso-and-character/351582/9 "2025-02-20T07:13:38Z")

</div>

经过进一步调查，我确实对其进行了错误的编码。

以下是我最终得到的代码，供以后参考：

```plaintext
return_payload = base64.b64encode(parse.urlencode(kwargs).encode("utf-8"))
h = hmac.new(secret.encode("utf-8"), return_payload, digestmod=hashlib.sha256)
resp = requests.post(
       ".../admin/users/sync_sso",
        data={"sso": return_payload, "sig": h.hexdigest()}
        headers={...}
)

```

如果您正在进行重定向，请确保对 `{"sso"...}` 进行 `parse.urlencode` 编码。

感谢 @sam 和 @david 的帮助！

---

_[View the full topic](https://meta.discourse.org/t/issues-with-sso-and-character/351582)._
