Skip to main content

No project description provided

Project description

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 = {
    "KEY_TYPE": "RS256",
    "PUBLIC_KEY_PEM_FILE": "public_key.pem",
    "FORCE_CLIENT": False, # allows non Oauth2 JWTs to be used

}

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.

from authentikate.strawberry.permissions import IsAuthenticated, NeedsScopes

@strawberry.type
class Query

    @strawberry.field(permission_classes=[IsAuthenticated])
    def me(self, info: Info) -> User:
        return info.context.auth.user

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

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 = {
    "KEY_TYPE": "RS256",
    "PUBLIC_KEY_PEM_FILE": "public_key.pem",
    "FORCE_CLIENT": False, # allows non Oauth2 JWTs to be used
    "STATIC_TOKENS": {
        "my_token": {
            "user": "my_user",
            "app": "my_app",
            "scopes": ["read:users"]
        }
    }
}

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

authentikate-0.9.0.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

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

authentikate-0.9.0-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: authentikate-0.9.0.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.2

File hashes

Hashes for authentikate-0.9.0.tar.gz
Algorithm Hash digest
SHA256 6a1c7bafbda25f25fc56daee4055e60e3d1edc837660bce4ebc2865ce7abe087
MD5 70a9de0dd9f21d2810b3ffe53b27c4bb
BLAKE2b-256 c41f3c2da3318b23f2e6cd6946b48c30db4b8327a6eb8092c99c4b3386c8d34b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for authentikate-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 621497c13f136c9c9eff2492c129dae73a9a1cd1deb824816e2d2a2171fefd23
MD5 27a67cebff25cd134578430578ddabd4
BLAKE2b-256 6031d9a9d3a4704c22bcd2655736fca1a04d31dcfd283fc499b689ba353a5319

See more details on using hashes here.

Supported by

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