fromJSON static method

BasicCredential? fromJSON(
  1. dynamic json
)

Implementation

static BasicCredential? fromJSON(dynamic json) {
  if (json == null) return null;

  if (json is List) {
    if (json.length < 2) return null;
    var user = json[0];
    var pass = json[1];
    if (user is! String || pass is! String) return null;
    return BasicCredential(user, pass);
  } else if (json is Map) {
    if (json.length < 2) return null;

    var user = findKeyValue<dynamic, dynamic>(
        json, ['username', 'user', 'login', 'email', 'account'], true);
    var pass = findKeyValue<dynamic, dynamic>(
        json, ['password', 'pass', 'secret', 'token'], true);

    if (user is! String || pass is! String) return null;

    return BasicCredential(user, pass);
  } else if (json is String) {
    var parts = json.split(RegExp(r'[:;\s]+'));
    if (parts.length < 2) return null;
    return BasicCredential(parts[0], parts[1]);
  }
  return null;
}