Skip to content

Commit

Permalink
Merge pull request #10 from UiPath/feature/crypto-rand
Browse files Browse the repository at this point in the history
Use crypto/rand for pkce and state generation
  • Loading branch information
thschmitt authored Jan 12, 2023
2 parents bdc5e19 + d6d1529 commit fcb6872
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions auth/secret_generator.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package auth

import (
"crypto/rand"
"crypto/sha256"
"encoding/base64"
"fmt"
"math/rand"
"strings"
"time"
)

type SecretGenerator struct{}
Expand All @@ -33,8 +32,10 @@ func (g SecretGenerator) base64Encode(value []byte) string {
}

func (g SecretGenerator) randomString(length int) string {
rand.Seed(time.Now().UnixNano())
b := make([]byte, length)
rand.Read(b)
_, err := rand.Read(b)
if err != nil {
panic(fmt.Errorf("Could not get cryptographically secure random numbers: %v", err))
}
return fmt.Sprintf("%x", b)[:length]
}

0 comments on commit fcb6872

Please sign in to comment.