Skip to content

Commit 89620a7

Browse files
authored
refactor(oauth2): no need to use io.WriteString when sha256 provides a way to obtain a sum in a single call
1 parent bbfe397 commit 89620a7

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

internal/oauth2/authorization.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package oauth2 // import "miniflux.app/v2/internal/oauth2"
66
import (
77
"crypto/sha256"
88
"encoding/base64"
9-
"io"
109

1110
"golang.org/x/oauth2"
1211

@@ -33,17 +32,14 @@ func (u *Authorization) CodeVerifier() string {
3332

3433
func GenerateAuthorization(config *oauth2.Config) *Authorization {
3534
codeVerifier := crypto.GenerateRandomStringHex(32)
36-
37-
sha2 := sha256.New()
38-
io.WriteString(sha2, codeVerifier)
39-
codeChallenge := base64.RawURLEncoding.EncodeToString(sha2.Sum(nil))
35+
sum := sha256.Sum256([]byte(codeVerifier))
4036

4137
state := crypto.GenerateRandomStringHex(24)
4238

4339
authUrl := config.AuthCodeURL(
4440
state,
4541
oauth2.SetAuthURLParam("code_challenge_method", "S256"),
46-
oauth2.SetAuthURLParam("code_challenge", codeChallenge),
42+
oauth2.SetAuthURLParam("code_challenge", base64.RawURLEncoding.EncodeToString(sum[:])),
4743
)
4844

4945
return &Authorization{

0 commit comments

Comments
 (0)