Authorization Bearer Access Token doesn't seem to work
I have a piece of code that passes in a bearer token
Map<String, String>? get authorizationHeader =>
{ 'Authorization': 'Bearer $accessToken' };
I get the token and I make this call, but I get a 401 error
CachedNetworkImage(
width: 48,
height: 48,
imageUrl: iconService.getRoomIconUrl(
roomId: item.room.id,
iconMetaData: item.room.iconMetaData,
),
httpHeaders: iconService.authorizationHeader,
)
I do the same for Image.network and it works just fine. Am I doing something wrong?
Image.network(
iconService.getRoomIconUrl(
roomId: item.room.id,
iconMetaData: item.room.iconMetaData,
),
headers: iconService.authorizationHeader,
)
I'm checking the console and I see it's not being passed

but in Image.network, it is being passed just fine

Going to close. I realized the tag says it does not support Web as I was testing on Web. Sorry about that
Hi,
I encounter the same issue running my project on Web platform.
Issue comes from the default image renderer for web : ImageRenderMethodForWeb.HtmlImage which ignores headers.
Workaround :
Using ImageRenderMethodForWeb.HttpGet fixes the issue :
import 'package:cached_network_image/cached_network_image.dart';
import 'package:cached_network_image_platform_interface/cached_network_image_platform_interface.dart';
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CachedNetworkImage(
imageRenderMethodForWeb: ImageRenderMethodForWeb.HttpGet,
fit: BoxFit.cover,
imageUrl:
'http://pngimg.com/uploads/simpsons/simpsons_PNG94.png',
httpHeaders: const {
'test_header': 'test value',
},
);
}
}
Same issue, tested on android