I am using Flutter and Dart in order to fetch Objects from my iCloud calendar through CalDAV protocol. I have already created an app-specific-password for my Apple account, indeed i am using that password in order to login, i am able to perform correctly every step inside the "Retrieving calendar information" section as shown in this guide, but i cannot proceed and fetch the objects as i am getting the error code 403.
The 403 Forbidden error indicates that the server understands the request but can't provide additional access.
This is the code i am currently using. I am not sure if i had to include the c-tag inside the request or not.
This is the official documentation of CalDAV.
Future<http.Response> fetchObjects() async {
final request = http.Request(
'REPORT',
Uri.parse('https://pXXX-caldav.icloud.com:XXX/3XX91XX0X/calendars'),
);
request.headers['Authorization'] =
'Basic ' + base64Encode(utf8.encode('$appleId:$password'));
request.headers['Depth'] = '1';
request.headers['Prefer'] = 'return-minimal';
request.headers['Content-Type'] = 'application/xml; charset=utf-8';
final body = '''
<c:calendar-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
<d:prop>
<d:getetag />
<c:calendar-data />
</d:prop>
<c:filter>
<c:comp-filter name="VCALENDAR" />
</c:filter>
</c:calendar-query>
''';
request.body = body;
final response = await request.send();
// Convert the StreamedResponse to a Response.
final convertedResponse = await response.stream.toBytes();
final parsedResponse =
http.Response.bytes(convertedResponse, response.statusCode);
print(parsedResponse.statusCode);
print(parsedResponse.body);
return parsedResponse;
}