forked from voc/srtrelay
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement HTTP auth, fix authconfig parsing
- Loading branch information
Showing
6 changed files
with
101 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,59 @@ | ||
package auth | ||
|
||
import "github.com/voc/srtrelay/stream" | ||
import ( | ||
"log" | ||
"net/http" | ||
"net/url" | ||
"time" | ||
|
||
"github.com/voc/srtrelay/stream" | ||
) | ||
|
||
type httpAuth struct { | ||
url string | ||
config HTTPAuthConfig | ||
client *http.Client | ||
} | ||
|
||
type HttpAuthConfig struct { | ||
URL string | ||
type HTTPAuthConfig struct { | ||
URL string | ||
Application string | ||
Timeout time.Duration // Timeout for Auth request | ||
PasswordParam string // POST Parameter containing stream passphrase | ||
} | ||
|
||
func NewHttpAuth(config HttpAuthConfig) *httpAuth { | ||
// NewHttpAuth creates an Authenticator with a HTTP backend | ||
func NewHTTPAuth(config HTTPAuthConfig) *httpAuth { | ||
return &httpAuth{ | ||
url: config.URL, | ||
config: config, | ||
client: &http.Client{ | ||
Timeout: config.Timeout, | ||
}, | ||
} | ||
} | ||
|
||
// Implement Authenticator | ||
|
||
// Authenticate sends form-data in a POST-request to the configured url. | ||
// If the response code is 2xx the publish/play is allowed, otherwise it is denied. | ||
// This should be compatible with nginx-rtmps on_play/on_publish directives. | ||
// https://github.com/arut/nginx-rtmp-module/wiki/Directives#on_play | ||
func (h *httpAuth) Authenticate(streamid stream.StreamID) bool { | ||
// TODO: implement post request | ||
return false | ||
response, err := h.client.PostForm(h.config.URL, url.Values{ | ||
"call": {streamid.Mode().String()}, | ||
"app": {h.config.Application}, | ||
"name": {streamid.Name()}, | ||
h.config.PasswordParam: {streamid.Password()}, | ||
}) | ||
|
||
if err != nil { | ||
log.Println("http-auth:", err) | ||
return false | ||
} | ||
defer response.Body.Close() | ||
|
||
if response.StatusCode < 200 || response.StatusCode >= 300 { | ||
return false | ||
} | ||
|
||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters