feat: 优化web

This commit is contained in:
2026-04-23 18:58:13 +08:00
commit 544a2f3428
160 changed files with 27327 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
package oauth2
import (
"crypto/sha256"
"crypto/subtle"
"encoding/base64"
"strings"
)
// VerifyPKCES256 校验 code_verifier 是否与 code_challengeS256)一致。
func VerifyPKCES256(codeVerifier, codeChallenge string) bool {
if codeVerifier == "" || codeChallenge == "" {
return false
}
sum := sha256.Sum256([]byte(codeVerifier))
expected := base64.RawURLEncoding.EncodeToString(sum[:])
return subtle.ConstantTimeCompare([]byte(expected), []byte(codeChallenge)) == 1
}
// NormalizeCodeChallengeMethod 返回小写方法名;仅支持 S256(OAuth 2.1 推荐)。
func NormalizeCodeChallengeMethod(m string) string {
return strings.TrimSpace(strings.ToLower(m))
}