Skip to main content

A simple authorization API for Python.

Project description

A simple authorization API for Python.

Example

First, mix the UserMixin and ResourceMixin with your User class and the resources you want to provide authorization for.

from moat import ResourceMixin, UserMixin

class Post(ResourceMixin):

    def type(self):
        return self.__class__.__name__

    def identifier(self):
        return self.id


class User(UserMixin):

    def identifier(self):
        return self.id

Now implement the methods specified in the base Repository class to retrieve the permissions from the datastore. Pass in an instance of the repository to the main Moat class.

Now you can check whether a user is actually authorized to do certain things:

from moat import Moat, Permissions
from moat.repositories import MockRepository

moat = Moat(MockRepository())

# Now you can check if a user has a specific permission for a certain object.
moat.has(Permission.read, user, post)
moat.has(Permission.write, user, post)

# Remove the permission
moat.remove(Permission.write, user, post)

# Set the permission, again
moat.set(Permission.write, user, post)

# Or get all the ids of type of resources the user has permissions for
moat.all(Permission.read, user, Post)

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

moat-0.1.0.tar.gz (2.6 kB view details)

Uploaded Source

File details

Details for the file moat-0.1.0.tar.gz.

File metadata

  • Download URL: moat-0.1.0.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for moat-0.1.0.tar.gz
Algorithm Hash digest
SHA256 efd8762eceda8e698fd3178d6ed5ebb895a797dbc820acb9c0ab2001c87effc9
MD5 100b6ebdc73b8282e6d48d87e873c32a
BLAKE2b-256 ef39f887aeace7b34b2231151f8bfdcf4f6f156554fbc19e2c5532d9cf38df04

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