Skip to content

Commit

Permalink
feat(auth): Optimize login requests
Browse files Browse the repository at this point in the history
  • Loading branch information
0x676e67 committed Nov 26, 2023
1 parent 7ffbee5 commit ffcd2c9
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Reverse engineered `ChatGPT` proxy (bypass Cloudflare 403 Access Denied)
### Installation

If you need more detailed installation and usage information, please check [Installation Document](https://github.com/gngpp/ninja/blob/main/doc/readme.md))
If you need more detailed installation and usage information, please check [Installation Document](https://github.com/gngpp/ninja/blob/main/doc/readme.md)

- Platform

Expand Down
2 changes: 1 addition & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
### 安装

如果您需要更详细的安装与使用信息,请查看[安装文档](https://github.com/gngpp/ninja/blob/main/doc/readme_zh.md))
如果您需要更详细的安装与使用信息,请查看[安装文档](https://github.com/gngpp/ninja/blob/main/doc/readme_zh.md)

### 贡献

Expand Down
46 changes: 23 additions & 23 deletions openai/src/auth/error.rs
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
#[derive(thiserror::Error, Debug)]
pub enum AuthError {
#[error("bad request (error {0:?})")]
#[error("Bad request (error {0:?})")]
BadRequest(String),
#[error("too many requests (error {0:?})")]
#[error("Too many requests (error {0:?})")]
TooManyRequests(String),
#[error("Unauthorized request (error {0:?})")]
Unauthorized(String),
#[error("Server error ({0:?})")]
ServerError(String),
#[error("failed login")]
#[error("Failed login")]
FailedLogin,
#[error(transparent)]
FailedRequest(#[from] reqwest::Error),
#[error("invalid client request (error {0:?})")]
InvalidClientRequest(String),
#[error("failed to get access token (error {0:?})")]
#[error("Failed to get access token (error {0:?})")]
FailedAccessToken(String),
#[error("invalid arkose token ({0:?})")]
InvalidArkoseToken(anyhow::Error),
#[error("failed get code from callback url")]
#[error("Failed get code from callback url")]
FailedCallbackCode,
#[error("failed callback url")]
#[error("Failed callback url")]
FailedCallbackURL,
#[error("failed to get authorized url")]
#[error("Failed to get authorized url")]
FailedAuthorizedUrl,
#[error("Failed to get state")]
FailedState,
#[error("failed get csrf token")]
#[error("Failed get csrf token")]
FailedCsrfToken,
#[error("failed to get auth session cookie")]
#[error("Failed to get auth session cookie")]
FailedAuthSessionCookie,
#[error("invalid request login url (error {0:?})")]
#[error("Invalid client request (error {0:?})")]
InvalidClientRequest(String),
#[error("Invalid arkose token ({0:?})")]
InvalidArkoseToken(anyhow::Error),
#[error("Invalid request login url (error {0:?})")]
InvalidLoginUrl(String),
#[error("invalid email or password")]
#[error("Invalid email or password")]
InvalidEmailOrPassword,
#[error("invalid request (error {0:?})")]
#[error("Invalid request (error {0:?})")]
InvalidRequest(String),
#[error("invalid email")]
#[error("Invalid email")]
InvalidEmail,
#[error("invalid Location")]
#[error("Invalid Location")]
InvalidLocation,
#[error("invalid refresh token")]
#[error("Invalid refresh token")]
InvalidRefreshToken,
#[error("invalid location path")]
#[error("Accidentally jumped back to the login homepage, please try again.")]
InvalidLocationPath,
#[error("MFA failed")]
MFAFailed,
#[error("MFA required")]
MFARequired,
#[error("json deserialize error (error {0:?})")]
#[error("Json deserialize error (error {0:?})")]
DeserializeError(String),
#[error("implementation is not supported")]
#[error("Implementation is not supported")]
NotSupportedImplementation,
#[error("failed to get preauth cookie")]
#[error("Failed to get preauth cookie")]
PreauthCookieNotFound,
}
10 changes: 9 additions & 1 deletion openai/src/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,15 @@ impl AuthClientBuilder {
AuthClientBuilder {
inner: Client::builder()
.danger_accept_invalid_certs(true)
.connect_timeout(Duration::from_secs(30))
.connect_timeout(Duration::from_secs(10))
.timeout(Duration::from_secs(30))
.default_headers({
let mut headers = HeaderMap::new();
headers.insert(header::DNT, HeaderValue::from_static("1"));
headers.insert(header::ORIGIN, HeaderValue::from_static(OPENAI_OAUTH_URL));
headers.insert(header::REFERER, HeaderValue::from_static(OPENAI_OAUTH_URL));
headers
})
.redirect(Policy::none()),
}
}
Expand Down
2 changes: 2 additions & 0 deletions openai/src/auth/provide/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ impl<'a> RequestContext<'a> {

self.cookie
.insert(format!("arkoseToken={}", arkose_token.value()));
self.cookie
.insert(format!("arkose_token={}", arkose_token.value()));
Ok(())
}
}
Expand Down
2 changes: 1 addition & 1 deletion openai/src/token/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub async fn await_check_for_u8(token: &[u8]) -> TokenResult<Option<TokenProfile
#[cfg(feature = "remote-token")]
pub fn await_check(token: &str) -> TokenResult<Option<TokenProfile>> {
let token = token.trim_start_matches("Bearer ");
if token.starts_with("sk-") || token.starts_with("sess-") {
if check_sk_or_sess(token) {
return Ok(None);
}
let key_result = keys().await?;
Expand Down

0 comments on commit ffcd2c9

Please sign in to comment.