parseSsoAccounts function

List<SsoAccountInfo> parseSsoAccounts(
  1. dynamic json
)

Reads the body of GET /api/auth/oauth/accounts.

Implementation

List<SsoAccountInfo> parseSsoAccounts(dynamic json) {
  final accounts = switch (json) {
    List<dynamic> list => list,
    Map<String, dynamic> map when map['accounts'] is List =>
      map['accounts'] as List<dynamic>,
    _ => throw FormatException(
      'Unexpected response from the SSO accounts endpoint',
    ),
  };

  return accounts
      .map(
        (account) =>
            SsoAccountInfo.fromJson(asJsonObject(account, 'An SSO account')),
      )
      .toList();
}