Skip to main content

Custom Django Oauth backend for Ressource Servers to download full user data fom Authorization Server

Project description

If you’ve read RFCs on OAuth or (more likely) the django-oauth-toolkit docs, you know that a Ressource Server sorts of delegates user authentication to the Authorization Server.

But the current implementation in Django OAuth Toolkit only copies the username from the Authorization Server in its database. This implies that all users have no special permissions, i.e. you lose administrator rights when you access the Ressource Server !

The class FullUserOAuthBackend aims to fix this by fetching the full user model from the Authorization Server after you’ve accessed the Ressource Server.

Installation

pip install oauth-slave-accounts

Setup

Authorization Server

You need to create an endpoint that exposes user data in a json manner (or further override my methods), the easiest being a DjangoRestFramework ModelViewset. The current implementation uses the user’s Authorization token as lookup_field.

class UserViewSet(viewset.ReadOnlyModelViewSet):
    queryset = User.objects.all()
    serializer_class = UserSerializer
    permission_classes = [ServerServerPermission]
    def get_object(self):
        return  AccessToken.objects.get(token=self.kwargs.get('pk')).user

pro tip: you should exclude the password from the serializer, because its confidential even if salted, and furthermore its useability probably depends on the SECRET_KEY

Ressource Server

Subclass ressource_server_utils.backend.FullUserOAuthBackend and override the following :
  • property fetch_url : a string that describes your Authorization Server’s endpoint to get User data e.g. http://auth.srv/user/{}/

  • property UserSerializer : a DjangoRestFramework Serializer that defines how to parse your Authorization Server’s response

  • And optionnally
    • method get_auth_token()

    • method refresh_auth_token()

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

oauth-slave-accounts-0.1.1.tar.gz (3.8 kB view details)

Uploaded Source

File details

Details for the file oauth-slave-accounts-0.1.1.tar.gz.

File metadata

  • Download URL: oauth-slave-accounts-0.1.1.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.5

File hashes

Hashes for oauth-slave-accounts-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c0361fa155935f94b286eac526b2b0ddad8ca5a5416a0246209595716150d924
MD5 14c853d14b293f1b40c2763757b1a813
BLAKE2b-256 e9c8dba0f137b8fde29884d0e81381c2b39d4fd0a533d8399b13f8c298b0e4b9

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