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

Error: "Either a token, token param, or a keyName and secret are required to connect to Ably" #21

Closed
stannedelchev opened this issue Aug 28, 2015 · 4 comments

Comments

@stannedelchev
Copy link
Contributor

I'm trying to use an auth url in the constructor of the realtime:

let clientOptions = ARTClientOptions()
clientOptions.authOptions.authUrl = NSURL(string: "https://www.ably.io/ably-auth/token-request/demos")
clientOptions.clientId = "stan"

let realtime = ARTRealtime(options: clientOptions)

However, I'm getting this error in the constructor:

*** Terminating app due to uncaught exception 'Either a token, token param, or a keyName and secret are required to connect to Ably', reason: ''

*** First throw call stack:
(
    0   CoreFoundation    0x000000010c52ac65 __exceptionPreprocess + 165
    1   libobjc.A.dylib   0x000000010e095bb7 objc_exception_throw + 45
    2   CoreFoundation    0x000000010c52ab9d +[NSException raise:format:] + 205
    3   ably              0x000000010c3484d0 -[ARTAuth initWithRest:options:] + 1520
    4   ably              0x000000010c377f6a -[ARTRest initWithOptions:] + 330
    5   ably              0x000000010c36d9e5 -[ARTRealtime initWithOptions:] + 133
    6   demo-ios          0x000000010c1e64f2 _TTOFCSo11ARTRealtimecfMS_FT7optionsGSQCSo16ARTClientOptions__GSQS__ + 34
    7   demo-ios          0x000000010c1e570f _TFCSo11ARTRealtimeCfMS_FT7optionsGSQCSo16ARTClientOptions__GSQS__ + 79
    8   demo-ios          0x000000010c1e4d7e _TFC8demo_ios18ChatViewController11viewDidLoadfS0_FT_T_ + 862
    9   demo-ios          0x000000010c1e4dd2 _TToFC8demo_ios18ChatViewController11viewDidLoadfS0_FT_T_ + 34
    10  UIKit             0x000000010cefa1d0 -[UIViewController loadViewIfRequired] + 738
    11  UIKit             0x000000010cefa3ce -[UIViewController view] + 27
    12  UIKit             0x000000010cf1f257 -[UINavigationController _startCustomTransition:] + 633
    13  UIKit             0x000000010cf2b37f -[UINavigationController _startDeferredTransitionIfNeeded:] + 386
    14  UIKit             0x000000010cf2bece -[UINavigationController __viewWillLayoutSubviews] + 43
    15  UIKit             0x000000010d0766d5 -[UILayoutContainerView layoutSubviews] + 202
    16  UIKit             0x000000010ce499eb -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 536
    17  QuartzCore        0x000000010eca4ed2 -[CALayer layoutSublayers] + 146
    18  QuartzCore        0x000000010ec996e6 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
    19  QuartzCore        0x000000010ec99556 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
    20  QuartzCore        0x000000010ec0586e _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
    21  QuartzCore        0x000000010ec06a22 _ZN2CA11Transaction6commitEv + 462
    22  QuartzCore        0x000000010ec070d3 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 89
    23  CoreFoundation    0x000000010c45dca7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    24  CoreFoundation    0x000000010c45dc00 __CFRunLoopDoObservers + 368
    25  CoreFoundation    0x000000010c453a33 __CFRunLoopRun + 1123
    26  CoreFoundation    0x000000010c453366 CFRunLoopRunSpecific + 470
    27  GraphicsServices  0x0000000110e8fa3e GSEventRunModal + 161
    28  UIKit             0x000000010cdc98c0 UIApplicationMain + 1282
    29  demo-ios          0x000000010c1e6c57 main + 135
    30  libdyld.dylib     0x000000010f04d145 start + 1
    31  ???               0x0000000000000001 0x0 + 1
)

FYI @mattheworiordan @fealebenpae

@fealebenpae
Copy link
Contributor

I think token authentication with the authUrl option should work (except for the error in the ARTAuth initializer), but I can't be certain since I'm in the process of going through basic authentication at the moment, and then I'll move on to token authentication. You can try removing the check on ARTAuth.m line 238 which I think should unblock you.

@stannedelchev
Copy link
Contributor Author

I removed the if check you mentioned. That way the code blows up again, but this time on line 386:

return cb(@{@"Authorization": self.basicCredentials});

as basicCredentials is nil

2015-08-31 17:18:18.935 demo-ios[1189:18134] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 
'*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(
    0   CoreFoundation    0x0000000106706c65 __exceptionPreprocess + 165
    1   libobjc.A.dylib   0x0000000108271bb7 objc_exception_throw + 45
    2   CoreFoundation    0x000000010661084f -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 383
    3   CoreFoundation    0x000000010662359b +[NSDictionary dictionaryWithObjects:forKeys:count:] + 59
    4   ably              0x0000000106526c36 -[ARTAuth authHeadersUseBasic:cb:] + 326
    5   ably              0x0000000106559f12 -[ARTRest(Private) withAuthHeadersUseBasic:cb:] + 114
    6   ably              0x00000001065569be -[ARTRest makeRequestWithMethod:relUrl:headers:body:authenticated:fb:cb:] + 1406
    7   ably              0x0000000106558690 -[ARTRest makeRequestWithMethod:relUrl:headers:body:authenticated:cb:] + 272
    8   ably              0x0000000106559d97 -[ARTRest(Private) post:headers:body:authenticated:cb:] + 215
    9   ably              0x0000000106554943 -[ARTRest token:tokenCb:] + 1523
    10  ably              0x0000000106525ff7 __25-[ARTAuth prepConnection]_block_invoke_2 + 599
    11  ably              0x0000000106529c1a __50+[ARTAuth defaultSignedTokenRequestCallback:rest:]_block_invoke452 + 762
    12  ably              0x0000000106529578 __50+[ARTAuth defaultSignedTokenRequestCallback:rest:]_block_invoke_3 + 184
    13  ably              0x000000010655533f __16-[ARTRest time:]_block_invoke + 319
    14  ably              0x00000001065578f8 __73-[ARTRest makeRequestWithMethod:relUrl:headers:body:authenticated:fb:cb:]_block_invoke + 3416
    15  ably              0x0000000106531424 __26-[ARTHttp makeRequest:cb:]_block_invoke_2 + 148
    16  CoreFoundation    0x000000010663a41c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
    17  CoreFoundation    0x0000000106630165 __CFRunLoopDoBlocks + 341
    18  CoreFoundation    0x000000010662ff25 __CFRunLoopRun + 2389
    19  CoreFoundation    0x000000010662f366 CFRunLoopRunSpecific + 470
    20  GraphicsServices  0x000000010b06ba3e GSEventRunModal + 161
    21  UIKit             0x0000000106fa58c0 UIApplicationMain + 1282
    22  demo-ios          0x00000001063c2c57 main + 135
    23  libdyld.dylib     0x0000000109229145 start + 1
    24  ???               0x0000000000000001 0x0 + 1

@fealebenpae
Copy link
Contributor

I think I've gotten to the bottom of this - the clientId property of ARTClientOptions is ignored. You need to set the ARTAuthOptions's clientId:

clientOptions.authOptions.clientId = "stan"

I'll remove the clientId property from ARTClientOptions.

@mattheworiordan
Copy link
Member

@fealebenpae where is ClientOptions used as the format seems wrong? See http://docs.ably.io/client-lib-development-guide/features/#options for a spec on the format of this type.

ricardopereira added a commit that referenced this issue Aug 22, 2019
 - This failed in RTP9a because it sometimes ends but the ACK/NACK of the last sent presence message has not arrived yet, it means the callback is pended. The callback is called when the connection closes (test ends), a "ARTErrorInfo with code 0, message: connection broken before receiving publishing acknowledgment." happens and it will crash because the callback is nil.

EXC_BAD_ACCESS (code=1, address=0x10) in ARTRealtimeChannel.m:335

Thread 3 Queue : io.ably.tests (serial)
#0	0x000000012186c6b4 in __47-[ARTRealtimeChannel publishPresence:callback:]_block_invoke.164 at /<redacted>/ably-cocoa/Source/ARTRealtimeChannel.m:335
#1	0x000000012186ecdd in __43-[ARTRealtimeChannel sendMessage:callback:]_block_invoke at /<redacted>/ably-cocoa/Source/ARTRealtimeChannel.m:450
#2	0x00000001218be38e in __22-[ARTEventEmitter on:]_block_invoke at /<redacted>/ably-cocoa/Source/ARTEventEmitter.m:209
#3	0x00000001083ff632 in -[__NSObserver _doit:] ()
#4	0x00000001094827bc in __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ ()
#5	0x0000000109481c3f in _CFXRegistrationPost ()
#6	0x0000000109481983 in ___CFXNotificationPost_block_invoke ()
#7	0x00000001095657c2 in -[_CFXNotificationRegistrar find:object:observer:enumerator:] ()
#8	0x00000001094812d1 in _CFXNotificationPost ()
#9	0x00000001083ffddb in -[NSNotificationCenter postNotificationName:object:userInfo:] ()
#10	0x00000001218bf843 in -[ARTEventEmitter emit:with:] at /<redacted>/ably-cocoa/Source/ARTEventEmitter.m:275
#11	0x0000000121915222 in -[ARTRealtime transition:withErrorInfo:] at /<redacted>/ably-cocoa/Source/ARTRealtime.m:429
#12	0x0000000121914c0a in -[ARTRealtime transition:] at /<redacted>/ably-cocoa/Source/ARTRealtime.m:412
#13	0x000000012191b755 in -[ARTRealtime onClosed] at /<redacted>/ably-cocoa/Source/ARTRealtime.m:768
#14	0x0000000121928933 in -[ARTRealtime realtimeTransport:didReceiveMessage:] at /<redacted>/ably-cocoa/Source/ARTRealtime.m:1392
#15	0x00000001218c4bef in -[ARTWebSocketTransport receive:] at /<redacted>/ably-cocoa/Source/ARTWebSocketTransport.m:109
#16	0x00000001218c4cbe in -[ARTWebSocketTransport receiveWithData:] at /<redacted>/ably-cocoa/Source/ARTWebSocketTransport.m:114
#17	0x00000001218c7c44 in -[ARTWebSocketTransport webSocketMessageData:] at /<redacted>/ably-cocoa/Source/ARTWebSocketTransport.m:367
#18	0x00000001218c77a0 in -[ARTWebSocketTransport webSocket:didReceiveMessage:] at /<redacted>/ably-cocoa/Source/ARTWebSocketTransport.m:349
#19	0x0000000121bf06c9 in __43-[SRWebSocket _handleFrameWithData:opCode:]_block_invoke.239 ()
#20	0x000000010b3e2ccf in _dispatch_call_block_and_release ()
#21	0x000000010b3e3d02 in _dispatch_client_callout ()
#22	0x000000010b3ea720 in _dispatch_lane_serial_drain ()
#23	0x000000010b3eb261 in _dispatch_lane_invoke ()
#24	0x000000010b3f3fcb in _dispatch_workloop_worker_thread ()
#25	0x000000010bb12611 in _pthread_wqthread ()
#26	0x000000010bb123fd in start_wqthread ()
maratal pushed a commit that referenced this issue Jul 19, 2023
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

4 participants