listRoomExternalOAuthRegistrations method

Future<List<ExternalOAuthClientRegistration>> listRoomExternalOAuthRegistrations({
  1. required String projectId,
  2. required String roomName,
  3. String? delegatedTo,
})

Implementation

Future<List<ExternalOAuthClientRegistration>> listRoomExternalOAuthRegistrations({
  required String projectId,
  required String roomName,
  String? delegatedTo,
}) async {
  final encodedProjectId = Uri.encodeComponent(projectId);
  final encodedRoomName = Uri.encodeComponent(roomName);
  final query = <String, String>{};
  if (delegatedTo != null) query['delegated_to'] = delegatedTo;
  final uri = Uri.parse(
    '$baseUrl/accounts/projects/$encodedProjectId/rooms/$encodedRoomName/external-oauth',
  ).replace(queryParameters: query.isEmpty ? null : query);
  final response = await httpClient.get(uri);

  if (response.statusCode >= 400) {
    throw MeshagentException(
      'Failed to list room external oauth registrations. '
      'Status code: ${response.statusCode}, body: ${response.body}',
    );
  }

  final decoded = jsonDecode(response.body) as Map<String, dynamic>;
  final registrations = decoded['registrations'] as List<dynamic>? ?? const [];
  return registrations.whereType<Map<String, dynamic>>().map(ExternalOAuthClientRegistration.fromJson).toList();
}