get_basic_auth_credentials

View as MarkdownOpen in Claude

Retrieve the current HTTP Basic Auth credentials used by this service. Every SWMLService instance has auth credentials — either explicitly provided in the constructor, read from environment variables, or auto-generated at startup.

Parameters

include_source
boolDefaults to False

When True, returns a 3-tuple that includes the credential source as the third element. The source is one of:

  • "environment" — credentials came from SWML_BASIC_AUTH_USER and SWML_BASIC_AUTH_PASSWORD environment variables
  • "auto-generated" — credentials were randomly generated at startup

Returns

tuple[str, str] — A (username, password) tuple when include_source is False.

tuple[str, str, str] — A (username, password, source) tuple when include_source is True.

Example

1from signalwire import SWMLService
2
3service = SWMLService(name="my-service")
4
5# Get credentials
6username, password = service.get_basic_auth_credentials()
7print(f"Auth: {username}:{password}")
8
9# Get credentials with source information
10username, password, source = service.get_basic_auth_credentials(include_source=True)
11print(f"Auth source: {source}") # "environment" or "auto-generated"