GenerateRandomState generates a cryptographically secure random state parameter for OAuth2 flows to prevent CSRF attacks. Returns: - string: A hexadecimal encoded random state string - error: An error if the random generation fails, nil otherwise
()
| 15 | // - string: A hexadecimal encoded random state string |
| 16 | // - error: An error if the random generation fails, nil otherwise |
| 17 | func GenerateRandomState() (string, error) { |
| 18 | bytes := make([]byte, 16) |
| 19 | if _, err := rand.Read(bytes); err != nil { |
| 20 | return "", fmt.Errorf("failed to generate random bytes: %w", err) |
| 21 | } |
| 22 | return hex.EncodeToString(bytes), nil |
| 23 | } |
| 24 | |
| 25 | // OAuthCallback captures the parsed OAuth callback parameters. |
| 26 | type OAuthCallback struct { |
no test coverage detected