Skip to main content
# PythonAuthenticationLib

A library for authenticating against the UserService

## Installation

pip install tangent-tokenauth

## Usage

Add to installed apps:

```
INSTALLED_APPS = (
...
'tokenauth',
)
```

Add to middleware:

```
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',

'tokenauth.middleware.TokenAuthMiddleware',
)
```

**Add authentication backends**

```
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',

## this will allow you to authenticate against the userservice with a token
'tokenauth.authbackends.TokenAuthBackend'
## this will allow you to authenticate against the userservice with a username and password
'tokenauth.authbackends.UserServiceAuthBackend'
)
```

**Notes:** It is advisable to include `UserServiceAuthBackend` after `ModelBackend`.
Since `UserServiceAuthBackend` will sync the user returned from the UserService, it will be preferable to login using the local synced user rather than hitting the UserService each time.
From the frontend this will be transparent.

**Add userservice url**

USERSERVICE_BASE_URL = "http://example.com"

**Profit**

$$

You can now authenticate against the UserService:

from django.contrib.auth.models import User

# TokenAuthBackend
user.authenticate(token)

# UserServiceAuthBackend
user.authenticate(username, password)

Metadata

Release files for tangent-tokenauth 0.1.4

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

Source distribution (sdist)

Source distribution for tangent-tokenauth 0.1.4
File Size Uploaded Provenance
tangent-tokenauth-0.1.4.tar.gz 4.7 kB Without provenance Details

Release files / tangent-tokenauth-0.1.4.tar.gz

Download URL tangent-tokenauth-0.1.4.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
488653b0cd1835d63e2660db1c0a82c0854d371bebe148dd5d176f7fafc6188f
BLAKE2b-256 checksum
How to use checksums
aec98b7773b47d45c20647e1377d0ded5facb4b91751d08fb94ca02f88256fcf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for tangent-tokenauth 0.1.4

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

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