WhintPy 1.1

https://sourceforge.net/projects/whintpy/

whintpy.connection module

WhintPy Authentication System

This authentication system offers several methods to authenticate a user, including Basic Authentication, LDAP Authentication, and JWT Token generation and verification.

To use these classes for authentication, you need to integrate your chosen methods into the methods dictionary inside the AuthenticationMethods class.

Features

  • Multiple Authentication Methods: Supports Basic, LDAP, and JWT Token authentication.
  • Dynamic Configuration: Allows for the dynamic addition and management of authentication methods at runtime.
  • Centralized Management: Centralizes the configuration and usage of different authentication strategies.

Configuration

  • Choose the authentication methods required for your application.
  • Extend BaseAuthentication if you are creating a custom method.
  • -
    class YourCustomMethod(BaseAuthentication)
  • Add the authentication method you want to add to the existing methods in Connection.
    class Connection:
        def __init__(self):
            # Add custom authentication method here
            for auth_class in (
                LdapAuthentication,
                JwtAuthentication,
                YourCustomMethod
            ):  
                pass
  • Instantiate the Connection class and enable the necessary authentication methods.
    connection = Connection()
    connection.enable_method(YourMethod.name(), True, "Your parameters")
  • Use the connect method to authenticate a user with a specific method.
    connection.connect(YourMethod.name(), 'your_parameters')

General Usage Example

from ldap_authentication import LdapAuthentication
from jwt_token import JwtAuthentication
from connection import Connection

# Instantiate the Connection class
connection = Connection()

# Enable LDAP authentication method with domain "test.dom"
connection.enable_method(LdapAuthentication.name(), True, "test.dom")

# Enable JwtAuthentication authentication method with secret key "test"
connection.enable_method(JwtAuthentication.name(), True, "test")

# Authenticate a user with LDAP
if connection.connect(LdapAuthentication.name(), 'test', 'test'):
    print('User authenticated')
else:
    print('Authentication failed')

# Disable LDAP authentication method
connection.enable_method(LdapAuthentication.name(), False, "test.dom")
# Generate a token
connection.get_authentication_method_by_name(JwtAuthentication.name()).generate_token("test")
# Authenticate a user with a token (the token was generate with the generate_token method, replace it with the token you want to use)
if connection.connect(JwtAuthentication.name(), 'ultra_secure_token'):
    print('User authenticated')
else:
    print('Authentication failed')

# Disable JwtAuthentication authentication method
connection.enable_method(JwtAuthentication.name(), False)

List of classes