Skip to main content

oktagon-python

PyPI

This python package is a tiny utility for verifying & decoding OKTA tokens in python backend services.

Installation

pip install oktagon-python

Getting Started

Let's say you have /consignments REST API endpoint which you'd like to make accessible only by logistics OKTA group. Then you would write something like this:

import os

from oktagon_python.authorisation import AuthorisationManager
from starlette.requests import Request

auth_manager = AuthorisationManager(
    service_name="your_service_name",
    okta_issuer=os.environ.get("OKTAGON_OKTA_ISSUER"),
    okta_audience=os.environ.get("OKTAGON_OKTA_AUDIENCE"),
)

async def is_authorised(request: Request):
    return await auth_manager.is_user_authorised(
        allowed_groups=["logistics"],
        resource_name="consignments",
        cookies=request.cookies
    )

This will create an AuthorisationManager instance that will check user's authorisation.

Getting user's email

There is get_user_email async method on AuthorisationManager to retrieve user's email. Usage:

from starlette.requests import Request

cookies: Request.cookies = request.cookies
email = await auth_manager.get_user_email(cookies)

Contributing

git clone https://github.com/madedotcom/oktagon-python.git
cd oktagon-python
make install
make tests

This will install all the dependencies (including dev ones) and run the tests.

Run the formatters/linters

make pretty

Will run all the formatters and linters (black, isort and pylint) in write mode.

make pretty-check

Will run the formatters and linters in check mode.

You can also run them separtly with make black, make isort, make pylint.

Realeses

Merging a PR into the main branch will trigger the GitHub release workflow.
The following GitHub actions will be triggered:

Release files for oktagon-python 0.0.18

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for oktagon-python 0.0.18
File Size Uploaded
oktagon-python-0.0.18.tar.gz 22.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for oktagon-python 0.0.18
File Interpreter ABI Platform
oktagon_python-0.0.18-py3-none-any.whl Python 3 none any Details

Total release size: 27.5 kB

Release files / oktagon-python-0.0.18.tar.gz

Download URL oktagon-python-0.0.18.tar.gz
Size 22.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2d62639021f1eabf7aaf38e313e5207fe1a830e0e3029cf36f04d64b52e8f786
BLAKE2b-256 checksum
How to use checksums
3949a803c696970e4ae2502fb53d9d32db79d5db00c854fe43e372232d20c2b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.13

Release files / oktagon_python-0.0.18-py3-none-any.whl

Download URL oktagon_python-0.0.18-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b0095c010e703d0b6d6b4c727dfb3d4f2b49cf052b1365ea23d3cdabd8257eed
BLAKE2b-256 checksum
How to use checksums
9949ae22aa342268a87a4fc158116d988e0f257db5dcbf43c4126b852b84ce35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.13

Release history Release notifications | RSS feed

This release

0.0.18 This release

2 release files

0.0.17

2 release files

0.0.16

2 release files

0.0.15

2 release files

0.0.10

1 release file

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page