HappyElements SSO client — Python library and CLI tool
Project description
he-sso
HappyElements SSO 客户端,提供 Python 函数 API 和命令行工具(CLI),用于在脚本或应用中获取当前用户的 SSO 认证信息。
安装
pip install he-sso
函数 API
from he_sso import get_user_info, logout
# 获取用户信息(自动缓存 token,失效时触发浏览器登录)
info = get_user_info()
print(info["email"])
print(info["username"])
print(info["unique_id"]) # 工号
print(info["token"]) # SSO token
# 强制重新登录(忽略本地缓存)
info = get_user_info(refresh=True)
# 不自动开浏览器(适合 CI/无头环境,打印 URL 手动访问)
info = get_user_info(open_browser=False)
# 自定义服务地址
info = get_user_info(service_url="https://sso.example.com")
# 删除本地缓存
logout()
返回值结构
get_user_info() 返回一个字典:
{
"username": "张三",
"unique_id": "12345", # 工号
"email": "zhangsan@example.com",
"mobile": "13800138000",
"mobile_area_code": "+86",
"account_type": "employee",
"login_channel": "wework",
"token": "<sso-token>",
}
环境变量
| 变量 | 说明 | 默认值 |
|---|---|---|
SSO_SERVICE_URL |
SSO 服务根 URL | 内置默认地址 |
SSO_TOKEN_DIR |
本地凭证目录 | ~/.config/happyelements-sso |
⚠️
token字段属于敏感信息,请勿将其写入日志或输出到不受控的位置。
CLI
he-sso # 输出用户信息
he-sso --refresh # 强制重新登录
he-sso --json # JSON 格式输出(含 token)
he-sso --delete # 删除本地缓存
he-sso --no-browser # 不自动开浏览器
he-sso --service-url https://... # 指定服务地址
he-sso --help # 查看所有选项
工作原理
- 优先读取本地缓存 token(
~/.config/happyelements-sso/credentials.json) - 向服务端验证 token 有效性
- token 不存在或已失效时,创建浏览器登录会话并轮询直到认证完成
- 新 token 自动保存到本地(目录权限
0700,文件权限0600)
AppSecret 仅保存在服务端,客户端零配置。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
he_sso-1.0.0.tar.gz
(3.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file he_sso-1.0.0.tar.gz.
File metadata
- Download URL: he_sso-1.0.0.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43b258c75ec7451f1a8ad123aad42deb2351bf29b77b424135a9cecea0101110
|
|
| MD5 |
79da4cc616b864ceb5f269cf2db261a0
|
|
| BLAKE2b-256 |
c0d56f18327aef2c50fc140a5b9cb52a00b738cac875d6cffba417af794d47cb
|
File details
Details for the file he_sso-1.0.0-py3-none-any.whl.
File metadata
- Download URL: he_sso-1.0.0-py3-none-any.whl
- Upload date:
- Size: 2.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52242cadea340afa56ce0d19e44752b16e8d2f0b662b3c970c884ca02b27779b
|
|
| MD5 |
8c0caf4a740ae5d1f840d5b4fc118611
|
|
| BLAKE2b-256 |
fa07fdddf641860240818ecb0fcc8f939b8ca51a332f9e998edea014f9bdb7e8
|