1
This commit is contained in:
@@ -24,6 +24,12 @@ func init() {
|
|||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FixedAuthURL 固定的授权 URL(用于测试,绕过 S2A)
|
||||||
|
const FixedAuthURL = "https://auth.openai.com/oauth/authorize?client_id=app_EMoamEEZ73f0CkXaXp7hrann&code_challenge=fEepJO0_NJiqP-_FC_HLH-aqZsq68JeFtNvYY6q3qbQ&code_challenge_method=S256&codex_cli_simplified_flow=true&id_token_add_organizations=true&redirect_uri=http%3A%2F%2Flocalhost%3A1455%2Fauth%2Fcallback&response_type=code&scope=openid+profile+email+offline_access&state=da3ec35b7368c91193d27c90e3ecd0c4fa45bebd430bcc6b5c236461d2742e93"
|
||||||
|
|
||||||
|
// UseFixedAuthURL 是否使用固定的授权 URL(设为 true 可绕过 S2A 进行测试)
|
||||||
|
var UseFixedAuthURL = false
|
||||||
|
|
||||||
// 常量 CodexClientID, CodexRedirectURI, CodexScope 已在 s2a.go 中定义
|
// 常量 CodexClientID, CodexRedirectURI, CodexScope 已在 s2a.go 中定义
|
||||||
|
|
||||||
// CodexAPIAuth 纯 API 授权 (无浏览器) - 基于 get_code.go 的实现
|
// CodexAPIAuth 纯 API 授权 (无浏览器) - 基于 get_code.go 的实现
|
||||||
@@ -377,8 +383,12 @@ func (c *CodexAPIAuth) GetSessionID() string {
|
|||||||
func (c *CodexAPIAuth) ObtainAuthorizationCode() (string, error) {
|
func (c *CodexAPIAuth) ObtainAuthorizationCode() (string, error) {
|
||||||
c.logStep(StepNavigate, "开始 Codex API 授权流程...")
|
c.logStep(StepNavigate, "开始 Codex API 授权流程...")
|
||||||
|
|
||||||
// 使用 S2A 生成的授权 URL(不再自己生成 PKCE 参数)
|
// 选择使用固定 URL 还是 S2A 生成的 URL
|
||||||
if c.authURL == "" {
|
authURL := c.authURL
|
||||||
|
if UseFixedAuthURL {
|
||||||
|
authURL = FixedAuthURL
|
||||||
|
c.logStep(StepNavigate, "使用固定授权 URL(测试模式)")
|
||||||
|
} else if authURL == "" {
|
||||||
return "", fmt.Errorf("authURL 未设置,请先通过 S2A 生成授权 URL")
|
return "", fmt.Errorf("authURL 未设置,请先通过 S2A 生成授权 URL")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -390,14 +400,14 @@ func (c *CodexAPIAuth) ObtainAuthorizationCode() (string, error) {
|
|||||||
|
|
||||||
// 访问授权页面并手动跟随重定向
|
// 访问授权页面并手动跟随重定向
|
||||||
c.logStep(StepNavigate, "访问授权页面...")
|
c.logStep(StepNavigate, "访问授权页面...")
|
||||||
resp, _, err := c.doRequest("GET", c.authURL, nil, headers)
|
resp, _, err := c.doRequest("GET", authURL, nil, headers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.logError(StepNavigate, "访问授权页失败: %v", err)
|
c.logError(StepNavigate, "访问授权页失败: %v", err)
|
||||||
return "", fmt.Errorf("访问授权页失败: %v", err)
|
return "", fmt.Errorf("访问授权页失败: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 手动跟随重定向
|
// 手动跟随重定向
|
||||||
currentURL := c.authURL
|
currentURL := authURL
|
||||||
for resp.StatusCode >= 300 && resp.StatusCode < 400 {
|
for resp.StatusCode >= 300 && resp.StatusCode < 400 {
|
||||||
location := resp.Header.Get("Location")
|
location := resp.Header.Get("Location")
|
||||||
if location == "" {
|
if location == "" {
|
||||||
|
|||||||
Reference in New Issue
Block a user