Skip to main content
https://img.shields.io/travis/com/bruziev/security_interface.svg?style=flat-square https://img.shields.io/codecov/c/github/bruziev/security_interface.svg?style=flat-square

Security Interface

This library provides easy API for authentication and authorization.

Installation

Install with the following command:

$ pip install security_interface

Usage

First of all you need implement IdentityPolicyInterface and AuthorizationPolicyInterface interfaces. For example we can implement JWT Security:

import jwt
from security_interface import IdentityPolicyInterface, AuthorizationPolicyInterface

class JwtIdentityPolicy(IdentityPolicyInterface):
    def __init__(self, secret, algorithm="HS256"):
        self.algorithm = algorithm
        self.secret = secret

    async def identify(self, identity):
        if jwt is None:
            raise TypeError("Please install PyJWT")
        try:
            return jwt.decode(
                identity,
                self.secret,
                algorithms=[self.algorithm],
                options={"verify_exp": True, "verify_iat": True},
            )
        except Exception as e:
            return None

class JwtAuthPolicy(AuthorizationPolicyInterface):
    async def can(self, identity, permission):
        return permission in identity["scope"]

Create security instance with our implementation

from security_interface.api import Security
jwt_identity = JwtIdentityPolicy("SECRET")
jwt_auth_policy = JwtAuthPolicy()
security = Security(jwt_identity, jwt_auth_policy)
# Checking claim
security.identify(CLAIM)
# Checking permission
security.can(CLAIM, "read")
security.can(CLAIM, "write")

For full implementation see DEMO

Metadata

Release files for security-interface 0.1.0

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

Source distribution (sdist)

Source distribution for security-interface 0.1.0
File Size Uploaded Provenance Actions
security_interface-0.1.0.tar.gz 3.4 kB Without provenance Details for security_interface-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for security-interface 0.1.0
File Interpreter ABI Platform Actions
security_interface-0.1.0-py2.py3-none-any.whl Python 3, Python 2 none any Details for security_interface-0.1.0-py2.py3-none-any.whl

Total release size: 8.9 kB

Release files / security_interface-0.1.0.tar.gz

Download URL security_interface-0.1.0.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b3248553ac7f2c34ba1c135a17582ddbdc853c3a71e43a345a8ee52b18aca2b9
BLAKE2b-256 checksum
How to use checksums
0bd5698447436c98bab0d3a3a401113b6ee0786060d099bac1bd2ad6ec6508c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

Release files / security_interface-0.1.0-py2.py3-none-any.whl

Download URL security_interface-0.1.0-py2.py3-none-any.whl
Size 5.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
0d2f35a82fbea387898e316c504eed4689983f593adfd0b7767283c70e6b75ec
BLAKE2b-256 checksum
How to use checksums
6eab275e37f2a60422d9785de81c6104e776ddbde4e6d9cb34e4713c45690ddb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

Security for security-interface 0.1.0

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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