auth-xjtu


Nameauth-xjtu JSON
Version 0.2.1 PyPI version JSON
download
home_pageNone
SummaryAutomated XJTU OpenPlatform OAuth authentication for Python
upload_time2025-08-17 16:09:14
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseNone
keywords xjtu auth_xjtuoauth authentication python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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:

```bash
pip install auth-xjtu
```

Or install from source:

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

## Usage

```python
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.


```python
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](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.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "auth-xjtu",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "xjtu, auth_xjtuoauth, authentication, python",
    "author": null,
    "author_email": "Rouge Lin <rougeLin3877@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/33/d0/4d341ac73636e0e64a5750df1923257044a4c607f9ebdb08340403998417/auth_xjtu-0.2.1.tar.gz",
    "platform": null,
    "description": "# Auth.xjtu\n\n\n## Introduction\n`auth-xjtu` is a `Python` package for authentication at XJTU that automates the authentication process against Xi'an Jiaotong University\u2019s (XJTU) OpenPlatform OAuth system. It handles the complete login flow, including AES\u2011encrypted password submission, CAPTCHA cookie retrieval, and redirect management, returning a valid session cookie jar ready for further HTTP requests.\n\n## Installation\n\nInstall via pip:\n\n```bash\npip install auth-xjtu\n```\n\nOr install from source:\n\n```bash\ngit clone https://github.com/rouge3877/Auth.xjtu.git\ncd Auth.xjtu\npip install .\n```\n\n## Usage\n\n```python\nfrom auth_xjtu import Authenticator\n\nusername = \"your_xjtu_id\"\npassword = \"your_plain_password\"\ndest_app_url = \"http://rg.lib.xjtu.edu.cn:8086\" # for example\n\n# Create an authenticator instance\nauth = Authenticator(username, password)\n\nret, message = auth.login(dest_app_url)\n\nif ret == 0:\n    print(\"==============Login successful!==============\")\n    session_for_login = auth.get_session()\n    print(\"Content in %s:\\n%s\", dest_app_url, session_for_login.get(dest_app_url).text)\nelse:\n    print(\"Login failed:\", message)\n\n```\n\n## Logging\nThe 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.\n\n\n```python\nimport logging\nfrom auth_xjtu import Authenticator\n\n...\nauth = Authenticator(username, password, log_path=\"your_log_file.log\")\n# or the following if you don't want to use the default log file\n#\n# your_logger = logging.getLogger(\"auth_xjtu\")\n# your_logger.setLevel(logging.DEBUG)  # Set to DEBUG or INFO as needed\n# auth = Authenticator(username, password, logger=your_logger)\ncookies = auth.login(dest_url, dest_host)\n...\n\n```\n\n## Detail\n\n### Login process\nAuthenticate the user and navigate to the destination application.\n\nThis login method performs a multi-step authentication process:\n1. Identifies the entry point URL for the destination application.\n2. Follows redirects to reach the authentication page.\n3. Constructs the necessary payload for authentication using the provided credentials.\n4. Submits the payload and follows redirects to complete the login process.\n\n`dest_app_url (str)`: The URL of the destination application requiring authentication.\n\n`Tuple[int, str]`: A tuple containing:\n- `int`: Status code indicating the result of the authentication process:\n    - 0: Success.\n    - 1: Failure to retrieve the authentication page.\n    - 2: Failure to construct the authentication payload.\n    - 3: Failure during the login process after submitting the payload.\n- `str`: An error message describing the failure, or an empty string on success.\n\n## TODO\n- [ ]: Automate entry point discovery (`src/auth_xjtu/core/find_entry.py`)\n- [ ]: More tests\n\n## License\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n\n## Disclaimer\nThis 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.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Automated XJTU OpenPlatform OAuth authentication for Python",
    "version": "0.2.1",
    "project_urls": {
        "Homepage": "https://github.com/rouge3877/Auth.xjtu",
        "Issues": "https://github.com/rouge3877/Auth.xjtu/issues"
    },
    "split_keywords": [
        "xjtu",
        " auth_xjtuoauth",
        " authentication",
        " python"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "3a047df045c6336eef56eefc8129e95326c9826d4f806c3d8da32b2055447231",
                "md5": "af282d3b14885c4ba6167417a90c52e9",
                "sha256": "2554be5855704d88976ed454c61afdaf921fe12100e8414e89bf36b38f889e44"
            },
            "downloads": -1,
            "filename": "auth_xjtu-0.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "af282d3b14885c4ba6167417a90c52e9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 9514,
            "upload_time": "2025-08-17T16:09:13",
            "upload_time_iso_8601": "2025-08-17T16:09:13.584156Z",
            "url": "https://files.pythonhosted.org/packages/3a/04/7df045c6336eef56eefc8129e95326c9826d4f806c3d8da32b2055447231/auth_xjtu-0.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "33d04d341ac73636e0e64a5750df1923257044a4c607f9ebdb08340403998417",
                "md5": "96004978e97a10434977c4268267ce84",
                "sha256": "8b430be189e193018a3337276fee068320af86258ef44611c58463240868c814"
            },
            "downloads": -1,
            "filename": "auth_xjtu-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "96004978e97a10434977c4268267ce84",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 9854,
            "upload_time": "2025-08-17T16:09:14",
            "upload_time_iso_8601": "2025-08-17T16:09:14.653802Z",
            "url": "https://files.pythonhosted.org/packages/33/d0/4d341ac73636e0e64a5750df1923257044a4c607f9ebdb08340403998417/auth_xjtu-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-17 16:09:14",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "rouge3877",
    "github_project": "Auth.xjtu",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "auth-xjtu"
}
        
Elapsed time: 0.70195s