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.

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_app_url = "http://rg.lib.xjtu.edu.cn:8086" # for example

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

ret, message = auth.login(dest_app_url)

if ret == 0:
    print("==============Login successful!==============")
    session_for_login = auth.get_session()
    print("Content in %s:\n%s", dest_app_url, session_for_login.get(dest_app_url).text)
else:
    print("Login failed:", message)

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)
...

Detail

Login process

Authenticate the user and navigate to the destination application.

This login method performs a multi-step authentication process:

  1. Identifies the entry point URL for the destination application.
  2. Follows redirects to reach the authentication page.
  3. Constructs the necessary payload for authentication using the provided credentials.
  4. Submits the payload and follows redirects to complete the login process.

dest_app_url (str): The URL of the destination application requiring authentication.

Tuple[int, str]: A tuple containing:

  • int: Status code indicating the result of the authentication process:
    • 0: Success.
    • 1: Failure to retrieve the authentication page.
    • 2: Failure to construct the authentication payload.
    • 3: Failure during the login process after submitting the payload.
  • str: An error message describing the failure, or an empty string on success.

TODO

  • [ ]: Automate entry point discovery (src/auth_xjtu/core/find_entry.py)
  • [ ]: More tests

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.2.1.tar.gz (9.9 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.2.1-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: auth_xjtu-0.2.1.tar.gz
  • Upload date:
  • Size: 9.9 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.2.1.tar.gz
Algorithm Hash digest
SHA256 8b430be189e193018a3337276fee068320af86258ef44611c58463240868c814
MD5 96004978e97a10434977c4268267ce84
BLAKE2b-256 33d04d341ac73636e0e64a5750df1923257044a4c607f9ebdb08340403998417

See more details on using hashes here.

Provenance

The following attestation bundles were made for auth_xjtu-0.2.1.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.2.1-py3-none-any.whl.

File metadata

  • Download URL: auth_xjtu-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 9.5 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.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2554be5855704d88976ed454c61afdaf921fe12100e8414e89bf36b38f889e44
MD5 af282d3b14885c4ba6167417a90c52e9
BLAKE2b-256 3a047df045c6336eef56eefc8129e95326c9826d4f806c3d8da32b2055447231

See more details on using hashes here.

Provenance

The following attestation bundles were made for auth_xjtu-0.2.1-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