Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AuthCallback error: java.lang.Exception: Invalid authCallback response on Flutter Android #121

Closed
raniel05 opened this issue May 18, 2021 · 4 comments
Labels
bug Something isn't working. It's clear that this does need to be fixed.

Comments

@raniel05
Copy link

raniel05 commented May 18, 2021

I am getting my TokenRequest via authCallback but I am getting an Error only on Android. iOS has no problem and it is working properly.

 var clientOptions = ably.ClientOptions()
      ..clientId = _clientId
      ..autoConnect = false
      ..authCallback = (ably.TokenParams tokenParams) async {
        try {
          final tokenRequestMap = await fetchRTSToken();
          setState(() {
            _clientId = tokenRequestMap['clientId'];
          });
          return ably.TokenRequest.fromMap(tokenRequestMap);
        } catch (e) {
          print("ERROR: $e");
        }
      };
    try {
      realtimeInstance = new ably.Realtime(options: clientOptions);
      realtimeInstance.connect();

Debug Log:

I/System.out( 4385): Ably Plugin handle: connectRealtime
I/System.out( 4385): (INFO): Auth.assertValidToken():
I/System.out( 4385): (INFO): Auth.assertValidToken(): requesting new token
I/System.out( 4385): (INFO): Auth.requestToken(): using token auth with auth_callback
I/System.out( 4385): (INFO): TokenAuth.setTokenDetails():
I/System.out( 4385): (ERROR): io.ably.lib.transport.WebSocketTransport: Unexpected exception attempting connection; wsUri = wss://realtime.ably.io:443/
I/System.out( 4385): io.ably.lib.types.AblyException: java.lang.Exception: Unable to set different clientId from that given in options
I/System.out( 4385): at io.ably.lib.rest.Auth.setClientId(Auth.java:1040)
I/System.out( 4385): at io.ably.lib.rest.Auth.setTokenDetails(Auth.java:934)
I/System.out( 4385): at io.ably.lib.rest.Auth.assertValidToken(Auth.java:963)
I/System.out( 4385): at io.ably.lib.rest.Auth.assertValidToken(Auth.java:947)
I/System.out( 4385): at io.ably.lib.rest.Auth.getAuthParams(Auth.java:812)
I/System.out( 4385): at io.ably.lib.transport.WebSocketTransport.connect(WebSocketTransport.java:65)
I/System.out( 4385): at io.ably.lib.transport.ConnectionManager.connectImpl(ConnectionManager.java:1321)
I/System.out( 4385): at io.ably.lib.transport.ConnectionManager.access$400(ConnectionManager.java:21)
I/System.out( 4385): at io.ably.lib.transport.ConnectionManager$Connecting.enact(ConnectionManager.java:207)
I/System.out( 4385): at io.ably.lib.transport.ConnectionManager$StateChangeAction.enactState(ConnectionManager.java:523)
I/System.out( 4385): at io.ably.lib.transport.ConnectionManager$AsynchronousStateChangeAction.run(ConnectionManager.java:567)
I/System.out( 4385): at io.ably.lib.transport.ConnectionManager$ActionHandler.run(ConnectionManager.java:677)
I/System.out( 4385): at java.lang.Thread.run(Thread.java:923)
I/System.out( 4385): Caused by: java.lang.Exception: Unable to set different clientId from that given in options
I/System.out( 4385): ... 13 more
I/System.out( 4385): (ERROR): io.ably.lib.transport.ConnectionManager: onTransportUnavailable: unexpected transport error: Unable to set different clientId from that given in options <

┆Issue is synchronized with this Jira Bug by Unito

@ben-xD
Copy link
Contributor

ben-xD commented May 18, 2021

Hi @raniel05

The important error message here is:

io.ably.lib.types.AblyException: java.lang.Exception: Unable to set different clientId from that given in options.

This indicates that you first set the Ably client with a clientId, and then in the authCallback you try to change it. This won't work, because the Ably client doesn't allow changing the clientId after specifying it initially. Your server which provides the token request should respect the clientId that was given to it, which is given to authCallback in the tokenParams. Therefore there is no need to call setState either.

Note: In the future, we may allow you to not specify clientId in the ClientOptions at all, and clientId will automatically be taken from the TokenRequest returned by your server. This is an open issue, this auth token demo seems to be simplest implementation we can do. However, you still have to respect this clientId in the tokenParams argument, because the authCallback is called whenever the token needs to be renewed, not just when it first needs to be created. This would allow us to conform to RSA7b2 in the features spec.

I am now trying to get past a different error which you might face after you fix yours:

2021-05-18 10:02:33.643 9153-9205/com.example.ably_flutter_demo I/System.out: (ERROR): io.ably.lib.transport.WebSocketTransport: Unexpected exception attempting connection; wsUri = wss://realtime.ably.io:443/
2021-05-18 10:02:33.646 9153-9205/com.example.ably_flutter_demo I/System.out: io.ably.lib.types.AblyException: io.ably.lib.types.AblyException: java.lang.Exception: Invalid authCallback response

Hoping to get a fix for you asap :)

@raniel05
Copy link
Author

raniel05 commented May 18, 2021

Okay I get it now. But yeah that different error occurs also to me, even after unspecifying the clientId. Hopefully a fix soon. Thank you :)

@ben-xD
Copy link
Contributor

ben-xD commented May 18, 2021

Temporary solution:

It looks like you can actually ignore this error for now, because I've got my auth example app (Android and iOS) connecting to the same channel and displaying all the clientIds in the channel, as shown below, regardless of this error happening on Android. I've updated the example, the network/ authCallback code doesn't change much, I made it a little clearer.

Screenshot 2021-05-18 at 13 42 28

Errors still exists:

The logs are quite long/ full of errors however, so I think we should work on fixing this (cc: @tiholic , @QuintinWillison):

I/System.out(15873): Ably Plugin handle: registerAbly
I/System.out(15873): Registering library instance to clean up any existing instances
I/System.out(15873): Ably Plugin handle: createRealtimeWithOptions
I/System.out(15873): (INFO): io.ably.lib.realtime.AblyRealtime: started
I/System.out(15873): (INFO): Auth(): using token auth with authCallback
I/System.out(15873): Ably Plugin handle: connectRealtime
I/System.out(15873): (INFO): Auth.assertValidToken(): 
I/System.out(15873): (INFO): Auth.assertValidToken(): requesting new token
I/flutter (15873): Ably Platform Object 1
I/System.out(15873): (INFO): Auth.requestToken(): using token auth with auth_callback
I/System.out(15873): (ERROR): io.ably.lib.transport.WebSocketTransport: Unexpected exception attempting connection; wsUri = wss://realtime.ably.io:443/
I/System.out(15873): io.ably.lib.types.AblyException: io.ably.lib.types.AblyException: java.lang.Exception: Invalid authCallback response
I/System.out(15873): 	at io.ably.lib.rest.Auth.requestToken(Auth.java:591)
I/System.out(15873): 	at io.ably.lib.rest.Auth.assertValidToken(Auth.java:963)
I/System.out(15873): 	at io.ably.lib.rest.Auth.assertValidToken(Auth.java:947)
I/System.out(15873): 	at io.ably.lib.rest.Auth.getAuthParams(Auth.java:812)
I/System.out(15873): 	at io.ably.lib.transport.WebSocketTransport.connect(WebSocketTransport.java:65)
I/System.out(15873): 	at io.ably.lib.transport.ConnectionManager.connectImpl(ConnectionManager.java:1321)
I/System.out(15873): 	at io.ably.lib.transport.ConnectionManager.access$400(ConnectionManager.java:21)
I/System.out(15873): 	at io.ably.lib.transport.ConnectionManager$Connecting.enact(ConnectionManager.java:207)
I/System.out(15873): 	at io.ably.lib.transport.ConnectionManager$StateChangeAction.enactState(ConnectionManager.java:523)
I/System.out(15873): 	at io.ably.lib.transport.ConnectionManager$AsynchronousStateChangeAction.run(ConnectionManager.java:567)
I/System.out(15873): 	at io.ably.lib.transport.ConnectionManager$ActionHandler.run(ConnectionManager.java:677)
I/System.out(15873): 	at java.lang.Thread.run(Thread.java:764)
I/System.out(15873): Caused by: io.ably.lib.types.AblyException: java.lang.Exception: Invalid authCallback response
I/System.out(15873): 	at io.ably.lib.rest.Auth.requestToken(Auth.java:589)
I/System.out(15873): 	... 11 more
I/System.out(15873): Caused by: java.lang.Exception: Invalid authCallback response
I/System.out(15873): 	... 12 more
I/flutter (15873): {keyName: trbEaQ.5b3nkg, clientId: 9811c6db-20db-454a-9470-1e02e749c08c, timestamp: 1621341878049, nonce: 7042912302761102, mac: d6ywMOxV1IyDSkOCe/4RfPjifb36AHDKvFN5e22CZxg=}
I/System.out(15873): Ably Plugin handle: connectRealtime
I/System.out(15873): (INFO): Auth.assertValidToken(): 
I/System.out(15873): (INFO): Auth.assertValidToken(): requesting new token
I/System.out(15873): (INFO): Auth.requestToken(): using token auth with auth_callback
W/System  (15873): ClassLoader referenced unknown path: system/framework/mediatek-cta.jar
I/System.out(15873): e:java.lang.ClassNotFoundException: com.mediatek.cta.CtaHttp
W/System  (15873): ClassLoader referenced unknown path: system/framework/mediatek-cta.jar
I/System.out(15873): e:java.lang.ClassNotFoundException: com.mediatek.cta.CtaHttp
I/System.out(15873): Check isMmsSendPdu
W/System  (15873): ClassLoader referenced unknown path: system/framework/mediatek-cta.jar
I/System.out(15873): [OkHttp] sendRequest<<
I/System.out(15873): (INFO): TokenAuth.setTokenDetails(): 
I/System.out(15873): (INFO): TokenAuth.getTokenDetails(): 
W/System.err(15873): SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
W/System.err(15873): SLF4J: Defaulting to no-operation (NOP) logger implementation
W/System.err(15873): SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
W/System  (15873): ClassLoader referenced unknown path: system/framework/mediatek-cta.jar
I/System.out(15873): e:java.lang.ClassNotFoundException: com.mediatek.cta.CtaHttp

@ably-sync-bot ably-sync-bot changed the title AuthCallback error on android AuthCallback error on Flutter Android May 24, 2021
@ben-xD ben-xD added the bug Something isn't working. It's clear that this does need to be fixed. label Jun 7, 2021
@ben-xD ben-xD changed the title AuthCallback error on Flutter Android AuthCallback error: java.lang.Exception: Invalid authCallback response on Flutter Android Jun 7, 2021
@ben-xD
Copy link
Contributor

ben-xD commented Oct 27, 2021

This was fixed by #164

@ben-xD ben-xD closed this as completed Oct 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working. It's clear that this does need to be fixed.
Development

No branches or pull requests

2 participants