class BasicAuthentication
A configuration class for HTTP Basic authentication that stores username and password credentials for API calls.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/directory/authentication/basic.py
6 - 20
simple
Purpose
This class represents the configuration needed to perform HTTP Basic authentication in API requests. It inherits from ApiAuthenticationConfigurationBase and stores username and password credentials that will be encoded as base64 and sent in the Authorization header as 'Basic {encoded_credentials}'. This is a standard authentication mechanism used in HTTP APIs where credentials are transmitted in the format 'username:password' after base64 encoding.
Source Code
class BasicAuthentication(ApiAuthenticationConfigurationBase):
"""
Represents configuration for using HTTP Basic authentication, which entails a username and password, in an API call.
The username and password is sent as the Authorization header as Basic {value} where value is
base 64 encoded version of username:password.
"""
def __init__(self, username=None, password=None):
"""
:param str username: The username.
:param str password: The password. It is not returned in the responses.
"""
super(BasicAuthentication, self).__init__()
self.username = username
self.password = password
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
ApiAuthenticationConfigurationBase | - |
Parameter Details
username: The username credential for basic authentication. This is a string value that identifies the user attempting to authenticate. Can be None if not yet configured. This value will be combined with the password and base64 encoded for transmission.
password: The password credential for basic authentication. This is a string value used to verify the user's identity. Can be None if not yet configured. For security reasons, this value is not returned in API responses. It will be combined with the username and base64 encoded for transmission.
Return Value
Instantiation returns a BasicAuthentication object that stores the provided username and password credentials. This object can be used to configure API authentication settings and will be processed to generate the appropriate Authorization header for HTTP requests.
Class Interface
Methods
__init__(username=None, password=None)
Purpose: Initializes a new BasicAuthentication instance with the provided username and password credentials
Parameters:
username: Optional string representing the username for authentication. Defaults to None if not provided.password: Optional string representing the password for authentication. Defaults to None if not provided. This value is sensitive and not returned in responses.
Returns: None (constructor)
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
username |
str or None | Stores the username credential for basic authentication. This value is set during initialization and can be accessed for authentication purposes. | instance |
password |
str or None | Stores the password credential for basic authentication. This is sensitive data that should be protected and is not returned in API responses. Set during initialization. | instance |
Dependencies
office365
Required Imports
from office365.directory.authentication.configuration_base import ApiAuthenticationConfigurationBase
from office365.directory.authentication.basic import BasicAuthentication
Usage Example
from office365.directory.authentication.basic import BasicAuthentication
# Create a basic authentication configuration
auth_config = BasicAuthentication(
username='user@example.com',
password='secure_password123'
)
# Access the stored credentials
print(auth_config.username) # Output: user@example.com
# The password is stored but typically not displayed
# This object would be passed to an API client for authentication
# Example: api_client.authenticate(auth_config)
Best Practices
- Never hardcode passwords directly in source code; use environment variables or secure credential storage
- The password attribute should be treated as sensitive data and not logged or displayed
- Ensure credentials are transmitted over HTTPS to prevent interception since Basic authentication only uses base64 encoding (not encryption)
- Create a new instance for each set of credentials rather than modifying an existing instance
- The class is immutable after instantiation in typical usage - set username and password during construction
- This class is typically used as a configuration object passed to API clients rather than used directly for making HTTP requests
- Remember that the password is not returned in API responses for security reasons
- Consider using more secure authentication methods (like OAuth2) for production systems when available
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class ApiAuthenticationConfigurationBase 75.9% similar
-
class NetworkCredentialProvider 63.9% similar
-
class ClientCertificateAuthentication 61.7% similar
-
class UserCredential 58.2% similar
-
class AuthenticationProvider 58.1% similar