Skip to content

Commit

Permalink
[fix] 修复simple auth模块里hls无法关闭鉴权的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
q191201771 committed Jan 17, 2022
1 parent 1106c33 commit b1e0eac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
1 change: 1 addition & 0 deletions pkg/logic/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ type SimpleAuthConfig struct {
SubHttptsEnable bool `json:"sub_httpts_enable"`
PubRtspEnable bool `json:"pub_rtsp_enable"`
SubRtspEnable bool `json:"sub_rtsp_enable"`
HlsM3u8Enable bool `json:"hls_m3u8_enable"`
}

type PprofConfig struct {
Expand Down
14 changes: 5 additions & 9 deletions pkg/logic/simple_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,9 @@ func SimpleAuthCalcSecret(key string, streamName string) string {
const secretName = "lal_secret"

type SimpleAuthCtx struct {
key string
config SimpleAuthConfig
}

// NewSimpleAuthCtx
//
// @param key: 如果为空,则所有鉴权接口都返回成功
//
func NewSimpleAuthCtx(config SimpleAuthConfig) *SimpleAuthCtx {
return &SimpleAuthCtx{
config: config,
Expand All @@ -46,7 +41,6 @@ func (s *SimpleAuthCtx) OnPubStart(info base.PubStartInfo) error {
s.config.PubRtspEnable && info.Protocol == base.ProtocolRtsp {
return s.check(info.StreamName, info.UrlParam)
}

return nil
}

Expand All @@ -57,12 +51,14 @@ func (s *SimpleAuthCtx) OnSubStart(info base.SubStartInfo) error {
(s.config.SubRtspEnable && info.Protocol == base.ProtocolRtsp) {
return s.check(info.StreamName, info.UrlParam)
}

return nil
}

func (s *SimpleAuthCtx) OnHls(streamName string, urlParam string) error {
return s.check(streamName, urlParam)
if s.config.HlsM3u8Enable {
return s.check(streamName, urlParam)
}
return nil
}

func (s *SimpleAuthCtx) check(streamName string, urlParam string) error {
Expand All @@ -82,7 +78,7 @@ func (s *SimpleAuthCtx) check(streamName string, urlParam string) error {
}

se := SimpleAuthCalcSecret(s.config.Key, streamName)
if v == se {
if v == se {
return nil
}

Expand Down

0 comments on commit b1e0eac

Please sign in to comment.