Skip to main content

No project description provided

Project description

PyWebAuthorization

The PyWebAuthorize library is intended to simplify all web based authorization

Install PyWebAuthorization

pip install pywebauthorization

PyWebAuthorization 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.2.tar.gz (3.8 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: pywebauthorization-0.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 92e6901364634b14e7a6f189a0d9262a140f953d369d2be1eeeaca283d6b141a
MD5 5476b7cc7e79a0eb37c13b9a2dd487a3
BLAKE2b-256 a4adc1e92b2dc9dd06cdf74d392a1b0959005cc8c93d5aa192fd1fa9f0352342

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