Skip to content

Upg: use proxy for oauth #11540

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions core/src/oauth/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,34 @@ pub struct RefreshResult {
pub trait Provider {
fn id(&self) -> ConnectionProvider;

fn reqwest_client(&self) -> reqwest::Client {
if let (Ok(proxy_host), Ok(proxy_port), Ok(proxy_user_name), Ok(proxy_user_password)) = (
env::var("PROXY_HOST"),
env::var("PROXY_PORT"),
env::var("PROXY_USER_NAME"),
env::var("PROXY_USER_PASSWORD"),
) {
match reqwest::Proxy::all(format!(
"http://{}:{}@{}:{}",
proxy_user_name, proxy_user_password, proxy_host, proxy_port
)) {
Ok(proxy) => match reqwest::Client::builder().proxy(proxy).build() {
Ok(client) => client,
Err(e) => {
error!(error = ?e, "Failed to create client with proxy");
reqwest::Client::new()
}
},
Err(e) => {
error!(error = ?e, "Failed to create proxy, falling back to no proxy");
reqwest::Client::new()
}
}
} else {
reqwest::Client::new()
}
}

async fn finalize(
&self,
connection: &Connection,
Expand Down
6 changes: 4 additions & 2 deletions core/src/oauth/providers/confluence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ impl Provider for ConfluenceConnectionProvider {
"redirect_uri": redirect_uri,
});

let req = reqwest::Client::new()
let req = self
.reqwest_client()
.post("https://auth.atlassian.com/oauth/token")
.header("Content-Type", "application/json")
.json(&body);
Expand Down Expand Up @@ -117,7 +118,8 @@ impl Provider for ConfluenceConnectionProvider {
"refresh_token": refresh_token,
});

let req = reqwest::Client::new()
let req = self
.reqwest_client()
.post("https://auth.atlassian.com/oauth/token")
.header("Content-Type", "application/json")
.json(&body);
Expand Down
3 changes: 2 additions & 1 deletion core/src/oauth/providers/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ impl GithubConnectionProvider {
code: &str,
) -> Result<(String, u64, serde_json::Value), ProviderError> {
// https://github.com/octokit/auth-app.js/blob/main/src/get-installation-authentication.ts
let req = reqwest::Client::new()
let req = self
.reqwest_client()
.post(format!(
"https://api.github.com/app/installations/{}/access_tokens",
code
Expand Down
6 changes: 4 additions & 2 deletions core/src/oauth/providers/gong.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ impl Provider for GongConnectionProvider {
("redirect_uri", &redirect_uri),
];

let req = reqwest::Client::new()
let req = self
.reqwest_client()
.post("https://app.gong.io/oauth2/generate-customer-token")
.header("Content-Type", "application/json")
.header("Authorization", authorization)
Expand Down Expand Up @@ -113,7 +114,8 @@ impl Provider for GongConnectionProvider {
("refresh_token", &refresh_token),
];

let req = reqwest::Client::new()
let req = self
.reqwest_client()
.post("https://app.gong.io/oauth2/generate-customer-token")
.header("Content-Type", "application/json")
.header("Authorization", authorization)
Expand Down
6 changes: 4 additions & 2 deletions core/src/oauth/providers/google_drive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ impl Provider for GoogleDriveConnectionProvider {
"redirect_uri": redirect_uri,
});

let req = reqwest::Client::new()
let req = self
.reqwest_client()
.post("https://oauth2.googleapis.com/token")
.header("Content-Type", "application/json")
.json(&body);
Expand Down Expand Up @@ -124,7 +125,8 @@ impl Provider for GoogleDriveConnectionProvider {
"refresh_token": refresh_token,
});

let req = reqwest::Client::new()
let req = self
.reqwest_client()
.post("https://oauth2.googleapis.com/token")
.header("Content-Type", "application/json")
.json(&body);
Expand Down
3 changes: 2 additions & 1 deletion core/src/oauth/providers/intercom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ impl Provider for IntercomConnectionProvider {
"redirect_uri": redirect_uri,
});

let req = reqwest::Client::new()
let req = self
.reqwest_client()
.post("https://api.intercom.io/auth/eagle/token")
.header("Content-Type", "application/json")
.json(&body);
Expand Down
6 changes: 4 additions & 2 deletions core/src/oauth/providers/microsoft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ impl Provider for MicrosoftConnectionProvider {
"scope": "User.Read Sites.Read.All Directory.Read.All Files.Read.All Team.ReadBasic.All ChannelSettings.Read.All ChannelMessage.Read.All",
});

let req = reqwest::Client::new()
let req = self
.reqwest_client()
.post("https://login.microsoftonline.com/common/oauth2/v2.0/token")
.header("Content-Type", "application/x-www-form-urlencoded")
.form(&body);
Expand Down Expand Up @@ -104,7 +105,8 @@ impl Provider for MicrosoftConnectionProvider {
"scope": "User.Read Sites.Read.All Directory.Read.All Files.Read.All Team.ReadBasic.All ChannelSettings.Read.All ChannelMessage.Read.All",
});

let req = reqwest::Client::new()
let req = self
.reqwest_client()
.post("https://login.microsoftonline.com/common/oauth2/v2.0/token")
.header("Content-Type", "application/x-www-form-urlencoded")
.form(&body);
Expand Down
3 changes: 2 additions & 1 deletion core/src/oauth/providers/notion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ impl Provider for NotionConnectionProvider {
"redirect_uri": redirect_uri,
});

let req = reqwest::Client::new()
let req = self
.reqwest_client()
.post("https://api.notion.com/v1/oauth/token")
.header("Accept", "application/json")
.header("Content-Type", "application/json")
Expand Down
6 changes: 4 additions & 2 deletions core/src/oauth/providers/salesforce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ impl Provider for SalesforceConnectionProvider {
form_data.insert("redirect_uri", redirect_uri);
form_data.insert("code_verifier", code_verifier);

let req = reqwest::Client::new()
let req = self
.reqwest_client()
.post(format!("{}/services/oauth2/token", instance_url))
.header("Content-Type", "application/x-www-form-urlencoded")
.form(&form_data);
Expand Down Expand Up @@ -134,7 +135,8 @@ impl Provider for SalesforceConnectionProvider {
form_data.insert("client_secret", &client_secret);
form_data.insert("refresh_token", &refresh_token);

let req = reqwest::Client::new()
let req = self
.reqwest_client()
.post(format!("{}/services/oauth2/token", instance_url))
.header("Content-Type", "application/x-www-form-urlencoded")
.form(&form_data);
Expand Down
5 changes: 3 additions & 2 deletions core/src/oauth/providers/slack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ impl Provider for SlackConnectionProvider {
code: &str,
redirect_uri: &str,
) -> Result<FinalizeResult, ProviderError> {
let req = reqwest::Client::new()
let req = self
.reqwest_client()
.post("https://slack.com/api/oauth.v2.access")
.header("Content-Type", "application/x-www-form-urlencoded")
.header("Authorization", format!("Basic {}", self.basic_auth()))
Expand Down Expand Up @@ -98,7 +99,7 @@ impl Provider for SlackConnectionProvider {
// .unseal_refresh_token()?
// .ok_or_else(|| anyhow!("Missing `refresh_token` in Slack connection"))?;

// let req = reqwest::Client::new()
// let req = self.reqwest_client()
// .post("https://slack.com/api/oauth.v2.access")
// .header("Authorization", format!("Basic {}", self.basic_auth()))
// .header("Content-Type", "application/json; charset=utf-8")
Expand Down
3 changes: 2 additions & 1 deletion core/src/oauth/providers/zendesk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ impl Provider for ZendeskConnectionProvider {

let url = format!("https://{}.zendesk.com/oauth/tokens", subdomain);

let req = reqwest::Client::new()
let req = self
.reqwest_client()
.post(url)
.header("Content-Type", "application/json")
.json(&body);
Expand Down
Loading