Browse Source

cleanup interaction with external auth

pull/1128/head
aler9 3 years ago
parent
commit
86c5fa9ba4
  1. 11
      internal/core/externalauth.go
  2. 2
      internal/core/hls_muxer.go
  3. 8
      internal/core/rtmp_conn.go
  4. 6
      internal/core/rtsp_conn.go
  5. 4
      internal/core/rtsp_session.go

11
internal/core/externalauth.go

@ -13,7 +13,7 @@ func externalAuth( @@ -13,7 +13,7 @@ func externalAuth(
user string,
password string,
path string,
action string,
isPublishing bool,
query string,
) error {
enc, _ := json.Marshal(struct {
@ -28,8 +28,13 @@ func externalAuth( @@ -28,8 +28,13 @@ func externalAuth(
User: user,
Password: password,
Path: path,
Action: action,
Query: query,
Action: func() string {
if isPublishing {
return "publish"
}
return "read"
}(),
Query: query,
})
res, err := http.Post(ur, "application/json", bytes.NewReader(enc))
if err != nil {

2
internal/core/hls_muxer.go

@ -487,7 +487,7 @@ func (m *hlsMuxer) authenticate(ctx *gin.Context) error { @@ -487,7 +487,7 @@ func (m *hlsMuxer) authenticate(ctx *gin.Context) error {
user,
pass,
m.pathName,
"read",
false,
ctx.Request.URL.RawQuery)
if err != nil {
return pathErrAuthCritical{

8
internal/core/rtmp_conn.go

@ -228,7 +228,7 @@ func (c *rtmpConn) runRead(ctx context.Context, u *url.URL) error { @@ -228,7 +228,7 @@ func (c *rtmpConn) runRead(ctx context.Context, u *url.URL) error {
pathUser conf.Credential,
pathPass conf.Credential,
) error {
return c.authenticate(pathName, pathIPs, pathUser, pathPass, "read", query, rawQuery)
return c.authenticate(pathName, pathIPs, pathUser, pathPass, false, query, rawQuery)
},
})
@ -491,7 +491,7 @@ func (c *rtmpConn) runPublish(ctx context.Context, u *url.URL) error { @@ -491,7 +491,7 @@ func (c *rtmpConn) runPublish(ctx context.Context, u *url.URL) error {
pathUser conf.Credential,
pathPass conf.Credential,
) error {
return c.authenticate(pathName, pathIPs, pathUser, pathPass, "publish", query, rawQuery)
return c.authenticate(pathName, pathIPs, pathUser, pathPass, true, query, rawQuery)
},
})
@ -617,7 +617,7 @@ func (c *rtmpConn) authenticate( @@ -617,7 +617,7 @@ func (c *rtmpConn) authenticate(
pathIPs []fmt.Stringer,
pathUser conf.Credential,
pathPass conf.Credential,
action string,
isPublishing bool,
query url.Values,
rawQuery string,
) error {
@ -628,7 +628,7 @@ func (c *rtmpConn) authenticate( @@ -628,7 +628,7 @@ func (c *rtmpConn) authenticate(
query.Get("user"),
query.Get("pass"),
pathName,
action,
isPublishing,
rawQuery)
if err != nil {
return pathErrAuthCritical{

6
internal/core/rtsp_conn.go

@ -107,7 +107,7 @@ func (c *rtspConn) authenticate( @@ -107,7 +107,7 @@ func (c *rtspConn) authenticate(
pathIPs []fmt.Stringer,
pathUser conf.Credential,
pathPass conf.Credential,
action string,
isPublishing bool,
req *base.Request,
query string,
) error {
@ -128,7 +128,7 @@ func (c *rtspConn) authenticate( @@ -128,7 +128,7 @@ func (c *rtspConn) authenticate(
username,
password,
pathName,
action,
isPublishing,
query)
if err != nil {
c.authFailures++
@ -251,7 +251,7 @@ func (c *rtspConn) onDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx, @@ -251,7 +251,7 @@ func (c *rtspConn) onDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx,
pathUser conf.Credential,
pathPass conf.Credential,
) error {
return c.authenticate(ctx.Path, pathIPs, pathUser, pathPass, "read", ctx.Request, ctx.Query)
return c.authenticate(ctx.Path, pathIPs, pathUser, pathPass, false, ctx.Request, ctx.Query)
},
})

4
internal/core/rtsp_session.go

@ -130,7 +130,7 @@ func (s *rtspSession) onAnnounce(c *rtspConn, ctx *gortsplib.ServerHandlerOnAnno @@ -130,7 +130,7 @@ func (s *rtspSession) onAnnounce(c *rtspConn, ctx *gortsplib.ServerHandlerOnAnno
pathUser conf.Credential,
pathPass conf.Credential,
) error {
return c.authenticate(ctx.Path, pathIPs, pathUser, pathPass, "publish", ctx.Request, ctx.Query)
return c.authenticate(ctx.Path, pathIPs, pathUser, pathPass, true, ctx.Request, ctx.Query)
},
})
@ -190,7 +190,7 @@ func (s *rtspSession) onSetup(c *rtspConn, ctx *gortsplib.ServerHandlerOnSetupCt @@ -190,7 +190,7 @@ func (s *rtspSession) onSetup(c *rtspConn, ctx *gortsplib.ServerHandlerOnSetupCt
pathUser conf.Credential,
pathPass conf.Credential,
) error {
return c.authenticate(ctx.Path, pathIPs, pathUser, pathPass, "read", ctx.Request, ctx.Query)
return c.authenticate(ctx.Path, pathIPs, pathUser, pathPass, false, ctx.Request, ctx.Query)
},
})

Loading…
Cancel
Save