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 生成提交用密码密文。
  • 检测账号密码错误、验证码要求和短信二次验证。
  • 通过回调提交短信验证码。
  • 保存并复用 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 服务,可在 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.0.tar.gz (10.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.0-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

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

Hashes for njau_auth-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3f2a1cae2e8cb9d3b5cae6c7b81d03e2bc198ddab87e9597395a41a10fed0592
MD5 e6d5795d1b4a6b4cfb3a289823a6c9d3
BLAKE2b-256 364a364f9ad5b8e221fda1f8f787a6d5bb1d2f6c5d7a6f813bbe1ec7ffd09d06

See more details on using hashes here.

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

Hashes for njau_auth-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f9e306273a1ea7778863ddb3ecd1ab889dffa64e28069ae2e6d28a0236cb192a
MD5 b08ee65bff2af81591e981dd92e5caae
BLAKE2b-256 29732a567ed369d5bbebef4eec7bea41c036dfbd78a419320912e55cf0145f92

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