Skip to main content

No project description provided

Project description

PyWebAuthorize

The PyWebAuthorize library is intended to simplify all web based authorization

Install PyWebAuthorize

pip install pywebauthorization

PyWebAuthorize Hierarchy

  • basicauth
    • encode
      • parameters
        • user (str) The username of the user
        • password (str) The password of the user
        • use_hashed_password (bool) Flag to indicate password is hashed using SHA3-512 algorithm
      • return (str) Basic Authorization string Basic <Base64 encoded string>
      • raises (BasicAuthError) Raises exception with reason
    • decode
      • parameters
        • authorization (str) The basic authorization string Basic <Base64 encoded string>
      • return (dict) Returns the user and password in a key value pair dictionary
      • raises (BasicAuthError) Raises exception with reason
    • verify
      • parameters
        • authorization (str) The basic authorization string
        • use_hashed_password (bool) Flag to indicate password is hashed using SHA3-512 algorithm
      • return (bool) True = Authorized, False = Not Authorized
      • raises (BasicAuthError) Raises exception with reason

Documentation

basicauth.encode

Encodes a username and password into a valid Basic Authorization string

Example

from pywebauthorization import basicauth, BasicAuthError

try:
  # Note: 
  # If the use_hashed_password is False:
  # Basic dGVzdDoxMjM0NQ==
  # If the use_hashed_password is True: 
  # Basic dGVzdDowYTJhMTcxOWJmM2NlNjgyYWZkYmVkZjNiMjM4NTc4MThkNTI2ZWZiZTdmY2IzNzJiMzEzNDdjMjYyMzlhMGY5MTZjMzk4YjdhZDhkZDBlZTc2ZThlMzg4NjA0ZDBiMGY5MjVkNWU5MTNhZDJkMzE2NWI5YjM1YjM4NDRjZDVlNg== 
  user_name = 'test'
  user_password = '12345'
  basic_auth = basicauth.encode(user=user_name, password=user_password)
  print(f'{basic_auth}')
except BasicAuthError as e:
  print(f'{e}')

basicauth.decode

Decode the Basic Authorization string into a dictionary

# Example output
{
  'user': 'test', 
  'password': '12345'
}

Code Example

from pywebauthorization import basicauth, BasicAuthError

try:
  # Note: 
  # This should print out dictionary
  # {'user': 'test', 'password': '12345'}
  basic_auth_plain_text = 'Basic dGVzdDoxMjM0NQ=='
  basic_auth = basicauth.decode(authorization=basic_auth_plain_text)
  print(f'{basic_auth}')
except BasicAuthError as e:
  print(f'{e}')

basicauth.verify

Verify a basic authorization string sent from client with username and password

Code Example

from pywebauthorization import basicauth, BasicAuthError

try:
  # Note: 
  # This should print 'Verified: True'
  basic_auth_plain_text = 'Basic dGVzdDoxMjM0NQ=='
  user_auth = {'user': 'test', 'password': '12345'}
  verified = basicauth.verify(authorization=basic_auth_plain_text, user=user_auth)
  print(f'Verified: {verified}')
except BasicAuthError as e:
  print(f'{e}')

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

pywebauthorization-0.0.1.tar.gz (3.8 kB view details)

Uploaded Source

File details

Details for the file pywebauthorization-0.0.1.tar.gz.

File metadata

  • Download URL: pywebauthorization-0.0.1.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.1

File hashes

Hashes for pywebauthorization-0.0.1.tar.gz
Algorithm Hash digest
SHA256 2f659277e59bd4c4aaa4b7ef8d235a8ebb15536681cc90400f97e3a802a8c3f6
MD5 4a0961c37ca60900f1b81415e0c4e9c8
BLAKE2b-256 18d5591938a4af89cce815806ac2fca33186cdc4bc7bb9f5459e4d3906a8b0d3

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