createRoomExternalOAuthRegistration method

Future<String> createRoomExternalOAuthRegistration({
  1. required String projectId,
  2. required String roomName,
  3. required OAuthClientConfig oauth,
  4. required String clientId,
  5. String? clientSecret,
  6. String? delegatedTo,
  7. ConnectorRef? connector,
})

Implementation

Future<String> createRoomExternalOAuthRegistration({
  required String projectId,
  required String roomName,
  required OAuthClientConfig oauth,
  required String clientId,
  String? clientSecret,
  String? delegatedTo,
  ConnectorRef? connector,
}) async {
  final encodedProjectId = Uri.encodeComponent(projectId);
  final encodedRoomName = Uri.encodeComponent(roomName);
  final uri = Uri.parse('$baseUrl/accounts/projects/$encodedProjectId/rooms/$encodedRoomName/external-oauth');
  final body = <String, dynamic>{
    'oauth': oauth.toJson(),
    'client_id': clientId,
    if (clientSecret != null) 'client_secret': clientSecret,
    if (delegatedTo != null) 'delegated_to': delegatedTo,
    if (connector != null) 'connector': connector.toJson(),
  };
  final response = await httpClient.post(uri, body: jsonEncode(body));

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

  return (jsonDecode(response.body) as Map<String, dynamic>)['id'] as String;
}