Skip to main content

OAuth2 Code Grant Authentication API

Project description

AuthAPI

A Simple Python API for Authenticated Operations.

landing_img

Quickstart:

Let's assume you want to interact with Google Ads API.

  1. Create my_secret.json with the following information:
{
    "client_id": "",
    "client_secret": "",
    "authorize_url": "",
    "access_token_url": "",
    "scopes": []
}
  1. Create a main.py script and paste the following content.
from authapi import AuthAPI, AuthData

class JsonSecret:
    def __init__(self, path: str):
        self.path = path

    def pull(self) -> dict:
        with open(self.path, "r") as f:
            return json.load(f)

    def push(self, payload: dict) -> None:
        with open(self.path, "w") as f:
            json.dump(payload, f)

app_secret = JsonSecret("my_secret.json")
app_token = JsonSecret("my_token.json")

auth_data = AuthData(**app_secret.pull())

app = AuthAPI(
    name="Auth API: My Auth API",
    auth_data=auth_data,
    token_secret=app_token,
)

app.debug = True


@app.route("/run", methods=["GET", "POST"])
def run():
    token = app.get_token()
    # Do your stuff here
    return "Done!"


if __name__ == "__main__":
    app.run(ssl_context="adhoc")
  1. Run python main.py and visit https://127.0.0.1:5000/ to start the authentication process.

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

authapi-0.1.15.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

authapi-0.1.15-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file authapi-0.1.15.tar.gz.

File metadata

  • Download URL: authapi-0.1.15.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.8 Linux/5.15.0-1022-azure

File hashes

Hashes for authapi-0.1.15.tar.gz
Algorithm Hash digest
SHA256 656d8acc64e647e79ed56c5715095ead5b2c218831602b0ab9b6817cb028d38a
MD5 3cb0a9158b751d45d21fbf1e47ac459b
BLAKE2b-256 06a54d094d07214b836cabbca2621e9bd0bda2f734b9458af9475f11ba6ca1eb

See more details on using hashes here.

File details

Details for the file authapi-0.1.15-py3-none-any.whl.

File metadata

  • Download URL: authapi-0.1.15-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.8 Linux/5.15.0-1022-azure

File hashes

Hashes for authapi-0.1.15-py3-none-any.whl
Algorithm Hash digest
SHA256 d96f6be7e569a900ec1d28c6b88e0ea76e1f8e6b66ecd8ed33d6ab812d8706fe
MD5 1051ed53cf7600e7feadd32deec2fb69
BLAKE2b-256 718f7df665dbd9e2abcbd5217a0ae53d17e5161c99d6b792e53410fc93bf5c70

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page