-
Notifications
You must be signed in to change notification settings - Fork 0
Push Socket Protocol
NOTE: Sockets are implemented using socket.io. For documentation beyond the protocol structure, visit http://socket.io/docs/ #Connect to Server from the Client
-
Open a connection with the server
var socket = ioClient.connect({"server_url"});
-
Once a connection is established, push the clients authentication credentials to the server with message title "authentication"
socket.on('connect', function (data) { socket.emit('authentication', { username:{"auth_username"}, password:{"auth_password"}; });
-
auth_usernameis of the formbase64(identityKey)|deviceIdwherebase64(identityKey)is your longterm public key base 64 encoded anddeviceIdis the device ID of the device you are making the request from. -
auth_passwordis of the formtimestamp|signature(timestamp)where timestamp is the current unix time as an integer and signature(timestamp) is a signature of the unix time from your longterm private key.
-
-
After pushing the
authenticationmessage and credentials, the client will receive one of two responses back from the server:-
The server will push an
authorizedmessage. It is not necessary to take further action upon receipt of this message, but it is provided as a notification that authorization succeeded. It can be received in the following way:socket.on('authorized', function(data) { //lets you know that socket.emit('authentication'... was successful });
-
The server will push a
not authorizedmessage. This message will include data that will detail why authorization failed and help the client make a valid request on subsequent attempts. This message can be received in the following way:socket.on('not authorized', function(data) { var reasonForFailure = data.message; if (reasonforfailure == "time") { var serverTime = data.serverTime; } //proceede based on reasonForFailure });
-
data.messagecan take the following values:-
"badly formed credentials"indicates that the submittedauth_usernameand/orauth_passwordwere missing or had the wrong format -
"revoked"indicates that the identity key submitted as part ofauth_usernamehas been revoked -
"signature"indicates that the signature submitted as part ofauth_passwordcould not be verified -
"not registered"indicates that the identityKey/deviceId combo submitted asauth_usernamehas not yet been registered with the key server -
"time"indicates that the timestamp submitted as part ofauth_passwordis either out of sync with the server or too stale to accept. In this case, there is also adata.serverTimevalue which contains a timestamp from the server in unix time as an integer. This timestamp can be signed to create a valid password.
-
-
-
#Receive Messages from the Server Once a connection is created and the client is authorized successfully, messages are received in the following way:
socket.on('message', function(messageData) {
//confirm reception of message
socket.emit('recieved', {messageId: messageData.id});
var messageHeader = messageData.header; //same header that was sent to server
var messageBody = messageData.body; //same body that was sent to server
// do something with messageData here
// ...
});-
messageData.headeris a base64 encoded string that contains the header of the out-band message -
messageData.bodyis a base64 encoded string that contains the body of the out-band message