diff options
| author | 2025-04-07 16:14:41 +0200 | |
|---|---|---|
| committer | 2025-04-07 16:14:41 +0200 | |
| commit | 365b5753419238bb96bc3f9b744d380ff20cbafc (patch) | |
| tree | 6b8e8b605c4cddeb6e3bc0f574ffbc856657e56c /vendor/github.com/pquerna/otp/internal/encode.go | |
| parent | [bugfix] Don't assume `"manuallyApprovesFollowers": true` if not set (#3978) (diff) | |
| download | gotosocial-365b5753419238bb96bc3f9b744d380ff20cbafc.tar.xz | |
[feature] add TOTP two-factor authentication (2FA) (#3960)
* [feature] add TOTP two-factor authentication (2FA)
* use byteutil.S2B to avoid allocations when comparing + generating password hashes
* don't bother with string conversion for consts
* use io.ReadFull
* use MustGenerateSecret for backup codes
* rename util functions
Diffstat (limited to 'vendor/github.com/pquerna/otp/internal/encode.go')
| -rw-r--r-- | vendor/github.com/pquerna/otp/internal/encode.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/vendor/github.com/pquerna/otp/internal/encode.go b/vendor/github.com/pquerna/otp/internal/encode.go new file mode 100644 index 000000000..2af3c8bc0 --- /dev/null +++ b/vendor/github.com/pquerna/otp/internal/encode.go @@ -0,0 +1,35 @@ +package internal + +import ( + "net/url" + "sort" + "strings" +) + +// EncodeQuery is a copy-paste of url.Values.Encode, except it uses %20 instead +// of + to encode spaces. This is necessary to correctly render spaces in some +// authenticator apps, like Google Authenticator. +func EncodeQuery(v url.Values) string { + if v == nil { + return "" + } + var buf strings.Builder + keys := make([]string, 0, len(v)) + for k := range v { + keys = append(keys, k) + } + sort.Strings(keys) + for _, k := range keys { + vs := v[k] + keyEscaped := url.PathEscape(k) // changed from url.QueryEscape + for _, v := range vs { + if buf.Len() > 0 { + buf.WriteByte('&') + } + buf.WriteString(keyEscaped) + buf.WriteByte('=') + buf.WriteString(url.PathEscape(v)) // changed from url.QueryEscape + } + } + return buf.String() +} |
