bluenviron / mediamtx

Ready-to-use SRT / WebRTC / RTSP / RTMP / LL-HLS media server and media proxy that allows to read, publish, proxy, record and playback video and audio streams.
MIT License
12.32k stars 1.53k forks source link

HTTP Ext Auth Redirection #3475

Open Sora012 opened 5 months ago

Sora012 commented 5 months ago

Describe the feature

HTTP External Auth should be capable of returning 301/302 redirections to a new stream paths

Description I am trying to make a twitch alike service, While I know twitch uses "/app/key" I'm trying to do something similiar with "/username/streamkey" where the user will input "rtmps://serv:port/username" then in the stream key section input the hidden key. which would return a stream path of "username/streamkey" this would be fine if I could strip the /streamkey and tell the server via EXT Auth to 301/302 the path to a new location.

I've tried a few different ways to try to handle this situation but I'm at a loss at the moment, and don't think its fully possible without further assistance and requesting 301/302 redirect support.

irg1008 commented 4 months ago

You need to use a reverse proxy and/or jwt authentication

Sora012 commented 4 months ago

As far as I can tell redirection only works internally, and not via external auth or JWT at all. I'm asking for something like the on_play directive for NGINX RTMP. (Which is also used for "on_publish" thus, a 301/302 will redirect a path when publishing)

HTTP 2xx code continues RTMP session HTTP 3xx redirects RTMP to another stream whose name is taken from Location HTTP response header. If new stream name is started with rtmp:// then remote relay is created instead.

irg1008 commented 4 months ago

You may be right. I was able to redirect and perform checks before starting streaming using WHIP/WHEP that works via http. I don't know if you can do the same with RTMP.

Diras226 commented 3 months ago

I am having the same problem right now. Did you find a solution?

Sora012 commented 3 months ago

No, I was never able to resolve this. I simply check on auth/stream that the username/stream path match exactly, and if they try to stream to any other path than the username with the key, its rejected just like any other invalid stream.

I was never able to force redirection to the correct path. A twitch-alike solution ( e.g. rtmp://127.0.0.1/app/streamkey ) is not doable as far as I can tell.