- 15 Aug 2022
- 1 Minute to read
Webhook stream authorization
- Updated on 15 Aug 2022
- 1 Minute to read
There are plenty of Security options for Publishing and Playing Streams available in Ant Media Server, however, if these are not suitable for your use case and you want to control which stream to be published directly from your own end, then you can use your own webhook structure for stream authentication.
After inserting this setting, restart the server.
You can use this webhook site to test this feature and get your own webhook URL. However, when you send a request to that site correctly, the response code will always be 200 by default. Let's test this with an example to publish a stream.
Sample webhook URL from webhook site is added in settings file as follows.
After this, when an RTMP/WebRTC stream initiates to publish, it will trigger the webhook URL and sends the request like below.
If the response is 200 then it allows the stream to be published with logs as follows.
INFO i.a.s.AcceptOnlyStreamsWithWebhook - Response from webhook is: 200 for stream:stream1 INFO i.a.e.w.WebSocketEnterpriseHandler - Is publish allowed through Webhook Authentication: true
Now you can change the response code on the webhook site by clicking the Edit option. As an example, change it to 300.
Please try to publish the stream again but this time as the response will be 300, hence it will not authorize to publish the stream on the server with the logs below.
INFO i.a.s.AcceptOnlyStreamsWithWebhook - Response from webhook is: 300 for stream:stream1 WARN i.a.s.AcceptOnlyStreamsWithWebhook - Connection object is null for stream1 INFO i.a.e.w.WebSocketEnterpriseHandler - Is publish allowed through Webhook Authentication: false
For more details about using webhook in Ant Media Server, please check webhook documentation.