nuclearace / Socket.IO-Client-Swift

socket.io-client for Swift
Other
361 stars 53 forks source link

Connection params not working #61

Closed Alex-Catchpole closed 9 years ago

Alex-Catchpole commented 9 years ago

I'm trying to use JSON web tokens to authenticate my socket.io connection. To do this i'm using this:

https://github.com/auth0/socketio-jwt

This requires I send the token in the connection params when I connect to my socket.io server. This isn't working even though I believe I'm doing everything right. The problem is client side on the app.

var sockett = SocketIOClient(socketURL: "192.168.0.3:8000", opts: ["connectParams": ["query": "token=\(token)"]])

sockett.on("error"){data, ack in
    println(data)
}

sockett.connect()

It appears the params are never being sent. I always receive the error event which tells me I have not sent the headers required (the token)

I believe I am sending the parameters correctly but feel free to correct me if I'm doing something wrong.

nuclearace commented 9 years ago

Have you tried

var sockett = SocketIOClient(socketURL: "192.168.0.3:8000", opts: ["connectParams": ["token": "\(token)"]])
nuclearace commented 9 years ago

@Alex-Catchpole does ^ work

benedictchen commented 9 years ago

This is also not working for me. Tried "connectParams" and nothing seems to come through at all.

markschmid commented 9 years ago

This is working for me. We're using the Objective-C convenience method.

self.socket = [[SocketIOClient alloc] initWithSocketURL:@"http://localhost/" options:@{@"connectParams": @{@"foo": @"bar", @"this": @"that"}}

On the server, I see (in socket.request):

  _query: 
   { transport: 'polling',
     foo: 'bar',
     this: 'that',
     b64: '1' },
vijaytholpadi commented 9 years ago

@markschmid +1. Worked for me too!

cesar-oyarzun-m commented 9 years ago

@Alex-Catchpole I have the same issue, Is working to some one?? @markschmid Did you try on Swift if this work I have this code and is not working

public var socket = SocketIOClient(socketURL: "develop.test.com:9000", options: ["log": true,"connectParams": ["token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1dWlkIjoiOTllZDUxM2UtZGZhOS00ODU4LWJlYTItODg5MDgxZTUxYzk0Iiwic2VjcmV0IjoiOTQyYmQzYTliYzkxMTBkZTcyZmQwYmUyMzRiNDlhMzUzM2M0MGEwNGFmMTJkNTI0ODYzYmYwNDdhYWJlZjY5ZTBjNTQ3YTljNWNiMDA4MTI3ODBkMmMzNWEwNDJlNTg3In0.6UC_P09W0-mcztRNQpPXep-k8knS5JE1AjSJIY70_C0"]])