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

Where can I set the authentication token? #62

Open
katsuo555 opened this issue Aug 24, 2015 · 2 comments
Open

Where can I set the authentication token? #62

katsuo555 opened this issue Aug 24, 2015 · 2 comments

Comments

@katsuo555
Copy link

I am developing a application of two-way communication in SocketIO between App of iPhone and server.

I would like to implement the authentication function when connecting from the application side to the chat server.

I have implemented on the server side as described below.

io.set('authorization', function (handshakeData, callback) {

    var token = handshakeData.query.token;

    checkAuthToken(token, callback);

});

However, I do not know where I should set the token in the app side.

var socket:SIOSocket! = nil

SIOSocket.socketWithHost("ServerUrl" , response: { (_socket: SIOSocket!) in
    self.socket = _socket

    println(self.socket)

    self.socket.onConnect = {() in
       println("connected")

    }
})

To borrow your wisdom.

@katsuo555 katsuo555 changed the title Where do the authentication token set? Where can I set the authentication token? Aug 24, 2015
@danipralea
Copy link

I use it in the connection block:

NSDictionary * parameters = [NSDictionary dictionaryWithObject:token forKey:@"token"];
    NSArray * parametersArray = [NSArray arrayWithObject:parameters];

    [SIOSocket socketWithHost:serverURL response: ^(SIOSocket *socket){
        self.socket = socket;

        self.socket.onConnect = ^ () {
            if ([GabAuthenticatedUser sharedUser].token) {
                NSLog(@"SIOSocket : web socket connected. Authenticating with parameters : %@", parameters);
                [socket emit: @"authenticate" args:parametersArray];
            }
        };

        self.socket.onDisconnect = ^ () {
            NSLog(@"SIOSocket : web socket disconnected!");
        };

        self.socket.onError = ^(NSDictionary* error) {
            NSLog(@"SIOSocket : error connecting to web socket : %@", error);
        };
    }];

@taylorbk
Copy link

An even more straightforward method that I personally used:

NSString *url = [NSString stringWithFormat:@"http://localhost:3000?token=%@",token];
[SIOSocket socketWithHost: url response: ^(SIOSocket *socketer) {
...

Works like a charm!

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

No branches or pull requests

3 participants