flutter_cached_network_image icon indicating copy to clipboard operation
flutter_cached_network_image copied to clipboard

Authorization Bearer Access Token doesn't seem to work

Open WillComesBack opened this issue 2 years ago • 4 comments

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,
)

WillComesBack avatar Feb 07 '23 02:02 WillComesBack

I'm checking the console and I see it's not being passed image

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

WillComesBack avatar Feb 07 '23 02:02 WillComesBack

Going to close. I realized the tag says it does not support Web as I was testing on Web. Sorry about that

WillComesBack avatar Feb 08 '23 03:02 WillComesBack

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',
      },
    );
  }
}

Chralu avatar Aug 20 '24 09:08 Chralu

Same issue, tested on android

Joyker avatar Sep 03 '24 10:09 Joyker