move cors to middleware (#54)
* move cors to middleware * check for nil url * remove snapshot
This commit is contained in:
@@ -34,6 +34,10 @@ func NewAPIKeyAuthMiddleware(provider auth.KeyProvider) *APIKeyAuthMiddleware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *APIKeyAuthMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
|
func (m *APIKeyAuthMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
|
||||||
|
if r.URL != nil && r.URL.Path == "/rtc/validate" {
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
}
|
||||||
|
|
||||||
authHeader := r.Header.Get(authorizationHeader)
|
authHeader := r.Header.Get(authorizationHeader)
|
||||||
var authToken string
|
var authToken string
|
||||||
|
|
||||||
|
|||||||
+13
-14
@@ -45,7 +45,6 @@ func NewRTCService(conf *config.Config, roomManager *RoomManager, router routing
|
|||||||
|
|
||||||
func (s *RTCService) Validate(w http.ResponseWriter, r *http.Request) {
|
func (s *RTCService) Validate(w http.ResponseWriter, r *http.Request) {
|
||||||
_, _, code, err := s.validate(r)
|
_, _, code, err := s.validate(r)
|
||||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleError(w, code, err.Error())
|
handleError(w, code, err.Error())
|
||||||
return
|
return
|
||||||
@@ -54,6 +53,17 @@ func (s *RTCService) Validate(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *RTCService) validate(r *http.Request) (string, routing.ParticipantInit, int, error) {
|
func (s *RTCService) validate(r *http.Request) (string, routing.ParticipantInit, int, error) {
|
||||||
|
claims := GetGrants(r.Context())
|
||||||
|
// require a claim
|
||||||
|
if claims == nil || claims.Video == nil {
|
||||||
|
return "", routing.ParticipantInit{}, http.StatusUnauthorized, rtc.ErrPermissionDenied
|
||||||
|
}
|
||||||
|
|
||||||
|
onlyName, err := EnsureJoinPermission(r.Context())
|
||||||
|
if err != nil {
|
||||||
|
return "", routing.ParticipantInit{}, http.StatusUnauthorized, err
|
||||||
|
}
|
||||||
|
|
||||||
roomName := r.FormValue("room")
|
roomName := r.FormValue("room")
|
||||||
reconnectParam := r.FormValue("reconnect")
|
reconnectParam := r.FormValue("reconnect")
|
||||||
protocolParam := r.FormValue("protocol")
|
protocolParam := r.FormValue("protocol")
|
||||||
@@ -61,10 +71,8 @@ func (s *RTCService) validate(r *http.Request) (string, routing.ParticipantInit,
|
|||||||
// plan b does not work fully at the moment.
|
// plan b does not work fully at the moment.
|
||||||
planBParam := r.FormValue("planb")
|
planBParam := r.FormValue("planb")
|
||||||
|
|
||||||
claims := GetGrants(r.Context())
|
if onlyName != "" {
|
||||||
// require a claim
|
roomName = onlyName
|
||||||
if claims == nil || claims.Video == nil {
|
|
||||||
return "", routing.ParticipantInit{}, http.StatusUnauthorized, rtc.ErrPermissionDenied
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pi := routing.ParticipantInit{
|
pi := routing.ParticipantInit{
|
||||||
@@ -89,15 +97,6 @@ func (s *RTCService) validate(r *http.Request) (string, routing.ParticipantInit,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onlyName, err := EnsureJoinPermission(r.Context())
|
|
||||||
if err != nil {
|
|
||||||
return "", routing.ParticipantInit{}, http.StatusUnauthorized, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if onlyName != "" {
|
|
||||||
roomName = onlyName
|
|
||||||
}
|
|
||||||
|
|
||||||
return roomName, pi, http.StatusOK, nil
|
return roomName, pi, http.StatusOK, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user