NJAU CAS authentication helper
Project description
NJAU-Auth
南京农业大学统一身份认证(CAS)登录辅助库。项目形态参考 Golevka2001/SEU-Auth,当前版本使用纯 HTTP 请求完成登录,不依赖 Playwright 或浏览器自动化。
当前实现参考了本地 NJAU-Libyy 项目中可工作的 CAS 自动化流程,支持:
- 使用学号和统一认证密码登录。
- 先 GET 登录页,提取
execution和pwdEncryptSalt。 - 使用 AES-128-CBC / PKCS7 生成提交用密码密文。
- 检测账号密码错误、验证码要求和短信二次验证。
- 通过回调提交短信验证码。
- 保存并复用 Cookie,减少重复登录。
- 默认服务地址为
http://jw3.njau.edu.cn/。
Installation
pip install -e .
Basic Usage
import asyncio
from njau_auth import NJAUAuthManager
async def sms_callback(challenge):
print(challenge.message)
return input("SMS code: ").strip()
async def main():
manager = NJAUAuthManager(
student_id="2023000000",
password="your-password",
sms_callback=sms_callback,
)
async with manager:
result = await manager.login()
print(result.final_url)
print(result.cookies)
asyncio.run(main())
CLI
njau-auth-login --student-id 2023000000
如果不传 --password,命令会从交互式密码输入读取。
Notes
- 默认密码密文使用当前 CAS 可接受的形态:
pwdEncryptSalt作为 AES key、固定 16 字节 IV、64 位随机前缀 + 原始密码作为明文。 utils.crypto里保留了固定 key 的兼容函数encrypt_password_with_fixed_key(),用于兼容其他部署或后续验证。- 如果要认证其他 CAS 服务,可在
NJAUAuthClient或NJAUAuthManager中传入service_url和success_url_contains。 - 当统一认证要求图形验证码或滑块验证码时,当前版本会直接抛出
CaptchaRequiredError,避免误判或卡死。
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
njau_auth-0.1.0.tar.gz
(10.6 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
njau_auth-0.1.0-py3-none-any.whl
(13.3 kB
view details)
File details
Details for the file njau_auth-0.1.0.tar.gz.
File metadata
- Download URL: njau_auth-0.1.0.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f2a1cae2e8cb9d3b5cae6c7b81d03e2bc198ddab87e9597395a41a10fed0592
|
|
| MD5 |
e6d5795d1b4a6b4cfb3a289823a6c9d3
|
|
| BLAKE2b-256 |
364a364f9ad5b8e221fda1f8f787a6d5bb1d2f6c5d7a6f813bbe1ec7ffd09d06
|
File details
Details for the file njau_auth-0.1.0-py3-none-any.whl.
File metadata
- Download URL: njau_auth-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9e306273a1ea7778863ddb3ecd1ab889dffa64e28069ae2e6d28a0236cb192a
|
|
| MD5 |
b08ee65bff2af81591e981dd92e5caae
|
|
| BLAKE2b-256 |
29732a567ed369d5bbebef4eec7bea41c036dfbd78a419320912e55cf0145f92
|