Skip to main content

Automated XJTU OpenPlatform OAuth authentication for Python

Project description

Auth.xjtu

Introduction

auth-xjtu is a Python package for authentication at XJTU that automates the authentication process against Xi'an Jiaotong University’s (XJTU) OpenPlatform OAuth system. It handles the complete login flow, including AES‑encrypted password submission, CAPTCHA cookie retrieval, and redirect management, returning a valid session cookie jar ready for further HTTP requests.

Features:

  • AES Password Encryption: Replicates XJTU’s client‑side AES encryption with PKCS7 padding.
  • Cookie Management: Automatically captures and maintains all necessary cookies across intermediate redirects.
  • Redirect Handling: Intercepts HTTP 302 responses instead of following redirects, extracting Location headers for custom flows.
  • Logging: Built‑in logging with configurable console and file handlers, using standard logging module.
  • Simple Interface: Single Authenticator class with a login method that returns a requests cookie jar.

Installation

Install via pip:

pip install auth-xjtu

Or install from source:

git clone https://github.com/rouge3877/Auth.xjtu.git
cd Auth.xjtu
pip install .

Usage

from auth_xjtu import Authenticator

username = "your_xjtu_id"
password = "your_plain_password"
dest_url = "http://rg.lib.xjtu.edu.cn:8086" # for example
dest_host = "rg.lib.xjtu.edu.cn:8086"       # for example

# Create an authenticator instance
auth = Authenticator(username, password)

# Perform login and retrieve cookies
cookies = auth.login(dest_url, dest_host)

# Use the cookies in subsequent requests
# for test, can diff with the dest_url above
import requests
response = requests.get(
    "http://ehall.xjtu.edu.cn/new/index.html?browser=no",
    cookies=cookies
)
if response.status_code == 200:
    print("Authenticated successfully!")
else:
    print("Authentication failed.")

Logging

The package uses Python's built-in logging module for logging. You can configure the logging level and handlers as needed. By default, it logs to the console with a level of INFO, and logs to a file (which you should specify) with a level of DEBUG. You can change the logging configuration in the Authenticator class.

import logging
from auth_xjtu import Authenticator

...
auth = Authenticator(username, password, log_path="your_log_file.log")
# or the following if you don't want to use the default log file
#
# your_logger = logging.getLogger("auth_xjtu")
# your_logger.setLevel(logging.DEBUG)  # Set to DEBUG or INFO as needed
# auth = Authenticator(username, password, logger=your_logger)
cookies = auth.login(dest_url, dest_host)
...

License

This project is licensed under the MIT License. See the LICENSE file for details.

Disclaimer

This project is inspired by the need for a simple and effective way to authenticate against XJTU's OpenPlatform OAuth system. This project is not affiliated with or endorsed by Xi'an Jiaotong University. It is intended for educational and research purposes only. Use at your own risk.

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

auth_xjtu-0.1.0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

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

auth_xjtu-0.1.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file auth_xjtu-0.1.0.tar.gz.

File metadata

  • Download URL: auth_xjtu-0.1.0.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for auth_xjtu-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6af74fd41f3b4b1999abd0f67ad197887b0d05433259c08deb172d571a2f964a
MD5 8a80c468c00265b76a271803435723a6
BLAKE2b-256 d64f47dd3ee32d4a34243645471b1cbe31aea310fa0cda136089114109ae3a2c

See more details on using hashes here.

Provenance

The following attestation bundles were made for auth_xjtu-0.1.0.tar.gz:

Publisher: python-publish.yml on rouge3877/Auth.xjtu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file auth_xjtu-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: auth_xjtu-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for auth_xjtu-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 33fc3a2ff465745ad6db5b9551692144595d34cd8924497fcc71060b9837124c
MD5 daa6258817ec1097174ab1bceac76aea
BLAKE2b-256 edc9fcdb05ff41a9a8034dddf2e18451035f95b4c9ccd03cd9a00a011ea8df88

See more details on using hashes here.

Provenance

The following attestation bundles were made for auth_xjtu-0.1.0-py3-none-any.whl:

Publisher: python-publish.yml on rouge3877/Auth.xjtu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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