(Feat): Initial Commit
Some checks failed
Build & Test / build-test (push) Has been cancelled
Build & Test / swagger-codegen-cli (push) Has been cancelled
CodeQL / Analyze (go) (push) Has been cancelled

This commit is contained in:
2026-07-03 19:41:31 +05:30
commit 7e940c83a7
461 changed files with 45002 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
package oauth2
import (
"crypto/sha256"
"encoding/base64"
"fmt"
"allaboutapps.dev/aw/go-starter/internal/util"
)
const (
defaultVerifierLength = 128
)
func GetPKCECodeVerifier() (string, error) {
// for details regarding possible characters in verifier, see:
// https://tools.ietf.org/html/rfc7636#section-4.1
verifier, err := util.GenerateRandomString(defaultVerifierLength, []util.CharRange{util.CharRangeNumeric, util.CharRangeAlphaLowerCase, util.CharRangeAlphaUpperCase}, "-._~")
if err != nil {
return "", fmt.Errorf("failed to generate random string: %w", err)
}
return verifier, nil
}
func GetPKCECodeChallengeS256(verifier string) string {
// for details regarding transformation of verifier to challenge see:
// https://tools.ietf.org/html/rfc7636#section-4.2
// base64 encoding must be unpadded, URL encoding:
// https://tools.ietf.org/html/rfc7636#page-17
sum := sha256.Sum256([]byte(verifier))
b64 := base64.RawURLEncoding.EncodeToString(sum[:])
return b64
}