Skip to main content
# Simple python authorization

This module was created to provide a simple authorization method to be used in service to service authorization.

## How to use

**Important note about the credentials backend:** At this moment we do not provide a backend to store credentials. We receive a dict containing all the valid credentials following this format: `{"app_key":["app_name","secret"]}`

Create a middleware in your API that receives the Authorization header and passes it to the package to ensue that the token is valid. In the above example we have a simple endpoint that validates the authentication based on a local dictionary as a credentials backend. Ideally you will implement a credential repository and pass the valid credentials to the module.

```python
from http import HTTPStatus
from flask import request, jsonify, Flask
from python_authorization import Authorization

app = Flask(__name__)

@app.route('/')
def dummy_endpoint():
authorization_header = request.headers.get('Authorization')

py_auth = Authorization(authorization_header, valid_credentials_dict={'valid_app_key1': ['valid_app_name', 'valid_secret']})

# This method will only validate the format of the token
is_valid = py_auth.validate_token_format()

if not is_valid:
return (jsonify({'Message': 'Invalid authorization token format'}), HTTPStatus.UNAUTHORIZED)

# This method will asume that the token is in a valid format and will try to validate it
is_authorized = py_auth.validate_token()

if not is_authorized:
return (jsonify({'Message': 'Invalid authorization token'}), HTTPStatus.UNAUTHORIZED)

return (jsonify({'Message': 'You are in!'}), HTTPStatus.OK)

app.run('0.0.0.0', port=5000)
```

You can also use this module to authenticate at a service using the Credentials class.

```python
from python_authorization import Credentials

credentials_factory = Credentials('valid_app_name', 'valid_app_key1', 'valid_secret')

token = credentials_factory.build_token()

print(f'This is my token: {token}')
```

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_authorization-1.0.2.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_authorization-1.0.2-py2.py3-none-any.whl (6.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file python_authorization-1.0.2.tar.gz.

File metadata

  • Download URL: python_authorization-1.0.2.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for python_authorization-1.0.2.tar.gz
Algorithm Hash digest
SHA256 49177f351d492ba7bc93db0fd4d14bfe274f46513bfabbbe397e63936d738a61
MD5 434c639cc651e8bdd4fef45be3891bf5
BLAKE2b-256 f71ef2df3643493829962669fb02714bbb1d8140cf1c7fe035eb548c91c669ec

See more details on using hashes here.

File details

Details for the file python_authorization-1.0.2-py2.py3-none-any.whl.

File metadata

  • Download URL: python_authorization-1.0.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for python_authorization-1.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f16c5da5e31530a079366c4cb814f5f99b2098e9e101597c74c27b559c25782a
MD5 5caf4c21a45802374600756697f0b418
BLAKE2b-256 ea86c3656c17fc4bbf583c01a684343d7cc301755e160591ce27ef4d7492067e

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.4

1 file

1.0.3

2 files

This release

1.0.2 This release

2 files

1.0.1

2 files

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