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 a app_secret.json with the following information:
{
    "client_id": "...",
    "client_secret": "..."
}
  1. Upload app_secret.json to your Secret Manager. Let's assume it's Google Cloud's Secret Manager.

  2. 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("your_secret.json")
app_token = JsonSecret("your_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")

You must fill the details in your_secret.json as follows:

{
    "client_id": "",
    "client_secret": "",
    "authorize_url": "",
    "access_token_url": "",
    "scopes": []
}
  1. 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.13.tar.gz (5.7 kB view hashes)

Uploaded Source

Built Distribution

authapi-0.1.13-py3-none-any.whl (7.9 kB view hashes)

Uploaded Python 3

Supported by

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