chinloyal / pusher_client

A Pusher Channels Client for Fluttter (Fully supports Android and iOS)
https://pusher.com/channels
MIT License
42 stars 173 forks source link

com.pusher.client.AuthorizationFailureException: java.io.FileNotFoundException: #25

Open godwintrav opened 3 years ago

godwintrav commented 3 years ago

Hello I'm trying to authorize my pusher client but I keep getting this error: com.pusher.client.AuthorizationFailureException: java.io.FileNotFoundException: http://167.99.214.205/api/v1/broadcasting/auth.

Please what can I do?

chinloyal commented 3 years ago

Can you share your pusher configuration?

Djihanegh commented 2 years ago

I have the same problem

Here's my Pusher config :

static PusherClient? pusher;
static Channel? channel;

static Future<void> initPusher(String token, int userId) async {
 PusherOptions options = new PusherOptions(
      cluster: 'eu',
      auth: new PusherAuth(
        'https://url',
        headers: {
          'authentication': '$token',
        },
      ),
    );

    try {
      pusher = new PusherClient("APP_KEY", options,
          enableLogging: true, autoConnect: false);

        pusher?.connect();

     channel = pusher?.subscribe("private-user" + '$userId');

}catch(e) {
}

After hours of debugging i managed that the pusher client is sending the previous token to the server. (This error only happens when i connect with another account, if it was my first login everything is fine, but then the pusher sends the previous token rather than the new one if i use my second account)

roiskhoiron commented 2 years ago

I have the same problem

Here's my Pusher config :

static PusherClient? pusher;
static Channel? channel;

static Future<void> initPusher(String token, int userId) async {
 PusherOptions options = new PusherOptions(
      cluster: 'eu',
      auth: new PusherAuth(
        'https://url',
        headers: {
          'authentication': '$token',
        },
      ),
    );

    try {
      pusher = new PusherClient("APP_KEY", options,
          enableLogging: true, autoConnect: false);

        pusher?.connect();

     channel = pusher?.subscribe("private-user" + '$userId');

}catch(e) {
}

After hours of debugging i managed that the pusher client is sending the previous token to the server. (This error only happens when i connect with another account, if it was my first login everything is fine, but then the pusher sends the previous token rather than the new one if i use my second account)

I have the same problem

yenyichau commented 2 years ago

Do we have any solution on this problem?

roiskhoiron commented 2 years ago

Do we have any solution on this problem?

i suggest socket_io_client_2

yenyichau commented 2 years ago

Do we have any solution on this problem?

i suggest socket_io_client_2

Is it socket_io_client? I can't find socket_io_client_2

roiskhoiron commented 2 years ago

Do we have any solution on this problem?

i suggest socket_io_client_2

Is it socket_io_client? I can't find socket_io_client_2

socket_io_client: ^2.0.0-beta.4-nullsafety.0

yenyichau commented 2 years ago

Do we have any solution on this problem?

i suggest socket_io_client_2

Is it socket_io_client? I can't find socket_io_client_2

socket_io_client: ^2.0.0-beta.4-nullsafety.0

ok thanks

MajedDH commented 1 year ago

I'm having exactly the same problem. we're making a new instance of pusher client and giving it new options with new authentication token but still the client is sending the previous token (although the rest of the data is up to date, only the token is being persisted some how.) I think that's a problem of cached headers...

Anyone solved the issue?

Djihanegh commented 1 year ago

I'm having exactly the same problem. we're making a new instance of pusher client and giving it new options with new authentication token but still the client is sending the previous token (although the rest of the data is up to date, only the token is being persisted some how.) I think that's a problem of cached headers...

Anyone solved the issue?

This may solve your problem , the commit 32ec432. The pull request is opened here

vw5921321 commented 3 months ago

pusherclient has an instance stored in native code, even if you make a new instance of pusherclient, the native code still does null check on the native pusherclient instance.

to fix this, first change lib/src/pusher/pusher_client.dart to not reuse the same instance. i've commented out the part that needs to be replaced.

  //   String appKey,
  //   PusherOptions options, {
  //   bool enableLogging = true,
  //   bool autoConnect = true,
  // });

  /// Creates a [PusherClient] -- returns the instance if it's already be called.
  // factory PusherClient(
  //   String appKey,
  //   PusherOptions options, {
  //   bool enableLogging = true,
  //   bool autoConnect = true,
  // }) {
  //   // _singleton ??= PusherClient._(
  //   //   appKey,
  //   //   options,
  //   //   enableLogging: enableLogging,
  //   //   autoConnect: autoConnect,
  //   // );
  //
  //   final initArgs = InitArgs(enableLogging: enableLogging);
  //
  //   _singleton!._init(appKey, options, initArgs);
  //
  //   if (autoConnect) _singleton!.connect();
  //
  //   return _singleton!;
  // }

  PusherClient(
      String appKey,
      PusherOptions options, {
        bool enableLogging = true,
        bool autoConnect = true,
      }) {
    // Create a new instance directly inside the constructor
    final initArgs = InitArgs(enableLogging: enableLogging);
    _init(appKey, options, initArgs);

    if (autoConnect) connect();
  }

then modify the native init func to not null check the native pusherclient instance.

for android, remove this from android/src.main/kotlin.com.github.chinloyal.pusher/pusher/PusherService.kt if(_pusherInstance == null) {

for ios, remove this from ios/Classes/PusherService.swift if(_pusherInstance == nil) {