feat: util for generating client credentials
This commit is contained in:
9
internal/util/client.go
Normal file
9
internal/util/client.go
Normal file
@ -0,0 +1,9 @@
|
||||
package util
|
||||
|
||||
func GenerateClientID() (string, error) {
|
||||
return generateRandomStringURLSafe(16)
|
||||
}
|
||||
|
||||
func GenerateClientSecret() (string, error) {
|
||||
return generateRandomStringURLSafe(32)
|
||||
}
|
17
internal/util/generate.go
Normal file
17
internal/util/generate.go
Normal file
@ -0,0 +1,17 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// generateRandomStringURLSafe generates a base64 URL-safe random string of n bytes.
|
||||
func generateRandomStringURLSafe(n int) (string, error) {
|
||||
bytes := make([]byte, n)
|
||||
_, err := rand.Read(bytes)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to generate random bytes: %w", err)
|
||||
}
|
||||
return base64.RawURLEncoding.EncodeToString(bytes), nil
|
||||
}
|
Reference in New Issue
Block a user