semvec/pypi-packages huggingface dataset:
pywebauthorize 0.0.2
A Web authorization utility

# PyWebAuthorize
The purpose of webauth library is to simplify Web Authorization 
functionality.

## Install library
```bash
pip install pywebauthorize
```

## basicauth
The basic authorization module has the ability to encode a
user and password into a Basic Authorization token. Also,
decode the same token into a user and password stored return
into a dictionary results.

- basicauth
  - encode - Encodes a user and password into a Basic Authorization string
    - parameters
      - user (str): The username of the user to encode
      - password (str) : The password of the user to encode
      - use_hashed_password (bool) : Flag that indicates if the password is hashed using SHA3-512 algorithm
  - decode - Decodes a Basic Authorization string into a dictionary with a user and password
    - parameters
      - authorization (str) - The basic authorization string that is setup in the following format.
      ```bash Basic <base64 encode string>```
  - verify - Allows the developer to pass a Basic Authorization String from the request headers and compare it to passed user and password key value pair
  
## Example for baseauth.encode
```python
from pywebauthorize import basicauth, BasicAuthError


try:
    # This method will build a string in the this format
    # 'Basic base64encode(user:password)'
    # If the encode it will raise a BasicAuthError
    # Typically an BasicAuthError will be raised only in the
    # event the user or password is blank or None
    basic_auth = basicauth.encode(user="test", password="password")
    # This should output the string => Basic dGVzdDpwYXNzd29yZA==
    print(basic_auth)
except BasicAuthError as e:
    print(f"{e}")
```

## Example for basicauth.decode
```python
from pywebauthorize import basicauth, BasicAuthError


try:
    # Note this token will be formatted like the following:
    # Basic <base64 encoded string>
    basic_auth = 'Basic dGVzdDpwYXNzd29yZA=='
    user_info = basicauth.decode(authorization=basic_auth)
    # This should print out a dictionary with as follows
    # { 'user': 'test', 'password': 'password' }
    print(basic_auth)
except BasicAuthError as e:
    print(f"{e}")
```

## Example for basicauth.verify
```python
from pywebauthorize import basicauth, BasicAuthError


try:
    # Note this token will be formatted like the following:
    # Basic <base64 encoded string>
    authorization = 'Basic dGVzdDpwYXNzd29yZA=='
    user = {'user': 'test', 'password': 'password'}
    result = basicauth.verify(authorization=authorization, user=user)
    # This should print out True or False
    print('Verified: ', result)
except BasicAuthError as e:
    print(f"{e}")
```