From b1e0eac90200bcd732eba1faeff310689b90c8e3 Mon Sep 17 00:00:00 2001
From: q191201771 <191201771@qq.com>
Date: Mon, 17 Jan 2022 21:48:03 +0800
Subject: [PATCH] =?UTF-8?q?[fix]=20=E4=BF=AE=E5=A4=8Dsimple=20auth?=
 =?UTF-8?q?=E6=A8=A1=E5=9D=97=E9=87=8Chls=E6=97=A0=E6=B3=95=E5=85=B3?=
 =?UTF-8?q?=E9=97=AD=E9=89=B4=E6=9D=83=E7=9A=84=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 pkg/logic/config.go      |  1 +
 pkg/logic/simple_auth.go | 14 +++++---------
 2 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/pkg/logic/config.go b/pkg/logic/config.go
index a3e5200..91a9cc4 100644
--- a/pkg/logic/config.go
+++ b/pkg/logic/config.go
@@ -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 {
diff --git a/pkg/logic/simple_auth.go b/pkg/logic/simple_auth.go
index 284c899..19d37f2 100644
--- a/pkg/logic/simple_auth.go
+++ b/pkg/logic/simple_auth.go
@@ -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,
@@ -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
 }
 
@@ -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 {
@@ -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
 	}