Authenticate with token
Authenticate the connection using the token method. See Authenticating for more details about the auth mechanism.
Path
auth:token
Request Body
token
string
Required
Your authentication token.
Response codes
| Code | Meaning | Description |
|---|---|---|
| 200 | OK | The request has succeeded. The client can read the result in the body if present. |
| 401 | Unauthorized | The connection is not authenticated or the authentication details provided are not valid. This error terminates the connection. |
Request example
auth:token
// Connect to the server
const ws = new WebSocket('wss://api.emogg.com/ws/v1');
// Helper function for sending messages
const sendMessage = (path, body, id) => {
const payload = {
"id": id,
"path": path,
"body": body
}
console.log('// Request\n', payload)
ws.send(JSON.stringify(payload));
}
// Authenticate connection
ws.onopen = () => sendMessage("auth:token", { "token": "YOUR_TOKEN" }, 1);
// Server messages callback
ws.onmessage = function (payload) {
const message = JSON.parse(payload.data)
console.log('// Response\n', message)
};
Result
// Request
{ "id": 1, "path": "auth:token", "body": { "token": "YOUR_TOKEN" } }
// Response
{ "id": 1, "path": "auth:token", "status": 200 }
// More requests and responses
{...}