mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-08 04:55:55 +08:00
clear check authorization.
This commit is contained in:
parent
e9b302ad74
commit
d266242887
@ -551,9 +551,3 @@ func formatMemberName(mem *client.GroupMemberInfo) string {
|
|||||||
}
|
}
|
||||||
return fmt.Sprintf("%s(%d)", mem.DisplayName(), mem.Uin)
|
return fmt.Sprintf("%s(%d)", mem.DisplayName(), mem.Uin)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToJSON 生成JSON字符串
|
|
||||||
func (m MSG) ToJSON() string {
|
|
||||||
b, _ := json.Marshal(m)
|
|
||||||
return string(b)
|
|
||||||
}
|
|
||||||
|
@ -97,12 +97,9 @@ func (s *httpServer) ServeHTTP(writer http.ResponseWriter, request *http.Request
|
|||||||
writer.WriteHeader(http.StatusNotFound)
|
writer.WriteHeader(http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if status := checkAuth(request, s.accessToken); status != http.StatusOK {
|
||||||
if s.accessToken != "" {
|
writer.WriteHeader(status)
|
||||||
if status := checkAuth(request, s.accessToken); status != http.StatusOK {
|
return
|
||||||
writer.WriteHeader(status)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
action := strings.TrimPrefix(request.URL.Path, "/")
|
action := strings.TrimPrefix(request.URL.Path, "/")
|
||||||
@ -116,6 +113,10 @@ func (s *httpServer) ServeHTTP(writer http.ResponseWriter, request *http.Request
|
|||||||
}
|
}
|
||||||
|
|
||||||
func checkAuth(req *http.Request, token string) int {
|
func checkAuth(req *http.Request, token string) int {
|
||||||
|
if token == "" { // quick path
|
||||||
|
return http.StatusOK
|
||||||
|
}
|
||||||
|
|
||||||
auth := req.Header.Get("Authorization")
|
auth := req.Header.Get("Authorization")
|
||||||
if auth == "" {
|
if auth == "" {
|
||||||
auth = req.URL.Query().Get("access_token")
|
auth = req.URL.Query().Get("access_token")
|
||||||
@ -126,13 +127,13 @@ func checkAuth(req *http.Request, token string) int {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
switch auth {
|
||||||
case auth == "":
|
case token:
|
||||||
return http.StatusUnauthorized
|
|
||||||
case auth != token:
|
|
||||||
return http.StatusForbidden
|
|
||||||
default:
|
|
||||||
return http.StatusOK
|
return http.StatusOK
|
||||||
|
case "":
|
||||||
|
return http.StatusUnauthorized
|
||||||
|
default:
|
||||||
|
return http.StatusForbidden
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user