BasicCredential.base64 constructor

BasicCredential.base64(
  1. String base64
)

Instantiate using a base64 encoded credential, in format $username:$password.

Implementation

factory BasicCredential.base64(String base64) {
  var decodedBytes = Base64Codec.urlSafe().decode(base64);

  String decoded;
  try {
    decoded = utf8.decode(decodedBytes);
  } catch (_) {
    decoded = latin1.decode(decodedBytes);
  }

  var idx = decoded.indexOf(':');

  if (idx < 0) {
    return BasicCredential(decoded, '');
  }

  var user = decoded.substring(0, idx);
  var pass = decoded.substring(idx + 1);

  return BasicCredential(user, pass);
}