NJAU CAS authentication helper
Project description
NJAU-Auth
南京农业大学统一身份认证(CAS)登录辅助库,使用纯 HTTP 请求完成登录,不依赖 Playwright 或浏览器自动化。
当前支持:
- 使用学号和统一认证密码登录。
- 先 GET 登录页,提取
execution和pwdEncryptSalt。 - 使用 AES-128-CBC / PKCS7 生成提交用密码密文。
- 登录前自动检查是否需要图形验证码,必要时用
ddddocr默认模型识别 80x30 四位字符验证码。 - 检测账号密码错误、验证码要求和短信二次验证。
- 通过回调提交短信验证码。
- 保存并复用 Cookie,减少重复登录。
- 默认服务地址为
http://jw3.njau.edu.cn/。
Installation
pip install njau-auth
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,命令会从交互式密码输入读取。
调试验证码识别时可以保存图片,或指定一次手动验证码:
njau-auth-login --student-id 2023000000 --captcha-image-dir ./captchas
njau-auth-login --student-id 2023000000 --captcha-code abcd
Notes
- 默认密码密文使用当前 CAS 可接受的形态:
pwdEncryptSalt作为 AES key、固定 16 字节 IV、64 位随机前缀 + 原始密码作为明文。 - 图形验证码默认使用
ddddocr的 common.onnx 模型自动识别。 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.2.tar.gz
(14.2 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.2-py3-none-any.whl
(15.3 kB
view details)
File details
Details for the file njau_auth-0.1.2.tar.gz.
File metadata
- Download URL: njau_auth-0.1.2.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bde4006e2e4d2582724db7c727db34e63559b5bd3ac007ff4bb9f603a7cd01ed
|
|
| MD5 |
2947e962eb0fb564087046ea6cd4ce5a
|
|
| BLAKE2b-256 |
c66b09cb2fc6c17afb935e2f83caf76c77162c70c83fa15b275fd01b86571f84
|
File details
Details for the file njau_auth-0.1.2-py3-none-any.whl.
File metadata
- Download URL: njau_auth-0.1.2-py3-none-any.whl
- Upload date:
- Size: 15.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 |
4ca7b12c7cb3abf2a2a380538d93a811502b49b5a29336799f687c18f3462c8b
|
|
| MD5 |
6753712ba833f85940c0ae2457a83c47
|
|
| BLAKE2b-256 |
d507f32feda58649970c37fb8eb73cf4d0fd03d467b615657ef25af9ade26f1a
|