Skip to main content

aboutcode.api_auth

Secured APIToken model and related APITokenAuthentication class.

Install

pip install aboutcode.api_auth

Define the APIToken model

In your main models.py module:

from aboutcode.api_auth import AbstractAPIToken

class APIToken(AbstractAPIToken):
    class Meta:
        verbose_name = "API Token"

Generate and apply schema migration:

$ ./manage.py makemigrations
$ ./manage.py migrate

Authenticator settings

Declare your APIToken model location in the API_TOKEN_MODEL setting:

API_TOKEN_MODEL = "your_app.APIToken"  # noqa: S105

Declare the APITokenAuthentication authentication class as one of the REST_FRAMEWORK.DEFAULT_AUTHENTICATION_CLASSES:

REST_FRAMEWORK = {
    "DEFAULT_AUTHENTICATION_CLASSES": (
        "aboutcode.api_auth.APITokenAuthentication",
    ),
}

Views (optional)

Base views are provided for generating and revoking API keys. They handle the token operations and redirect with a success message.

Subclass them in your app to add authentication requirements and configure the success URL and message:

from django.contrib.auth.mixins import LoginRequiredMixin
from django.urls import reverse_lazy

from aboutcode.api_auth.views import BaseGenerateAPIKeyView
from aboutcode.api_auth.views import BaseRevokeAPIKeyView


class GenerateAPIKeyView(LoginRequiredMixin, BaseGenerateAPIKeyView):
    success_url = reverse_lazy("profile")
    success_message = (
        "Copy your API key now, it will not be shown again: <pre>{plain_key}</pre>"
    )


class RevokeAPIKeyView(LoginRequiredMixin, BaseRevokeAPIKeyView):
    success_url = reverse_lazy("profile")
    success_message = "API key revoked."

Wire them up in your urls.py:

from your_app.views import GenerateAPIKeyView
from your_app.views import RevokeAPIKeyView

urlpatterns = [
    ...
    path("profile/api_key/generate/", GenerateAPIKeyView.as_view(), name="generate-api-key"),
    path("profile/api_key/revoke/", RevokeAPIKeyView.as_view(), name="revoke-api-key"),
]

Metadata

Release files for aboutcode.api-auth 0.2.0

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

Source distribution (sdist)

Source distribution for aboutcode.api-auth 0.2.0
File Size Uploaded Provenance Actions
aboutcode_api_auth-0.2.0.tar.gz 16.9 kB With provenance Details for aboutcode_api_auth-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for aboutcode.api-auth 0.2.0
File Interpreter ABI Platform Actions
aboutcode_api_auth-0.2.0-py3-none-any.whl Python 3 none any Details for aboutcode_api_auth-0.2.0-py3-none-any.whl

Total release size: 36.9 kB

Release files / aboutcode_api_auth-0.2.0.tar.gz

Download URL aboutcode_api_auth-0.2.0.tar.gz
Size 16.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5d3cbe19312db64f57f6ce3a63be11966d401e8c891e37290f4273b6893021b9
BLAKE2b-256 checksum
How to use checksums
957d97759f2b0008660ca05c7485f65824f2197edb246caa26879ba7d6c5c4c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 10, 2026.

Transparency log

Release files / aboutcode_api_auth-0.2.0-py3-none-any.whl

Download URL aboutcode_api_auth-0.2.0-py3-none-any.whl
Size 20.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
871181671c26dd27f3ac10ae2d469f0b31489586b13d3f0d14561bc8b5f7eaca
BLAKE2b-256 checksum
How to use checksums
c61122fbf05ee0a7554d73f1ea26128c189c6b866f3f22bc460931dce5963663
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 10, 2026.

Transparency log

Security for aboutcode.api-auth 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for aboutcode_api_auth-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 10, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

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