mirror of
https://github.com/openai/codex.git
synced 2026-11-16 22:00:36 +00:00
Add request-scoped OAuth credentials and session lifecycle APIs (#56036)
## What changed - Add `OAuthSessionRequest` to pair access tokens with their authorization identity and retain rejected-token recovery across transient failures and retries. New sign-ins receive an identity that survives token refresh. - Expose explicit login, logout, and authorization identity lookup, plus a per-manager option to disable automatic browser login while allowing credential reuse and refresh. - Move serializable `OAuthSessionConfig` into `codex-model-provider-info`, add an optional `device_authorization_url` field, and share endpoint URL validation through `codex-http-client`. - Distinguish permission failures, transient token endpoint failures, and invalid responses using `io::ErrorKind`. ## Testing Add coverage for sign-in identity preservation through refresh retries, removal of saved and cached credentials on logout, and suppression of automatic browser login. Extend token endpoint error classification coverage. GitOrigin-RevId: ae9f72e787171e179fe139a3b840a9f7e1e46506
This commit is contained in:
@@ -25,6 +25,7 @@ thiserror = { workspace = true }
|
||||
tokio = { workspace = true, features = ["macros", "rt", "time", "sync"] }
|
||||
tracing = { workspace = true }
|
||||
tracing-opentelemetry = { workspace = true }
|
||||
url = { workspace = true }
|
||||
zstd = { workspace = true }
|
||||
|
||||
[target.'cfg(target_os = "macos")'.dependencies]
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
use url::Host;
|
||||
use url::Url;
|
||||
|
||||
mod chatgpt_cloudflare_cookies;
|
||||
mod chatgpt_hosts;
|
||||
mod client;
|
||||
@@ -83,3 +86,26 @@ pub use crate::windows_proxy_auth::WindowsProxyTls;
|
||||
pub use crate::windows_proxy_auth::connect_windows_proxy;
|
||||
#[cfg(windows)]
|
||||
pub use crate::windows_tls::build_windows_platform_tls_config;
|
||||
|
||||
/// Validates HTTPS or loopback HTTP endpoints, rejecting userinfo and fragments.
|
||||
/// Errors identify the caller-supplied field without including the URL.
|
||||
pub fn validate_endpoint_url(value: &str, field: &str) -> Result<Url, String> {
|
||||
let url = Url::parse(value).map_err(|_| format!("invalid {field} URL"))?;
|
||||
let loopback = match url.host() {
|
||||
Some(Host::Domain(host)) => host.eq_ignore_ascii_case("localhost"),
|
||||
Some(Host::Ipv4(host)) => host.is_loopback(),
|
||||
Some(Host::Ipv6(host)) => host.is_loopback(),
|
||||
None => false,
|
||||
};
|
||||
if url.host().is_none()
|
||||
|| !url.username().is_empty()
|
||||
|| url.password().is_some()
|
||||
|| url.fragment().is_some()
|
||||
|| !(url.scheme() == "https" || (url.scheme() == "http" && loopback))
|
||||
{
|
||||
return Err(format!(
|
||||
"{field} must use HTTPS (or loopback HTTP), without userinfo or a fragment"
|
||||
));
|
||||
}
|
||||
Ok(url)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user