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.0.tar.gz (9.7 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.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: auth_xjtu-0.2.0.tar.gz
  • Upload date:
  • Size: 9.7 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.0.tar.gz
Algorithm Hash digest
SHA256 a1a22486b15a3039ad043f90211f01828ba1370ab5c37aaddeef1dc771a78103
MD5 2352e568d43617cf58ca5f7b5205f743
BLAKE2b-256 785fa03d6fe35b3e6571bfd3dc6ba577ebc4379fcaa9f21abff071fa1537eebe

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: auth_xjtu-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.3 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d82e8d652a9c049c37ba3c12ba8001721a691d19ed87d4c5faf4fe362e671e6f
MD5 deb3a57a5844be87bd9f58a9b88f73d5
BLAKE2b-256 28a790af862910b7c4ab8694c50b7452512aac24d211f3aa4a00657adfd5c81e

See more details on using hashes here.

Provenance

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