authorize method
Implementation
@override
Future<AuthCallbackResponse> authorize(AuthCallbackRequest request) async {
final extraHeaders = await (headerProvider?.call() ??
Future.value(const <String, String>{}));
final body = jsonEncode({
'socket_id': request.socketId,
'channel_name': request.channelName,
});
final outgoing = http.Request('POST', _endpoint)
..headers.addAll({'content-type': 'application/json', ...extraHeaders})
..body = body;
final response = await _client.send(outgoing);
final responseBody = await _readBoundedBody(response);
if (response.statusCode < 200 || response.statusCode >= 300) {
throw StateError(
'auth callback rejected subscription (HTTP ${response.statusCode})');
}
final decoded = jsonDecode(responseBody);
if (decoded is! Map<String, dynamic> || decoded['auth'] is! String) {
throw StateError('auth callback returned a malformed response');
}
final channelData = decoded['channel_data'];
return AuthCallbackResponse(
auth: decoded['auth'] as String,
channelData: channelData is String ? channelData : null,
);
}