Login Moderator via SSO
In this guide we will explore how you can login moderators via SSO, and how to create moderators that can only moderate single room and moderators that can moderate multiple rooms.
In this guide we will go through the steps on how you can login the moderator into the chat room.

Overview

We will learn the following:
    How to create moderators via the API
    How to create a moderator that can moderator all chat rooms
    How to create a moderator that can moderate a single chat room
    How to login the moderator into the chat room automatically via SSO
We highly recommend that you read the SSO using Auth Token Guide before reading this one.

Pre-requsite

You would need a Dead Simple Chat account, if you don't already have an account, signup for a free account here.
You also need to have the Secret Key to call the Dead Simple Chat API, if you don't have the Secret Key then you can contact the Dead Simple Chat Support to obtain the secret key.

Step 1a: Creating a Moderator who can moderate all Chat Rooms

To create a moderator is very simple, just call the create user api and pass isModerator property as true
cURL
Node.JS (Axios)
1
curl -X POST "https://api.deadsimplechat.com/consumer/api/v1/user?auth=<auth_token>" \
2
-H "Content-Type: application/json" \
3
-d '{ "username": "James", "isModerator": true }'
Copied!
1
const axios = require('axios').default;
2
axios.post('https://api.deadsimplechat.com/consumer/api/v1/user?auth=<auth_token>', {
3
username: "James",
4
isModerator: true
5
})
6
.then(function (response) {
7
console.log(response);
8
})
9
.catch(function (error) {
10
console.log(error);
11
});
Copied!
Response
1
{
2
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2MTIwMjZlMjc1NzA2MDM4NTAzNDRhNTUiLCJ1c2VybmFtZSI6IkJvbmQiLCJwYXJlbnRDdXN0b21lckFjY291bnQiOiI1ZTlmOTVmNGI4NTIzMDVjZWU5Zjc4N2MiLCJjcmVhdGVkVXNpbmdBcGkiOnRydWUsImlzTW9kZXJhdG9yIjp0cnVlLCJjdXN0b21lciI6IjVlOWY5NWY0Yjg1MjMwNWNlZTlmNzg3YyIsImNyZWF0ZWQiOiIyMDIxLTA4LTIwVDIyOjA0OjE4LjY3OVoiLCJ1cGRhdGVkIjoiMjAyMS0wOC0yMFQyMjowNDoxOC42NzlaIiwiX192IjowLCJpYXQiOjE2Mjk0OTcwNTh9.37H0RRBt77_sdY06ojkDb9Jt6qsSHLIRf_j2PfHuNXI",
3
"username": "Bond",
4
"userId": "612026e27570603850344a55",
5
"isModerator": true
6
}
Copied!
We have created a moderator with username Bond who can moderate any chat room.

Step 1b: Creating a Moderator who can moderate a Single Chat Room

To create a moderator who can moderate a single chat room you would have to pass the chatRoom parameter, and the chatRoom parameter would contain the roomId of the chatroom.
For e,g if your chat room id is -eZxgepn9 then the request would become
cURL
Node.JS (Axios)
1
curl -X POST "https://api.deadsimplechat.com/consumer/api/v1/user?auth=<auth_token>" \
2
-H "Content-Type: application/json" \
3
-d '{ "username": "James", "isModerator"; true, "chatRoom": "-eZxgepn9" }'
Copied!
1
const axios = require('axios').default;
2
axios.post('https://api.deadsimplechat.com/consumer/api/v1/user?auth=<auth_token>', {
3
username: "James",
4
isModerator: true,
5
chatRoom: "-eZxgepn9"
6
})
7
.then(function (response) {
8
console.log(response);
9
})
10
.catch(function (error) {
11
console.log(error);
12
});
Copied!
1
{
2
"accessToken": "asyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2MTIwMjZlMjc1NzA2MDM4NTAzNDRhNTUiLCJ1c2VybmFtZSI6IkJvbmQiLCJwYXJlbnRDdXN0b21lckFjY291bnQiOiI1ZTlmOTVmNGI4NTIzMDVjZWU5Zjc4N2MiLCJjcmVhdGVkVXNpbmdBcGkiOnRydWUsImlzTW9kZXJhdG9yIjp0cnVlLCJjdXN0b21lciI6IjVlOWY5NWY0Yjg1MjMwNWNlZTlmNzg3YyIsImNyZWF0ZWQiOiIyMDIxLTA4LTIwVDIyOjA0OjE4LjY3OVoiLCJ1cGRhdGVkIjoiMjAyMS0wOC0yMFQyMjowNDoxOC42NzlaIiwiX192IjowLCJpYXQiOjE2Mjk0OTcwNTh9.37H0RRBt77_sdY06ojkDb9Jt6qsSHLIRf_j2PfHuNXI",
3
"username": "Bond",
4
"userId": "612026e27570603850344a55",
5
"isModerator": true,
6
"chatRoom": "-eZxgepn9"
7
}
Copied!
This will create a moderator who can only moderate the chat room with specified roomId.
When we use this accessToken to login the moderator into another chat room, then the moderator will be logged-in as a regular user, and wouild not have the moderator functionality.

Step 2: Passing the Access Token to the Chat Room

The access token must be pass as a query parameter to the chat room url, for e.g if our chat room url is https://deadsimplechat.com/-eZgepn9 then we will change it to https://deadsimplechat.com/-eZgepn9?accessToken=<accessToken>
And replace <accessToken> with the actual access token that we have obtained from the API response.
So, our iFrame embed code would become
1
<iframe src="https://deadsimplechat.com/-eZxgepn9?accessToken=eyJhbGciOiJIUzI1NiIsR5cCI6IkpXVCJ9.eyfaWQiOiI2MTIwMDM2NTc1NzA2MDM4NTAzNDRhNTQiLCJ1c2VybmFtZSI6IkphbWVzIiwicGFyZW50Q3VzdG9tZXJBY2NvdW50IjoiNWU5Zjk1ZjRiODUyMzA1Y2VlOWY3ODdjIiwiY3JlYXRlZFVzaW5nQXBpIjp0cnVlLCJjcmVhdGVkIjoiMjAyMS0wOC0yMFQxOTozMjo1My45MjZaIiwidXBkYXRlZCI6IjIwMjEtMDgtMjBUMTk6MzI6NTMuOTI2WiIsIl9fdiI6MCwiaWF0IjoxNjI5NDg3OTczfQ.4SAdP458R4DM3sPVZJ0XRIEYullEMWaaA3FQQtMD4k4" width="100%" height="600px"></iframe>
2
Copied!
Last modified 1mo ago