Skip to main content

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                       # 查看所有选项

工作原理

  1. 优先读取本地缓存 token(~/.config/happyelements-sso/credentials.json
  2. 向服务端验证 token 有效性
  3. token 不存在或已失效时,创建浏览器登录会话并轮询直到认证完成
  4. 新 token 自动保存到本地(目录权限 0700,文件权限 0600

AppSecret 仅保存在服务端,客户端零配置。

Project details


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.1.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

he_sso-1.0.1-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file he_sso-1.0.1.tar.gz.

File metadata

  • Download URL: he_sso-1.0.1.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.12

File hashes

Hashes for he_sso-1.0.1.tar.gz
Algorithm Hash digest
SHA256 5bc38f8a5530de3011dc272405e40f1409b364789f3ca88adbb417d75555f805
MD5 791c114b4b542aca7c60b795136e41ef
BLAKE2b-256 6d2a116c18daaf0449e3c1e4cd4a03a351e2a99321d8f76aaf9c483fe4d3affe

See more details on using hashes here.

File details

Details for the file he_sso-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: he_sso-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.12

File hashes

Hashes for he_sso-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 10be6da1404926beacee88ae79ebf2f8099a2cfe3df772b41f7dc6a8d8cc5dbe
MD5 359640401cf9c8f55b281b52952c0085
BLAKE2b-256 0c16e818d8b764add24796817adc8214377623215cbf724a9c267da22f0c220f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page