🐛 Fixed optional code_challenge_method parameter parsing

This commit is contained in:
Maxim Lebedev 2023-12-06 00:33:50 +06:00
parent fa2216a318
commit 803999f201
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
1 changed files with 8 additions and 4 deletions

View File

@ -8,6 +8,7 @@ import (
"crypto/sha256"
"crypto/sha512"
"encoding/base64"
"errors"
"fmt"
"hash"
"strconv"
@ -61,27 +62,30 @@ func ParseCodeChallengeMethod(uid string) (CodeChallengeMethod, error) {
// UnmarshalForm implements custom unmarshler for form values.
func (ccm *CodeChallengeMethod) UnmarshalForm(v []byte) error {
method, err := ParseCodeChallengeMethod(string(v))
parsed, err := ParseCodeChallengeMethod(string(v))
if err != nil {
return fmt.Errorf("CodeChallengeMethod: UnmarshalForm: %w", err)
}
*ccm = method
*ccm = parsed
return nil
}
// UnmarshalJSON implements custom unmarshler for JSON.
func (ccm *CodeChallengeMethod) UnmarshalJSON(v []byte) error {
src, err := strconv.Unquote(string(v))
unquoted, err := strconv.Unquote(string(v))
if err != nil {
return fmt.Errorf("CodeChallengeMethod: UnmarshalJSON: %w", err)
}
if *ccm, err = ParseCodeChallengeMethod(src); err != nil {
parsed, err := ParseCodeChallengeMethod(unquoted)
if err != nil && !errors.Is(err, ErrCodeChallengeMethodUnknown) {
return fmt.Errorf("CodeChallengeMethod: UnmarshalJSON: %w", err)
}
*ccm = parsed
return nil
}