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
Locationheaders for custom flows. - Logging: Built‑in logging with configurable console and file handlers, using standard
loggingmodule. - Simple Interface: Single
Authenticatorclass with aloginmethod that returns arequestscookie 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
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
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
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6af74fd41f3b4b1999abd0f67ad197887b0d05433259c08deb172d571a2f964a
|
|
| MD5 |
8a80c468c00265b76a271803435723a6
|
|
| BLAKE2b-256 |
d64f47dd3ee32d4a34243645471b1cbe31aea310fa0cda136089114109ae3a2c
|
Provenance
The following attestation bundles were made for auth_xjtu-0.1.0.tar.gz:
Publisher:
python-publish.yml on rouge3877/Auth.xjtu
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
auth_xjtu-0.1.0.tar.gz -
Subject digest:
6af74fd41f3b4b1999abd0f67ad197887b0d05433259c08deb172d571a2f964a - Sigstore transparency entry: 217708772
- Sigstore integration time:
-
Permalink:
rouge3877/Auth.xjtu@82d7a09c9803abe4e666f24e414620b96c0b7605 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/rouge3877
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@82d7a09c9803abe4e666f24e414620b96c0b7605 -
Trigger Event:
workflow_dispatch
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
33fc3a2ff465745ad6db5b9551692144595d34cd8924497fcc71060b9837124c
|
|
| MD5 |
daa6258817ec1097174ab1bceac76aea
|
|
| BLAKE2b-256 |
edc9fcdb05ff41a9a8034dddf2e18451035f95b4c9ccd03cd9a00a011ea8df88
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
auth_xjtu-0.1.0-py3-none-any.whl -
Subject digest:
33fc3a2ff465745ad6db5b9551692144595d34cd8924497fcc71060b9837124c - Sigstore transparency entry: 217708778
- Sigstore integration time:
-
Permalink:
rouge3877/Auth.xjtu@82d7a09c9803abe4e666f24e414620b96c0b7605 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/rouge3877
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@82d7a09c9803abe4e666f24e414620b96c0b7605 -
Trigger Event:
workflow_dispatch
-
Statement type: