Authenticating
When using the Emogg WebSocket API, it's crucial to authenticate your connection immediately after it's established. The first message you send should always be an authentication message. Failure to authenticate promptly will result in the server terminating the connection.
If you do not have an access token see Authentication to learn how to get one.
Authentication request format
- The
pathfield must be set toauth:token. - The
bodyof the message must contain an object with a single field,token, which is your access token.
For more details check Request format.
Example
Here's an example of an authentication message:
{
"path": "auth:token",
"body": {
"token": "YOUR_ACCESS_TOKEN"
}
}
Response
Upon receiving your authentication message, the server will process it and respond accordingly:
Always check the server's response to your authentication request before sending messages to ensure that your connection remains open and active for further communication.
Successful authentication
If your token is valid, the server will respond with a message containing a status of 200, indicating that the authentication was successful.
Example
{
"id": null,
"path": "auth:token",
"status": 200
}
Failed authentication
If the token is invalid or if there's any issue with your authentication request, the server will send a response with a status of 401. Additionally, the server will close the connection immediately after sending this error message.
Example
{
"error": true,
"id": null,
"path": "auth:token",
"status": 401,
"data": {
"message": "Invalid token"
}
}