Skip to main content

Authentikate

codecov PyPI version Maintenance Maintainer PyPI pyversions PyPI status PyPI download month Code style: black Checked with mypy Ruff

What is Authentikate?

Authentikate is a library that provides a simple interface to validate tokens and retrieve corresponding user information inside a django application.

Note: This library is still somewhat tied to the Arkitekt Framework. We are working on making it more generic. If you have any ideas, please open an issue or a PR.

Alternatives

There are a few alternatives to this library, but none of them provide the same functionality. The most popular alternative is Simple JWT or Strawberry-django Auth . Both of these libraries provide a great way to authenticate users. So you should seriously consider using them instead of this library.

Why Authentikate?

Authentikate was designed to work with the Arkitekt Framework and therefore comes with a few additional features that are not available in other libraries.

Features:

  • Designed to work with the more specific Oauth2 Self-Encoded Access Tokens
  • Models Oauth2 Clients and Scopes
  • Build in support for Guardian for object level permissions
  • Build in support for Static Tokens (Token that are hard coded into the settings, e.g. for testing)
  • Build in support for Strawberry
  • Designed to work with Koherent for audit logging
  • Imitation support with Imitation Tokens (Token that are hard coded into the settings, e.g. for testing)

Composed Usage

If you plan to use Authentikate with the Arkitekt Framework, you should consider the Kante library. It composes Authentikate with Koherent and provides a simple interface to authenticate and log all changes that are done by a specific app and user.

How do I use it?

Authentikate is a Django Libary, so you will have to add it to your INSTALLED_APPS in your settings.py file.

INSTALLED_APPS = [
    ...
    'guardian', # This is required for object level permissions
    'authentikate',
    ...
]

AUTHENTICATION_BACKENDS = [
    "django.contrib.auth.backends.ModelBackend",
    "guardian.backends.ObjectPermissionBackend", # This is required for object level permissions
]

You will also need some additional configuration in your `settings.py` file.

```python
AUTH_USER_MODEL = "authentikate.User"


AUTHENTIKATE = {
    "ISSUERS": [
        {
            "kind": "jwks_uri",
            "iss": "https://lok.my-org.com",
            "jwks_uri": "https://lok.my-org.com/.well-known/jwks.json",
        }
    ],
    # This service's identifier, checked against the token's `aud`. Optional
    # today (a warning is logged when unset) and required from 4.0 — without it
    # a token your issuer minted for any other service is accepted here.
    "AUDIENCE": "my-service",
}

ISSUERS is the only required key. Each entry is selected by its kind (jwks_uri, jwks_dict, rsa, or rsa_file). For the full settings shape — issuers, static tokens, provenance, headers, the public API and error model — see docs/USAGE.md.

Upgrading from 2.x? 3.0 fixes two authentication bypasses and contains breaking changes (most notably: token roles are no longer mirrored onto Django Groups). See docs/UPGRADING.md.

Standard Usage

Koherent is designed to work with Strawberry, so you will need to add its extension to your schema.

from authentikate.utils import authenticate_header_or_none


def my_view(request: HttpRequest) -> None:
    auth = authenticate_header_or_none(request.headers)

    if auth:
        auth.user # This is the user that is authenticated
        auth.app # This is the app that is authenticated
        auth.scopes # These are the scopes that are authenticated

GraphQL Setup

Currently we require that you use the Kante GraphQL library, as it provides some boilerplate code that is required to make this work.

import strawberry
from authentikate.strawberry import AuthentikateExtension, AuthExtension

schema = strawberry.Schema(query=Query, extensions=[AuthentikateExtension])


@strawberry.type
class Query:

    @strawberry.field(extensions=[AuthExtension()])
    def me(self, info: Info) -> User:
        return info.context.request.user

    @strawberry.field(extensions=[AuthExtension(scopes=["read:users"])])
    def users(self, info: Info) -> List[User]:
        return User.objects.all()

AuthExtension accepts scopes, roles, any_scope_of and any_role_of. Use AuthSubscribeExtension on subscription fields.

Static Tokens

Static Tokens are tokens that are hard coded into the settings. They are useful for testing and development, but should not be used in production.

AUTHENTIKATE = {
    "ISSUERS": [
        {
            "kind": "jwks_uri",
            "iss": "https://lok.my-org.com",
            "jwks_uri": "https://lok.my-org.com/.well-known/jwks.json",
        }
    ],
    # Static tokens bypass signature verification entirely. They are for tests
    # and local development only: configuring them while DEBUG is False raises
    # ImproperlyConfigured at startup.
    "STATIC_TOKENS": {
        "my_token": {
            "sub": "my_user",
            "iss": "https://lok.my-org.com",
            "scope": "read:users",
            "roles": ["reader"],
        }
    }
}

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

authentikate-3.1.0.tar.gz (37.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

authentikate-3.1.0-py3-none-any.whl (48.0 kB view details)

Uploaded Python 3

File details

Details for the file authentikate-3.1.0.tar.gz.

File metadata

  • Download URL: authentikate-3.1.0.tar.gz
  • Upload date:
  • Size: 37.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for authentikate-3.1.0.tar.gz
Algorithm Hash digest
SHA256 bd9967e59685b2ffcc088188b86a441f516caa0473eb58460e19ad0e7690bb37
MD5 8385442b099ef233d2c7268681edd4b9
BLAKE2b-256 5bb127a99589855fe2f7cad8809bc4bef4f4e59ee622462a7b5e07f5158690d6

See more details on using hashes here.

File details

Details for the file authentikate-3.1.0-py3-none-any.whl.

File metadata

  • Download URL: authentikate-3.1.0-py3-none-any.whl
  • Upload date:
  • Size: 48.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for authentikate-3.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 52aac527ec348304f69ee57af36fa4d12101ffd58ff79a43ba9cea4787650486
MD5 301401e5f6952d65b076ea244f8030b8
BLAKE2b-256 6bb2180d59bf42d46660d0056efa92ca6eeeb77ba32decd1149cfc9fab9e1d57

See more details on using hashes here.

Release history Release notifications | RSS feed

4.1.0

2 files

4.0.1

2 files

4.0.0

2 files

3.2.0

2 files

This release

3.1.0 This release

2 files

3.0.0

2 files

2.2.1

2 files

2.2.0

2 files

2.1.2

2 files

2.1.1

2 files

2.1.0

2 files

2.0.1

2 files

2.0.0

2 files

1.3.0

2 files

1.2.0

2 files

1.1.0

2 files

1.0.1

2 files

1.0.0

2 files

0.32.0

2 files

0.31.0

2 files

0.30.0

2 files

0.29.0

2 files

0.28.0

2 files

0.26.0

2 files

0.25.0

2 files

0.24.0

2 files

0.23.0

2 files

0.22.0

2 files

0.21.1

2 files

0.21.0

2 files

0.20.0

2 files

0.19.0

2 files

0.18.2

2 files

0.18.1

2 files

0.18.0

2 files

0.17.1

2 files

0.17.0

2 files

0.16.0

2 files

0.15.0

2 files

0.14.0

2 files

0.13.0

2 files

0.12.0

2 files

0.11.0

2 files

0.10.0

2 files

0.9.1

2 files

0.9.0

2 files

0.8.1

2 files

0.8.0

2 files

0.7.0

2 files

0.6.0

2 files

0.5.0

2 files

0.4.0

2 files

0.1.11

2 files

0.1.10

2 files

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 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