Authentication lib for Tangent Micro Services
Project description
# 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)
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)
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
File details
Details for the file tangent-tokenauth-0.1.4.tar.gz
.
File metadata
- Download URL: tangent-tokenauth-0.1.4.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 488653b0cd1835d63e2660db1c0a82c0854d371bebe148dd5d176f7fafc6188f |
|
MD5 | c770ee4c989d3f410d505e9bf4bddf68 |
|
BLAKE2b-256 | aec98b7773b47d45c20647e1377d0ded5facb4b91751d08fb94ca02f88256fcf |