parseSsoProviders function

List<SsoProviderInfo> parseSsoProviders(
  1. dynamic json
)

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

Accepts both shapes the API may use - {"providers": [...]} and a bare array - and throws on anything else rather than reporting "no providers", which would silently hide every sign-in button.

Implementation

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

  return providers
      .map(
        (provider) =>
            SsoProviderInfo.fromJson(asJsonObject(provider, 'An SSO provider')),
      )
      .toList();
}