pusher_client icon indicating copy to clipboard operation
pusher_client copied to clipboard

cant't change PusherAuth

Open cjo4m06 opened this issue 4 years ago • 7 comments

My application uses JWT Token, and it’s only valid for five minutes.

But now I cannot change the Auth setting of Pusher

cjo4m06 avatar Feb 20 '21 05:02 cjo4m06

Hello. I have the same problem. My app to changes token after every login. I should change auth token after re-login app. But now I have exception when subscribe to private channel again. I think pusherClient or channel instance still save old pusher connect. @chinloyal please help

E/PusherClientPlugin(13836): java.io.FileNotFoundException: https://<url>/pusher/auth W/System.err(13836): com.pusher.client.AuthorizationFailureException: java.io.FileNotFoundException: https://<url>pusher/auth W/System.err(13836): at com.pusher.client.util.HttpAuthorizer.authorize(HttpAuthorizer.java:146) W/System.err(13836): at com.pusher.client.channel.impl.PrivateChannelImpl.getAuthResponse(PrivateChannelImpl.java:130) W/System.err(13836): at com.pusher.client.channel.impl.PrivateChannelImpl.toSubscribeMessage(PrivateChannelImpl.java:90) W/System.err(13836): at com.pusher.client.channel.impl.ChannelManager$1.run(ChannelManager.java:149) W/System.err(13836): at com.pusher.client.util.Factory$1.run(Factory.java:119) W/System.err(13836): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) W/System.err(13836): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) W/System.err(13836): at java.lang.Thread.run(Thread.java:923) W/System.err(13836): Caused by: java.io.FileNotFoundException: https://<url>/pusher/auth W/System.err(13836): at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:255) W/System.err(13836): at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:211) W/System.err(13836): at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:30) W/System.err(13836): at com.pusher.client.util.HttpAuthorizer.authorize(HttpAuthorizer.java:128) W/System.err(13836): ... 7 more E/PusherClientPlugin(13836): java.io.FileNotFoundException: https://<url>/pusher/auth W/System.err(13836): com.pusher.client.AuthorizationFailureException: java.io.FileNotFoundException: https://<url>/pusher/auth W/System.err(13836): at com.pusher.client.util.HttpAuthorizer.authorize(HttpAuthorizer.java:146) W/System.err(13836): at com.pusher.client.channel.impl.PrivateChannelImpl.getAuthResponse(PrivateChannelImpl.java:130) W/System.err(13836): at com.pusher.client.channel.impl.PrivateChannelImpl.toSubscribeMessage(PrivateChannelImpl.java:90) W/System.err(13836): at com.pusher.client.channel.impl.ChannelManager$1.run(ChannelManager.java:149) W/System.err(13836): at com.pusher.client.util.Factory$1.run(Factory.java:119) W/System.err(13836): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) W/System.err(13836): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) W/System.err(13836): at java.lang.Thread.run(Thread.java:923) W/System.err(13836): Caused by: java.io.FileNotFoundException: https://<url>/pusher/auth W/System.err(13836): at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:255) W/System.err(13836): at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:211) W/System.err(13836): at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:30) W/System.err(13836): at com.pusher.client.util.HttpAuthorizer.authorize(HttpAuthorizer.java:128) @chinloyal

boolkaco avatar Mar 30 '21 20:03 boolkaco

I am having the same problem in my Flutter app. @chinloyal

ZigaZumer avatar May 21 '21 11:05 ZigaZumer

Did anyone solve this issue?

jeghedderchristoffer avatar Jun 07 '21 05:06 jeghedderchristoffer

I was able to resolve this issue, and if anybody needs a version that allows you to change PusherAuth on new login etc. you can use my fork of this repo (its null-safety): https://github.com/jeghedderchristoffer/pusher_client. I do not think this library is maintained anymore so forking is your best opportunity. Cheers!

jeghedderchristoffer avatar Jun 07 '21 07:06 jeghedderchristoffer

@cjo4m06 Maybe I'm misinterpreting what you're saying but you can set the auth on PushOptions object using a PusherAuth object

chinloyal avatar Aug 13 '21 08:08 chinloyal

@chinloyal Please check this.

PusherOptions options = PusherOptions(
      host: AppConstants.PUSHER_HOST,
      wssPort: AppConstants.PUSHER_WSS_PORT,
      encrypted: true,
      auth: PusherAuth(
        AppConstants.API_BASE_URL + _authUrl,
        headers: {
          'Content-type': 'application/json',
          'Authorization':
              'Bearer ${_box.read(AppConstants.TOKEN_KEY) ?? null}',
          'Device-Info': deviceInfo,
        },
      ),
    );

Now when the token changes, PusherAuth isn't picking up the new token. It still uses the old token and the connection keeps failing. I hope this explanation will help you in debugging.

abinvp avatar Sep 13 '21 21:09 abinvp

I have the same issue. I Have to close the app and restart it before it works but it is not a good experience for final users.

kuatek avatar Dec 04 '21 17:12 kuatek