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

Publishing messages with authCallback is broken after upgrading from 1.1.16 to 1.2.1 #1074

Closed
tiholic opened this issue Oct 6, 2020 · 4 comments
Assignees

Comments

@tiholic
Copy link

tiholic commented Oct 6, 2020

Ably SDK Version: 1.2.1
iOS: iOS13.6, simulator
Cocoapods: 1.9.3
Xcode: 11.6, Build version 11E708

Unable to publish messages with authCallback enabled. Shared logs from 2 scenarios for better understanding.

  1. This scenario is based on authCallback, for publishing one message(same as above) by acquiring TokenRequest json form https://www.ably.io/ably-auth/token-request/demos

As far as I remember, this used to work well before upgrade

2020-10-03 12:11:01.025098+0530 Runner[92073:745806] flutter: Sending rest message
2020-10-03 12:11:01.026661+0530 Runner[92073:745566] AblyFlutterPlugin.m:327 publish(AblyFlutterMessage)
2020-10-03 12:11:01.027102+0530 Runner[92073:751706] VERBOSE: RS:0x600001cd8d80 ARTJsonLikeEncoder<msgpack>: messageToDictionary {
    clientId = "*";
    data = "Flutter 1";
    name = Hello;
}
2020-10-03 12:11:01.028955+0530 Runner[92073:751706] DEBUG: RS:0x600001cd8d80 ARTJsonLikeEncoder<msgpack> encoding '{
    clientId = "*";
    data = "Flutter 1";
    name = Hello;
}'; got: {length = 38, bytes = 0x83a46e61 6d65a548 656c6c6f a8636c69 ... 6c757474 65722031 }
2020-10-03 12:11:01.030651+0530 Runner[92073:751706] DEBUG: (ARTRestChannel.m:332) RS:0x600001cd8d80 C:0x600000aef1e0 (test) post message (null)
2020-10-03 12:11:01.033253+0530 Runner[92073:751706] DEBUG: (ARTRest.m:286) RS:0x600001cd8d80 calculating authorization 1
2020-10-03 12:11:01.035479+0530 Runner[92073:751706] VERBOSE: RS:0x600001cd8d80 ARTRestInternal reusing token: authorization bearer in Base64 Bearer STJFX0pRLkRCUklTOTRQdGQzNWlLRmRlZTB1bzEwSFpqZ09sZC01NEQtSXc1dU03dGt6NUo5RmdHc1c2bkktN1RwUU40YXhFekl1UGRiRE90bXJTSkNqUkpaOFBUdi12UkR5MllPSEp3OGpjUFhmMWVtanNUc1Vnd1FGUEMxeXkzNTVobnBKYw==
2020-10-03 12:11:01.037713+0530 Runner[92073:751706] DEBUG: (ARTRest.m:341) RS:0x600001cd8d80 executing request <NSMutableURLRequest: 0x600002cd6370> { URL: https://rest.ably.io:443/channels/test/messages? }
2020-10-03 12:11:01.040171+0530 Runner[92073:751706] DEBUG: POST https://rest.ably.io:443/channels/test/messages?
2020-10-03 12:11:01.042147+0530 Runner[92073:751706] VERBOSE: Headers {
    Accept = "application/x-msgpack,application/json";
    Authorization = "Bearer STJFX0pRLkRCUklTOTRQdGQzNWlLRmRlZTB1bzEwSFpqZ09sZC01NEQtSXc1dU03dGt6NUo5RmdHc1c2bkktN1RwUU40YXhFekl1UGRiRE90bXJTSkNqUkpaOFBUdi12UkR5MllPSEp3OGpjUFhmMWVtanNUc1Vnd1FGUEMxeXkzNTVobnBKYw==";
    "Content-Type" = "application/x-msgpack";
    "X-Ably-Lib" = "cocoa.ios-1.2.1";
    "X-Ably-Version" = "1.1";
}
2020-10-03 12:11:01.115300+0530 Runner[92073:751727] DEBUG: POST https://rest.ably.io:443/channels/test/messages?: statusCode 400
2020-10-03 12:11:01.117460+0530 Runner[92073:751727] VERBOSE: Headers {
    "Access-Control-Allow-Origin" = "*";
    "Content-Length" = 288;
    "Content-Type" = "application/json";
    Date = "Sat, 03 Oct 2020 06:41:01 GMT";
    Vary = Origin;
    Via = "1.1 8ce6c1082025b646a9044f0ebd185723.cloudfront.net (CloudFront)";
    "access-control-allow-credentials" = true;
    "access-control-expose-headers" = "Link,Transfer-Encoding,Content-Length,X-Ably-ErrorCode,X-Ably-ErrorMessage,X-Ably-ServerId,Server";
    "x-ably-errorcode" = 40012;
    "x-ably-errormessage" = "Malformed message; invalid clientId. (See https://help.ably.io/error/40012 for help.)";
    "x-ably-serverid" = "frontend.30a9.2.ap-southeast-1-A.i-0d88057852da824bd.a2dRQBgFAApzRc";
    "x-amz-cf-id" = "MR_XZX06oPseRtMfsWfr536Sf19gyTIREH35yJ7XcTwcptZ9NpMw5A==";
    "x-amz-cf-pop" = "HYD50-C2";
    "x-cache" = "Error from cloudfront";
}
2020-10-03 12:11:01.121106+0530 Runner[92073:751727] WARN: Malformed message; invalid clientId. (See https://help.ably.io/error/40012 for help.)
2020-10-03 12:11:01.123197+0530 Runner[92073:751727] DEBUG: RS:0x600001cd8d80 ARTJsonLikeEncoder<json> decoding '{length = 288, bytes = 0x7b0a0922 6572726f 72223a20 7b0a0909 ... 5263220a 097d0a7d }'; got: {
    error =     {
        code = 40012;
        href = "https://help.ably.io/error/40012";
        message = "Malformed message; invalid clientId. (See https://help.ably.io/error/40012 for help.)";
        serverId = "frontend.30a9.2.ap-southeast-1-A.i-0d88057852da824bd.a2dRQBgFAApzRc";
        statusCode = 400;
    };
}
2020-10-03 12:11:01.128831+0530 Runner[92073:745806] flutter: Rest message sending failed:: AblyException: Unable to publish message to Ably server; err = Malformed message; invalid clientId. (See https://help.ably.io/error/40012 for help.) (40012 ) :: ErrorInfo message=Malformed message; invalid clientId. (See https://help.ably.io/error/40012 for help.) code=null statusCode=400 href=null
  1. Below are logs of a regular scenario for publishing one message with an AppKey from ably web console. This works well even now. ✅
2020-10-03 12:02:20.252363+0530 Runner[91577:742827] flutter: Sending rest message
2020-10-03 12:02:20.253795+0530 Runner[91577:742600] AblyFlutterPlugin.m:327 publish(AblyFlutterMessage)
2020-10-03 12:02:20.254230+0530 Runner[91577:743204] VERBOSE: RS:0x6000031cf330 ARTJsonLikeEncoder<msgpack>: messageToDictionary {
    data = "Flutter 1";
    name = Hello;
}
2020-10-03 12:02:20.256361+0530 Runner[91577:743204] DEBUG: RS:0x6000031cf330 ARTJsonLikeEncoder<msgpack> encoding '{
    data = "Flutter 1";
    name = Hello;
}'; got: {length = 27, bytes = 0x82a46e61 6d65a548 656c6c6f a4646174 ... 6c757474 65722031 }
2020-10-03 12:02:20.258187+0530 Runner[91577:743204] DEBUG: (ARTRestChannel.m:332) RS:0x6000031cf330 C:0x6000027f9560 (test) post message (null)
2020-10-03 12:02:20.260350+0530 Runner[91577:743204] DEBUG: (ARTRest.m:286) RS:0x6000031cf330 calculating authorization 0
2020-10-03 12:02:20.262461+0530 Runner[91577:743204] VERBOSE: RS:0x6000031cf330 ARTRest: Basic ZEJqQlJnLkZxVzRHQTo2OHhfaWJnSm55Q2ViRFVF
2020-10-03 12:02:20.266292+0530 Runner[91577:743204] DEBUG: (ARTRest.m:341) RS:0x6000031cf330 executing request <NSMutableURLRequest: 0x6000001fc130> { URL: https://rest.ably.io:443/channels/test/messages? }
2020-10-03 12:02:20.269178+0530 Runner[91577:743204] DEBUG: POST https://rest.ably.io:443/channels/test/messages?
2020-10-03 12:02:20.271531+0530 Runner[91577:743204] VERBOSE: Headers {
    Accept = "application/x-msgpack,application/json";
    Authorization = "Basic ZEJqQlJnLkZxVzRHQTo2OHhfaWJnSm55Q2ViRFVF";
    "Content-Type" = "application/x-msgpack";
    "X-Ably-Lib" = "cocoa.ios-1.2.1";
    "X-Ably-Version" = "1.1";
}
2020-10-03 12:02:20.369799+0530 Runner[91577:743433] DEBUG: POST https://rest.ably.io:443/channels/test/messages?: statusCode 201
2020-10-03 12:02:20.371978+0530 Runner[91577:743433] VERBOSE: Headers {
    "Access-Control-Allow-Origin" = "*";
    "Content-Length" = 37;
    "Content-Type" = "application/x-msgpack";
    Date = "Sat, 03 Oct 2020 06:32:20 GMT";
    Vary = Origin;
    Via = "1.1 e37f5a1ae470dcb726258db2701f5a4e.cloudfront.net (CloudFront)";
    "access-control-allow-credentials" = true;
    "access-control-expose-headers" = "Link,Transfer-Encoding,Content-Length,X-Ably-ErrorCode,X-Ably-ErrorMessage,X-Ably-ServerId,Server";
    "x-ably-serverid" = "frontend.d488.2.ap-southeast-1-A.i-034eda59464148a38.a2daXHOJwApydg";
    "x-amz-cf-id" = "wA_pvOxg2sfYlDhdfuzwRjMkBpTNrDyPH1wXONAwFVqkW4HeeDw2gA==";
    "x-amz-cf-pop" = "HYD50-C2";
    "x-cache" = "Miss from cloudfront";
}
2020-10-03 12:02:20.375436+0530 Runner[91577:742827] flutter: Rest message sent.

More details at https://ably-real-time.slack.com/archives/C0178QGC093/p1601707774003700

@tiholic
Copy link
Author

tiholic commented Oct 6, 2020

ably-flutter PR#33 awaiting this issue resolution

@ricardopereira
Copy link
Contributor

@tiholic how is your authCallback implemented? You say it is broken because it is returning 400?

@tiholic
Copy link
Author

tiholic commented Oct 16, 2020

@ricardopereira Yes

implementation of authCallback:
https://github.com/ably/ably-flutter/blob/feature/rest-channel-history/ios/Classes/AblyFlutter.m#L88

In the above source,

  1. [self->_channel invokeMethod:AblyPlatformMethod_realtimeAuthCallback... will call dart code which will make API call to https://www.ably.io/ably-auth/token-request/demos
  2. The response from above HTTP call will be available as tokenData, a ARTTokenRequest object, created from the response obtained from dart side here

fyi; tokenData could also be ARTTokenDetails

@ricardopereira
Copy link
Contributor

⬆️

😖 I pointed to the wrong issue number.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants