Sign inSign up

pesudev/pesu-auth

By pesudev

•Updated 11 days ago

A simple and lightweight API to authenticate PESU credentials using PESU Academy.

Image
API management
Developer tools
Web servers
0

1.3K

pesudev/pesu-auth repository overview

⁠pesu-auth

Docker Image Build Pre-Commit Checks Lint Deploy

Docker Automated build Docker Image Version (tag) Docker Image Size (tag)

A simple and lightweight API to authenticate PESU credentials using PESU Academy.

The API is secure and protects user privacy by not storing any user credentials. It only validates credentials and returns the user's profile information. No personal data is stored.

⁠PESUAuth LIVE Deployment

⁠API Status

Cron job status
Cron job status
Cron job status
Cron job status

Note

All timestamps are in UTC.

Warning

The live version is hosted on a free tier server located in the United States. As a result, you *might* experience higher latencies and slower response times, compared to running the API locally or on a server closer to your location.

⁠How to run PESUAuth locally

Running the PESUAuth API locally is simple. Clone the repository and follow the steps below to get started.

Tip

We recommend running the API locally using Docker for ease of use, the best performance, and lowest latency.
⁠Running with Docker

This is the easiest and recommended way to run the API locally. Ensure you have Docker installed on your system. Run the following commands to start the API.

  1. Build the Docker image either from the source code or pull the pre-built image from Docker Hub.

    1. You can build the Docker image from the source code by running the following command in the root directory of the repository.

      docker build . --tag pesu-auth
      
    2. You can also pull the pre-built Docker image from Docker Hub⁠ by running the following command:

      docker pull pesudev/pesu-auth:latest
      
  2. Run the Docker container

    docker run --name pesu-auth -d -p 5000:5000 pesu-auth
    # If you pulled the pre-built image, use the following command instead:
    docker run --name pesu-auth -d -p 5000:5000 pesudev/pesu-auth:latest
    
  3. Access the API at http://localhost:5000/

⁠Running without Docker

If you don't have Docker installed, you can run the API natively. Ensure you have Python 3.11 or higher installed on your system. We recommend using a package manager like uv⁠ to manage dependencies.

  1. Create a virtual environment using and activate it. Then, install the dependencies using the following commands.

    uv venv --python=3.11
    source .venv/bin/activate
    uv sync
    
  2. Run the API using the following command.

    uv run python -m app.app
    
  3. Access the API as previously mentioned on http://localhost:5000/

⁠How to use the PESUAuth API

The API provides multiple endpoints for authentication, documentation, and monitoring.

EndpointMethodDescription
/GETServes the interactive API documentation (Swagger UI).
/authenticatePOSTAuthenticates a user using their PESU credentials.
/healthGETA health check endpoint to monitor the API's status.
/readmeGETRedirects to the project's official GitHub repository.
⁠/authenticate

You can send a request to the /authenticate endpoint with the user's credentials and the API will return a JSON object, with the user's profile information if requested.

⁠Request Parameters
ParameterOptionalTypeDefaultDescription
usernameNostrThe user's SRN or PRN
passwordNostrThe user's password
profileYesbooleanFalseWhether to fetch profile information
fieldsYeslist[str]NoneWhich fields to fetch from the profile information. If not provided, all fields will be fetched
⁠Response Object

On authentication, it returns the following parameters in a JSON object. If the authentication was successful and profile data was requested, the response's profile key will store a dictionary with a user's profile information. On an unsuccessful sign-in, this field will not exist.

FieldTypeDescription
statusbooleanA flag indicating whether the overall request was successful
profileProfileObjectA nested map storing the profile information, returned only if requested
messagestrA message that provides information corresponding to the status
timestampdatetimeA timezone offset timestamp indicating the time of authentication
⁠ProfileObject

This object contains the user's profile information, which is returned only if the profile parameter is set to True. If the authentication fails, this field will not be present in the response.

FieldDescription
nameName of the user
prnPRN of the user
srnSRN of the user
programAcademic program that the user is enrolled into
branchComplete name of the branch that the user is pursuing
semesterCurrent semester that the user is in
sectionSection of the user
emailEmail address of the user registered with PESU
phonePhone number of the user registered with PESU
campus_codeThe integer code of the campus (1 for RR and 2 for EC)
campusAbbreviation of the user's campus name
⁠/health

This endpoint can be used to check the health of the API. It's useful for monitoring and uptime checks. This endpoint does not take any request parameters.

⁠Response Object
FieldTypeDescription
statusstrtrue if healthy, false if there was an error
messagestr"ok" if healthy, error message otherwise
timestampstringA timezone offset timestamp indicating the time of authentication
⁠/readme

This endpoint redirects to the project's official GitHub repository. This endpoint does not take any request parameters.

⁠Integrating your application with the PESUAuth API

Here are some examples of how you can integrate your application with the PESUAuth API using Python and cURL.

⁠Python
⁠Request
import requests

data = {
    "username": "your SRN or PRN here",
    "password": "your password here",
    "profile": True,  # Optional, defaults to False
}

response = requests.post("http://localhost:5000/authenticate", json=data)
print(response.json())
⁠Response
{
  "status": true,
  "profile": {
    "name": "Johnny Blaze",
    "prn": "PES1201800001",
    "srn": "PES1201800001",
    "program": "Bachelor of Technology",
    "branch": "Computer Science and Engineering",
    "semester": "NA",
    "section": "NA",
    "email": "[email protected]",
    "phone": "1234567890",
    "campus_code": 1,
    "campus": "RR"
  },
  "message": "Login successful.",
  "timestamp": "2024-07-28 22:30:10.103368+05:30"
}
⁠cURL
⁠Request
curl -X POST http://localhost:5000/authenticate \
-H "Content-Type: application/json" \
-d '{
    "username": "your SRN or PRN here",
    "password": "your password here"
}'
⁠Response
{
  "status": true,
  "message": "Login successful.",
  "timestamp": "2024-07-28 22:30:10.103368+05:30"
}

⁠Contributing to PESUAuth

Made with ❤️ by

Contributors

Powered by contrib.rocks⁠

If you'd like to contribute, please follow our contribution guidelines⁠.

Tag summary

Content type

Image

Digest

sha256:27e1bc346…

Size

27.7 MB

Last updated

11 days ago

docker pull pesudev/pesu-auth