basicAuth static method

Future<BasicAuth> basicAuth(
  1. String path, {
  2. String? section,
  3. String usernameKey = 'username',
  4. String passwordKey = 'password',
})

Load a JSON file and extract BasicAuth credentials.

Throws FileSecretsError if the file is missing, malformed, or the required keys are absent.

Implementation

static Future<BasicAuth> basicAuth(
  String path, {
  String? section,
  String usernameKey = 'username',
  String passwordKey = 'password',
}) async {
  final data = await _load(path, section);
  final username = data[usernameKey];
  final password = data[passwordKey];
  if (username == null || password == null) {
    throw FileSecretsError(
      'Missing "$usernameKey" or "$passwordKey" in ${_desc(path, section)}',
    );
  }
  return BasicAuth(username, password);
}