mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 04:50:52 +08:00
Add OAuth support for Gemini CLI, Claude, Codex, and Qwen authentication
- Implemented new handlers (`RequestGeminiCLIToken`, `RequestAnthropicToken`, `RequestCodexToken`, `RequestQwenToken`) for initiating OAuth flows. - Added endpoints for authorization URLs in management API. - Extracted `GenerateRandomState` to a reusable utility in `misc` package. - Refactored related logic in `openai_login.go` and `anthropic_login.go` for consistency. Add endpoints for initiating OAuth flows in management API documentation - Documented new endpoints for Anthropic, Codex, Gemini CLI, and Qwen login URLs. - Provided request and response examples for each endpoint in both English and Chinese versions.
This commit is contained in:
21
internal/misc/oauth.go
Normal file
21
internal/misc/oauth.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package misc
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// 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
|
||||
func GenerateRandomState() (string, error) {
|
||||
bytes := make([]byte, 16)
|
||||
if _, err := rand.Read(bytes); err != nil {
|
||||
return "", fmt.Errorf("failed to generate random bytes: %w", err)
|
||||
}
|
||||
return hex.EncodeToString(bytes), nil
|
||||
}
|
||||
Reference in New Issue
Block a user