ably / demo-mobile-ios

A simple mobile app built for iOS using the ably-io realtime library
3 stars 4 forks source link

Missing clientId #5

Open mattheworiordan opened 8 years ago

mattheworiordan commented 8 years ago

@stannedelchev I have tested the iOS app today, and I consistently get:

voila_capture 2016-08-12_02-56-59_pm

I suspect that the clientId is missing from the token.

For example, it seems you set the clientId here https://github.com/ably/demo-mobile-ios/blob/5d9bb46cf6608b19455c0a1875d9cb6eb4219c09/demo-ios/ChatModel.swift#L29, yet the token you request has not clientId, so the token assigned clientId is the one that counts.

See https://github.com/ably/demo-mobile-phonegap-cordova/blob/main/www/js/app.js#L101 fro how it is handled in Cordova.

Also, I see that:

tcard commented 8 years ago

This was fixed in 0.8.3, while ably/demo-mobile-ios is using 0.8.2. A new pod install should fix it.

mattheworiordan commented 8 years ago

This was fixed in 0.8.3

I think you mean the incompatibility check / clientId param is fixed yes? Thanks @tcard

@stannedelchev, either way, a token with an embedded clientId should really be used.

tcard commented 8 years ago

I meant to do a pull request for 824663f but pushed directly to main, sorry. Anyway, should be fixed now.

tcard commented 8 years ago

I think you mean the incompatibility check / clientId param is fixed yes? Thanks @tcard

Yes, that comment should have gone to https://github.com/ably/ably-ios/issues/462.

mattheworiordan commented 8 years ago

Opening this as @stannedelchev please request a token with a clientId

stannedelchev commented 8 years ago

@mattheworiordan @tcard I'm requesting the token with the clientId url param: https://github.com/ably/demo-mobile-ios/commit/4b92e86b8e2d56fe6702ab9c42a6180ddef100c5

However, I'm getting an error Attempted to publish presence message without clientId here and a HTTP 401 from the server.

Here's the log:

2016-08-15 10:29:03.197 demo-ios[8358:113125] WARNING: A Gesture recognizer (<UITapGestureRecognizer: 0x7fcc4bec0ad0; state = Possible; view = <UIView 0x7fcc4bca24d0>; target= <(action=handleMembersContainerTap:, target=<demo_ios.ChatViewController 0x7fcc4bec13f0>)>>) was setup in a storyboard/xib to be added to more than one view (-><UIView: 0x7fcc4bcc2de0; frame = (0 0; 600 600); autoresize = RM+BM; gestureRecognizers = <NSArray: 0x7fcc4bccdff0>; layer = <CALayer: 0x7fcc4bcc2020>>) at a time, this was never allowed, and is now enforced. Beginning with iOS 9.0 it will be put in the first view it is loaded into.
Encoded client id is |abcdefffffff| , url is |Optional(https://www.ably.io/ably-auth/token-request/demos?clientId=abcdefffffff)|
2016-08-15 10:29:03.208 demo-ios[8358:113125] DEBUG: (ARTRest.m:57) RS:0x7fcc4beb40b0 0x7fcc4be27eb0 alloc HTTP
2016-08-15 10:29:03.208 demo-ios[8358:113125] DEBUG: (ARTAuth.m:45) RS:0x7fcc4beb40b0 validating ARTClientOptions: key=(null) token=(null) authUrl=https://www.ably.io/ably-auth/token-request/demos?clientId=abcdefffffff authMethod=GET hasAuthCallback=0
2016-08-15 10:29:03.208 demo-ios[8358:113125] DEBUG: (ARTAuth.m:66) RS:0x7fcc4beb40b0 setting up auth method Token with authUrl
2016-08-15 10:29:03.209 demo-ios[8358:113125] DEBUG: (ARTRest.m:73) RS:0x7fcc4beb40b0 initialized
2016-08-15 10:29:03.209 demo-ios[8358:113125] DEBUG: (ARTRealtime.m:82) R:0x7fcc4bebea70 initialized with RS:0x7fcc4beb40b0
2016-08-15 10:29:03.209 demo-ios[8358:113125] DEBUG: (ARTRealtime.m:212) R:0x7fcc4bebea70 transition to Connecting requested
2016-08-15 10:29:03.209 demo-ios[8358:113125] DEBUG: (ARTWebSocketTransport.m:56) R:0x0 WS:0x7fcc4bd0eff0 alloc
2016-08-15 10:29:03.209 demo-ios[8358:113125] DEBUG: (ARTWebSocketTransport.m:91) R:0x7fcc4bebea70 WS:0x7fcc4bd0eff0 websocket connect
2016-08-15 10:29:03.209 demo-ios[8358:113125] DEBUG: (ARTWebSocketTransport.m:105) R:0x7fcc4bebea70 WS:0x7fcc4bd0eff0 connecting with token auth; authorising
2016-08-15 10:29:03.210 demo-ios[8358:113125] VERBOSE: RS:0x7fcc4beb40b0 ARTAuth: requesting new token.
2016-08-15 10:29:03.210 demo-ios[8358:113125] DEBUG: (ARTAuth.m:175) RS:0x7fcc4beb40b0 using authUrl (GET https://www.ably.io/ably-auth/token-request/demos?clientId=abcdefffffff&ttl=3600.000000&capability=%7B%22*%22:%5B%22*%22%5D%7D&timestamp=1471246143.210246&format=msgpack)
2016-08-15 10:29:03.211 demo-ios[8358:113125] DEBUG: (ARTRest.m:138) RS:0x7fcc4beb40b0 executing request <NSMutableURLRequest: 0x7fcc4bccd850> { URL: https://www.ably.io/ably-auth/token-request/demos?clientId=abcdefffffff&ttl=3600.000000&capability=%7B%22*%22:%5B%22*%22%5D%7D&timestamp=1471246143.210246&format=msgpack }
2016-08-15 10:29:03.211 demo-ios[8358:113125] DEBUG: GET https://www.ably.io/ably-auth/token-request/demos?clientId=abcdefffffff&ttl=3600.000000&capability=%7B%22*%22:%5B%22*%22%5D%7D&timestamp=1471246143.210246&format=msgpack
2016-08-15 10:29:03.211 demo-ios[8358:113125] VERBOSE: Headers {
    Accept = "application/json,application/x-msgpack";
    "X-Ably-Version" = "0.8";
}
2016-08-15 10:29:03.212 demo-ios[8358:113125] DEBUG: (ARTRestChannel.m:35) RS:0x7fcc4bed7020 instantiating under 'mobile:chat'
2016-08-15 10:29:03.214 demo-ios[8358:113125] DEBUG: (ARTRealtimeChannel.m:540) R:0x7fcc4bebea70 C:0x7fcc4bed6c40 already attaching
2016-08-15 10:29:03.219 demo-ios[8358:113125] DEBUG: (ARTRealtimeChannel.m:540) R:0x7fcc4bebea70 C:0x7fcc4bed6c40 already attaching
2016-08-15 10:29:04.283 demo-ios[8358:113125] DEBUG: GET https://www.ably.io/ably-auth/token-request/demos?clientId=abcdefffffff&ttl=3600.000000&capability=%7B%22*%22:%5B%22*%22%5D%7D&timestamp=1471246143.210246&format=msgpack: statusCode 200
2016-08-15 10:29:04.284 demo-ios[8358:113125] VERBOSE: Headers {
    "Access-Control-Allow-Origin" = "http://docs.ably.io";
    "Cache-Control" = "max-age=0, private, must-revalidate";
    Connection = close;
    "Content-Encoding" = gzip;
    "Content-Type" = "application/json; charset=utf-8";
    Date = "Mon, 15 Aug 2016 07:29:04 GMT";
    Etag = "W/\"ca84f691cdd82e01f78fa0ec98a13fc7\"";
    Server = Cowboy;
    Status = "200 OK";
    Vary = "Accept-Encoding";
    Via = "1.1 vegur";
    "X-Content-Type-Options" = nosniff;
    "X-Frame-Options" = SAMEORIGIN;
    "X-Request-Id" = "6764b5aa-1311-4e48-ae59-ff642f24bce0";
    "X-Runtime" = "0.063669";
    "X-Xss-Protection" = "1; mode=block";
}
2016-08-15 10:29:04.284 demo-ios[8358:113125] DEBUG: RS:0x7fcc4beb40b0 ARTAuth: authUrl response <NSHTTPURLResponse: 0x7fcc4e01f400> { URL: https://www.ably.io/ably-auth/token-request/demos?clientId=abcdefffffff&ttl=3600.000000&capability=%7B%22*%22:%5B%22*%22%5D%7D&timestamp=1471246143.210246&format=msgpack } { status code: 200, headers {
    "Access-Control-Allow-Origin" = "http://docs.ably.io";
    "Cache-Control" = "max-age=0, private, must-revalidate";
    Connection = close;
    "Content-Encoding" = gzip;
    "Content-Type" = "application/json; charset=utf-8";
    Date = "Mon, 15 Aug 2016 07:29:04 GMT";
    Etag = "W/\"ca84f691cdd82e01f78fa0ec98a13fc7\"";
    Server = Cowboy;
    Status = "200 OK";
    Vary = "Accept-Encoding";
    Via = "1.1 vegur";
    "X-Content-Type-Options" = nosniff;
    "X-Frame-Options" = SAMEORIGIN;
    "X-Request-Id" = "6764b5aa-1311-4e48-ae59-ff642f24bce0";
    "X-Runtime" = "0.063669";
    "X-Xss-Protection" = "1; mode=block";
} }
2016-08-15 10:29:04.285 demo-ios[8358:113125] VERBOSE: RS:0x7fcc4beb40b0 ARTJsonLikeEncoder<json> decoding '<7b226b65 794e616d 65223a22 4932455f 4a512e72 5f614f59 67222c22 636c6965 6e744964 223a2261 62636465 66666666 66666622 2c227474 6c223a34 33323030 3030302c 2274696d 65737461 6d70223a 31343731 32343631 34343138 392c2263 61706162 696c6974 79223a22 7b5c222a 5c223a5b 5c222a5c 225d7d22 2c226e6f 6e636522 3a223232 32346631 34663461 31306134 32353464 61386635 62333563 36393532 3634222c 226d6163 223a226f 306f3851 445a2f6e 4e434a46 3757706e 7862484e 31563056 6e42696c 6d7a7634 354e7364 612f7558 55673d22 7d>'; got: {
    capability = "{\"*\":[\"*\"]}";
    clientId = abcdefffffff;
    keyName = "I2E_JQ.r_aOYg";
    mac = "o0o8QDZ/nNCJF7WpnxbHN1V0VnBilmzv45Nsda/uXUg=";
    nonce = 2224f14f4a10a4254da8f5b35c695264;
    timestamp = 1471246144189;
    ttl = 43200000;
}
2016-08-15 10:29:04.285 demo-ios[8358:113125] VERBOSE: RS:0x7fcc4beb40b0 ARTJsonLikeEncoder<json>: tokenFromDictionary {
    capability = "{\"*\":[\"*\"]}";
    clientId = abcdefffffff;
    keyName = "I2E_JQ.r_aOYg";
    mac = "o0o8QDZ/nNCJF7WpnxbHN1V0VnBilmzv45Nsda/uXUg=";
    nonce = 2224f14f4a10a4254da8f5b35c695264;
    timestamp = 1471246144189;
    ttl = 43200000;
}
2016-08-15 10:29:04.285 demo-ios[8358:113125] VERBOSE: RS:0x7fcc4beb40b0 ARTAuth: token request succeeded: ARTTokenDetails: token=(null) clientId=abcdefffffff issued=(null) expires=(null)
2016-08-15 10:29:04.285 demo-ios[8358:113125] DEBUG: (ARTWebSocketTransport.m:109) R:0x7fcc4bebea70 WS:0x7fcc4bd0eff0 authorised: ARTTokenDetails: token=(null) clientId=abcdefffffff issued=(null) expires=(null) error: (null)
2016-08-15 10:29:04.286 demo-ios[8358:113125] DEBUG: (ARTWebSocketTransport.m:181) R:0x7fcc4bebea70 WS:0x7fcc4bd0eff0 url /?accessToken&echo=true&format=msgpack&v=0.8 -- wss://realtime.ably.io:443
2016-08-15 10:29:04.603 demo-ios[8358:113125] DEBUG: (ARTWebSocketTransport.m:295) R:0x7fcc4bebea70 WS:0x7fcc4bd0eff0 websocket did receive error Error Domain=SRWebSocketErrorDomain Code=2132 "received bad response code from server 401" UserInfo={NSLocalizedDescription=received bad response code from server 401, HTTPResponseStatusCode=401}
2016-08-15 10:29:04.604 demo-ios[8358:113125] DEBUG: (ARTRealtime.m:756) R:0x7fcc4bebea70 realtime transport failed: <ARTRealtimeTransportError: 0x7fcc4be02b40 {
  type: BadResponse
  badResponseCode: 401
  url: /?accessToken&echo=true&format=msgpack&v=0.8 -- wss://realtime.ably.io:443
  error: Error Domain=SRWebSocketErrorDomain Code=2132 "received bad response code from server 401" UserInfo={NSLocalizedDescription=received bad response code from server 401, HTTPResponseStatusCode=401}
}>
2016-08-15 10:29:04.604 demo-ios[8358:113125] DEBUG: (ARTRealtime.m:212) R:0x7fcc4bebea70 transition to Failed requested
2016-08-15 10:29:04.605 demo-ios[8358:113125] DEBUG: (ARTWebSocketTransport.m:62) R:0x0 WS:0x7fcc4bd0eff0 dealloc
mattheworiordan commented 8 years ago

@tcard see above, looks like the token request being retrieved is not being used to then obtain an actual token. It then connects to Ably without an accessToken value in the URL. Any idea what is going on here?