Closed yazanIbrahim closed 4 years ago
I think you must set the authEndpoint correctly. It must point to your backend and will return an auth token for pusher. So if I understood it correctly it goes like
-> echo client -> detects private-channel -> client makes post request for authentication to your backend -> backend returns auth token to client -> client connects with token to pusher
Set authEndpoint to "https://your.domain.org/broadcasting/auth" or localhost or whatever you are using.
Hello am trying to authorise private channels as the plugin documentation says but i got this error
E/MethodChannel#com.github.heywhy/pusher( 5427): Failed to handle method call E/MethodChannel#com.github.heywhy/pusher( 5427): java.lang.IllegalStateException: Cannot subscribe to a private or presence channel because no Authorizer has been set. Call PusherOptions.setAuthorizer() before connecting to Pusher E/MethodChannel#com.github.heywhy/pusher( 5427): at com.pusher.client.Pusher.throwExceptionIfNoAuthorizerHasBeenSet(Pusher.java:341) E/MethodChannel#com.github.heywhy/pusher( 5427): at com.pusher.client.Pusher.subscribePrivate(Pusher.java:278) E/MethodChannel#com.github.heywhy/pusher( 5427): at com.github.heywhy.flutter_pusher.FlutterPusherPlugin.subscribe(FlutterPusherPlugin.java:258) E/MethodChannel#com.github.heywhy/pusher( 5427): at com.github.heywhy.flutter_pusher.FlutterPusherPlugin.onMethodCall(FlutterPusherPlugin.java:88) E/MethodChannel#com.github.heywhy/pusher( 5427): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:231) E/MethodChannel#com.github.heywhy/pusher( 5427): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:93) E/MethodChannel#com.github.heywhy/pusher( 5427): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:642) E/MethodChannel#com.github.heywhy/pusher( 5427): at android.os.MessageQueue.nativePollOnce(Native Method) E/MethodChannel#com.github.heywhy/pusher( 5427): at android.os.MessageQueue.next(MessageQueue.java:363) E/MethodChannel#com.github.heywhy/pusher( 5427): at android.os.Looper.loop(Looper.java:173) E/MethodChannel#com.github.heywhy/pusher( 5427): at android.app.ActivityThread.main(ActivityThread.java:8178) E/MethodChannel#com.github.heywhy/pusher( 5427): at java.lang.reflect.Method.invoke(Native Method) E/MethodChannel#com.github.heywhy/pusher( 5427): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) E/MethodChannel#com.github.heywhy/pusher( 5427): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101) D/FlutterPusherPlugin( 5427): bind exception: Attempt to invoke interface method 'void com.pusher.client.channel.Channel.bind(java.lang.String, com.pusher.client.channel.SubscriptionEventListener)' on a null object reference W/System.err( 5427): java.lang.NullPointerException: Attempt to invoke interface method 'void com.pusher.client.channel.Channel.bind(java.lang.String, com.pusher.client.channel.SubscriptionEventListener)' on a null object reference W/System.err( 5427): at com.github.heywhy.flutter_pusher.FlutterPusherPlugin.bind(FlutterPusherPlugin.java:304) W/System.err( 5427): at com.github.heywhy.flutter_pusher.FlutterPusherPlugin.onMethodCall(FlutterPusherPlugin.java:94) W/System.err( 5427): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:231) W/System.err( 5427): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:93) W/System.err( 5427): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:642) W/System.err( 5427): at android.os.MessageQueue.nativePollOnce(Native Method) W/System.err( 5427): at android.os.MessageQueue.next(MessageQueue.java:363) W/System.err( 5427): at android.os.Looper.loop(Looper.java:173) W/System.err( 5427): at android.app.ActivityThread.main(ActivityThread.java:8178) W/System.err( 5427): at java.lang.reflect.Method.invoke(Native Method) W/System.err( 5427): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) W/System.err( 5427): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101) E/flutter ( 5427): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(error, Cannot subscribe to a private or presence channel because no Authorizer has been set. Call PusherOptions.setAuthorizer() before connecting to Pusher, null) E/flutter ( 5427): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7) E/flutter ( 5427): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:321:33) E/flutter ( 5427): E/flutter ( 5427): #2 Channel._subscribe (package:flutter_pusher_client/flutter_pusher.dart:29:20) E/flutter ( 5427): #3 new Channel (package:flutter_pusher_client/flutter_pusher.dart:25:10) E/flutter ( 5427): #4 FlutterPusher.subscribe (package:flutter_pusher_client/flutter_pusher.dart:105:12) E/flutter ( 5427): #5 PusherChannel.subscribe (package:laravel_echo/src/channel/pusher-channel.dart:37:36) E/flutter ( 5427): #6 new PusherChannel (package:laravel_echo/src/channel/pusher-channel.dart:32:10) E/flutter ( 5427): #7 new PusherPrivateChannel (package:laravel_echo/src/channel/pusher-private-channel.dart:9:9) E/flutter ( 5427): #8 PusherConnector.privateChannel (package:laravel_echo/src/connector/pusher-connector.dart:48:44) E/flutter ( 5427): #9 Echo.private (package:laravel_echo/laravel_echo.dart:74:27) E/flutter ( 5427): #10 ChatThreadViewModel.init (package:books_hunter_app/view_models/ChatThreadViewModel.dart:59:10) E/flutter ( 5427): E/flutter ( 5427): #11 ChatThreadView.build. (package:books_hunter_app/views/main_views/ChatThreadView.dart:13:50) E/flutter ( 5427): #12 _BaseViewState.initState (package:books_hunter_app/views/view.dart) E/flutter ( 5427): #13 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4355:58) E/flutter ( 5427): #14 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5) E/flutter ( 5427): #15 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14) E/flutter ( 5427): #16 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12) E/flutter ( 5427): #17 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16) E/flutter ( 5427): #18 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5) E/flutter ( 5427): #19 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5) E/flutter ( 5427): #20 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5) E/flutter ( 5427): #21 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14) E/flutter ( 5427): #22 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12) E/flutter ( 5427): #23 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14) E/flutter ( 5427): #24 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14) E/flutter ( 5427): #25 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12) E/flutter ( 5427): #26 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16) E/flutter ( 5427): #27 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5) E/flutter ( 5427): #28 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5) E/flutter ( 5427): #29 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5) E/flutter ( 5427): #30 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14) E/flutter ( 5427): #31 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12) E/flutter ( 5427): #32 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14) E/flutter ( 5427): #33 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14) E/flutter ( 5427): #34 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12) E/flutter ( 5427): #35 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14) E/flutter ( 5427): #36 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14) E/flutter ( 5427): #37 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12) E/flutter ( 5427): #38 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16) E/flutter ( 5427): #39 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5) E/flutter ( 5427): #40 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5) E/flutter ( 5427): #41 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11) E/flutter ( 5427): #42 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5
and here is my code Echo echo = new Echo({ 'broadcaster': 'pusher', 'client': pusher, 'authEndpoint' : '/broadcasting/auth', 'auth': { 'headers': { 'Authorization': 'Bearer $token' } }
});
Please refer to the Readme.md. You are to set the authentication info on the pusher client directly.
Hi, where in the readme are you making reference to the auth with pusher. I'm trying to subscribe to a private channel and I can't get it.
I'm getting this error:
subscribe error: Cannot subscribe to a private or presence channel because no Authorizer has been set. Call PusherOptions.setAuthorizer() before connecting to Pusher
did you find soluation?
Hello am trying to authorise private channels as the plugin documentation says but i got this error
E/MethodChannel#com.github.heywhy/pusher( 5427): Failed to handle method call E/MethodChannel#com.github.heywhy/pusher( 5427): java.lang.IllegalStateException: Cannot subscribe to a private or presence channel because no Authorizer has been set. Call PusherOptions.setAuthorizer() before connecting to Pusher E/MethodChannel#com.github.heywhy/pusher( 5427): at com.pusher.client.Pusher.throwExceptionIfNoAuthorizerHasBeenSet(Pusher.java:341) E/MethodChannel#com.github.heywhy/pusher( 5427): at com.pusher.client.Pusher.subscribePrivate(Pusher.java:278) E/MethodChannel#com.github.heywhy/pusher( 5427): at com.github.heywhy.flutter_pusher.FlutterPusherPlugin.subscribe(FlutterPusherPlugin.java:258) E/MethodChannel#com.github.heywhy/pusher( 5427): at com.github.heywhy.flutter_pusher.FlutterPusherPlugin.onMethodCall(FlutterPusherPlugin.java:88) E/MethodChannel#com.github.heywhy/pusher( 5427): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:231) E/MethodChannel#com.github.heywhy/pusher( 5427): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:93) E/MethodChannel#com.github.heywhy/pusher( 5427): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:642) E/MethodChannel#com.github.heywhy/pusher( 5427): at android.os.MessageQueue.nativePollOnce(Native Method) E/MethodChannel#com.github.heywhy/pusher( 5427): at android.os.MessageQueue.next(MessageQueue.java:363) E/MethodChannel#com.github.heywhy/pusher( 5427): at android.os.Looper.loop(Looper.java:173) E/MethodChannel#com.github.heywhy/pusher( 5427): at android.app.ActivityThread.main(ActivityThread.java:8178) E/MethodChannel#com.github.heywhy/pusher( 5427): at java.lang.reflect.Method.invoke(Native Method) E/MethodChannel#com.github.heywhy/pusher( 5427): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) E/MethodChannel#com.github.heywhy/pusher( 5427): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101) D/FlutterPusherPlugin( 5427): bind exception: Attempt to invoke interface method 'void com.pusher.client.channel.Channel.bind(java.lang.String, com.pusher.client.channel.SubscriptionEventListener)' on a null object reference W/System.err( 5427): java.lang.NullPointerException: Attempt to invoke interface method 'void com.pusher.client.channel.Channel.bind(java.lang.String, com.pusher.client.channel.SubscriptionEventListener)' on a null object reference W/System.err( 5427): at com.github.heywhy.flutter_pusher.FlutterPusherPlugin.bind(FlutterPusherPlugin.java:304) W/System.err( 5427): at com.github.heywhy.flutter_pusher.FlutterPusherPlugin.onMethodCall(FlutterPusherPlugin.java:94) W/System.err( 5427): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:231) W/System.err( 5427): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:93) W/System.err( 5427): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:642) W/System.err( 5427): at android.os.MessageQueue.nativePollOnce(Native Method) W/System.err( 5427): at android.os.MessageQueue.next(MessageQueue.java:363) W/System.err( 5427): at android.os.Looper.loop(Looper.java:173) W/System.err( 5427): at android.app.ActivityThread.main(ActivityThread.java:8178) W/System.err( 5427): at java.lang.reflect.Method.invoke(Native Method) W/System.err( 5427): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) W/System.err( 5427): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101) E/flutter ( 5427): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(error, Cannot subscribe to a private or presence channel because no Authorizer has been set. Call PusherOptions.setAuthorizer() before connecting to Pusher, null) E/flutter ( 5427): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7) E/flutter ( 5427): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:321:33) E/flutter ( 5427):
E/flutter ( 5427): #2 Channel._subscribe (package:flutter_pusher_client/flutter_pusher.dart:29:20)
E/flutter ( 5427): #3 new Channel (package:flutter_pusher_client/flutter_pusher.dart:25:10)
E/flutter ( 5427): #4 FlutterPusher.subscribe (package:flutter_pusher_client/flutter_pusher.dart:105:12)
E/flutter ( 5427): #5 PusherChannel.subscribe (package:laravel_echo/src/channel/pusher-channel.dart:37:36)
E/flutter ( 5427): #6 new PusherChannel (package:laravel_echo/src/channel/pusher-channel.dart:32:10)
E/flutter ( 5427): #7 new PusherPrivateChannel (package:laravel_echo/src/channel/pusher-private-channel.dart:9:9)
E/flutter ( 5427): #8 PusherConnector.privateChannel (package:laravel_echo/src/connector/pusher-connector.dart:48:44)
E/flutter ( 5427): #9 Echo.private (package:laravel_echo/laravel_echo.dart:74:27)
E/flutter ( 5427): #10 ChatThreadViewModel.init (package:books_hunter_app/view_models/ChatThreadViewModel.dart:59:10)
E/flutter ( 5427):
E/flutter ( 5427): #11 ChatThreadView.build. (package:books_hunter_app/views/main_views/ChatThreadView.dart:13:50)
E/flutter ( 5427): #12 _BaseViewState.initState (package:books_hunter_app/views/view.dart)
E/flutter ( 5427): #13 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4355:58)
E/flutter ( 5427): #14 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
E/flutter ( 5427): #15 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 5427): #16 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
E/flutter ( 5427): #17 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
E/flutter ( 5427): #18 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
E/flutter ( 5427): #19 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
E/flutter ( 5427): #20 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
E/flutter ( 5427): #21 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 5427): #22 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
E/flutter ( 5427): #23 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
E/flutter ( 5427): #24 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 5427): #25 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
E/flutter ( 5427): #26 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
E/flutter ( 5427): #27 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
E/flutter ( 5427): #28 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
E/flutter ( 5427): #29 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
E/flutter ( 5427): #30 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 5427): #31 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
E/flutter ( 5427): #32 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
E/flutter ( 5427): #33 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 5427): #34 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
E/flutter ( 5427): #35 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
E/flutter ( 5427): #36 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 5427): #37 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
E/flutter ( 5427): #38 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
E/flutter ( 5427): #39 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
E/flutter ( 5427): #40 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
E/flutter ( 5427): #41 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
E/flutter ( 5427): #42 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5
and here is my code Echo echo = new Echo({ 'broadcaster': 'pusher', 'client': pusher, 'authEndpoint' : '/broadcasting/auth', 'auth': { 'headers': { 'Authorization': 'Bearer $token' } }