Skip to main content

NJAU CAS authentication helper

Project description

NJAU-Auth

南京农业大学统一身份认证(CAS)登录辅助库。项目形态参考 Golevka2001/SEU-Auth,当前版本使用纯 HTTP 请求完成登录,不依赖 Playwright 或浏览器自动化。

当前实现参考了本地 NJAU-Libyy 项目中可工作的 CAS 自动化流程,支持:

  • 使用学号和统一认证密码登录。
  • 先 GET 登录页,提取 executionpwdEncryptSalt
  • 使用 AES-128-CBC / PKCS7 生成提交用密码密文。
  • 登录前自动检查是否需要图形验证码,必要时用 ddddocr 默认模型识别 80x30 四位字符验证码。
  • 检测账号密码错误、验证码要求和短信二次验证。
  • 通过回调提交短信验证码。
  • 保存并复用 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,命令会从交互式密码输入读取。

调试验证码识别时可以保存图片,或指定一次手动验证码:

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 服务,可在 NJAUAuthClientNJAUAuthManager 中传入 service_urlsuccess_url_contains
  • 当统一认证要求滑块验证码,或图形验证码多次识别失败时,当前版本会抛出 CaptchaRequiredError

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

njau_auth-0.1.1.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

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

njau_auth-0.1.1-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file njau_auth-0.1.1.tar.gz.

File metadata

  • Download URL: njau_auth-0.1.1.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for njau_auth-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1019c5a1f2ac70da86890bfcafdb162fa048e2d1c69cf4daca5b78820785f0db
MD5 f9a5a170e3d750251c9211ad5f689a75
BLAKE2b-256 4c8e5a937be7d6110976a8a5ed97bf5e2c3fc98bd3a5cc215e40a65ab0da9630

See more details on using hashes here.

File details

Details for the file njau_auth-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: njau_auth-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 15.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for njau_auth-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a6aa5a8e961c665402831a27a6ecbddf31378698e71b8bee157d8afec25f99e7
MD5 d01a4cfb36d66aa1df51965078208258
BLAKE2b-256 23fb46462f271abacf5816f8c8fbb59c641218e25ddac8d5f282a681d856fd72

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