MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / checkTelegramAuthorization

Function checkTelegramAuthorization

controller/telegram.go:100–124  ·  view source on GitHub ↗
(params map[string][]string, token string)

Source from the content-addressed store, hash-verified

98}
99
100func checkTelegramAuthorization(params map[string][]string, token string) bool {
101 strs := []string{}
102 var hash = ""
103 for k, v := range params {
104 if k == "hash" {
105 hash = v[0]
106 continue
107 }
108 strs = append(strs, k+"="+v[0])
109 }
110 sort.Strings(strs)
111 var imploded = ""
112 for _, s := range strs {
113 if imploded != "" {
114 imploded += "\n"
115 }
116 imploded += s
117 }
118 sha256hash := sha256.New()
119 io.WriteString(sha256hash, token)
120 hmachash := hmac.New(sha256.New, sha256hash.Sum(nil))
121 io.WriteString(hmachash, imploded)
122 ss := hex.EncodeToString(hmachash.Sum(nil))
123 return hash == ss
124}

Callers 2

TelegramBindFunction · 0.85
TelegramLoginFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected