mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-23 00:00:33 +00:00
fix(frontend): get refresh token for google services
This commit is contained in:
+18
-19
@@ -185,9 +185,19 @@ pub fn build_basic_client(
|
||||
login: bool,
|
||||
base_url: &str,
|
||||
) -> (String, OClient) {
|
||||
let auth_url = Url::parse(&config.auth_url).expect("Invalid authorization endpoint URL");
|
||||
let mut auth_url = Url::parse(&config.auth_url).expect("Invalid authorization endpoint URL");
|
||||
let token_url = Url::parse(&config.token_url).expect("Invalid token endpoint URL");
|
||||
|
||||
if ["gcal", "gdrive", "gsheets", "gcloud", "gmail"]
|
||||
.into_iter()
|
||||
.any(|x| x == name)
|
||||
{
|
||||
auth_url
|
||||
.query_pairs_mut()
|
||||
.append_pair("access_type", "offline")
|
||||
.append_pair("prompt", "consent");
|
||||
}
|
||||
|
||||
let redirect_url = if login {
|
||||
format!("{base_url}/user/login_callback/{name}")
|
||||
} else {
|
||||
@@ -500,8 +510,7 @@ async fn connect_callback(
|
||||
.to_owned();
|
||||
|
||||
let token_response =
|
||||
exchange_code::<TokenResponse>(callback, &cookies, client, &http_client, &client_name)
|
||||
.await?;
|
||||
exchange_code::<TokenResponse>(callback, &cookies, client, &http_client).await?;
|
||||
|
||||
Ok(Json(token_response))
|
||||
}
|
||||
@@ -518,8 +527,7 @@ async fn connect_slack_callback(
|
||||
.ok_or_else(|| error::Error::BadRequest("slack client not setup".to_string()))?
|
||||
.to_owned();
|
||||
let token =
|
||||
exchange_code::<SlackTokenResponse>(callback, &cookies, client, &http_client, "slack")
|
||||
.await?;
|
||||
exchange_code::<SlackTokenResponse>(callback, &cookies, client, &http_client).await?;
|
||||
|
||||
Ok(Json(token))
|
||||
}
|
||||
@@ -686,9 +694,7 @@ async fn login_callback(
|
||||
.ok_or_else(|| error::Error::BadRequest("invalid client".to_string()))?
|
||||
.client)
|
||||
.to_owned();
|
||||
let token_res =
|
||||
exchange_code::<TokenResponse>(callback, &cookies, client, &http_client, "no_refresh")
|
||||
.await;
|
||||
let token_res = exchange_code::<TokenResponse>(callback, &cookies, client, &http_client).await;
|
||||
|
||||
if let Ok(token) = token_res {
|
||||
let token = &token.access_token.to_string();
|
||||
@@ -765,7 +771,6 @@ async fn exchange_code<T: DeserializeOwned>(
|
||||
cookies: &Cookies,
|
||||
client: OClient,
|
||||
http_client: &Client,
|
||||
client_name: &str,
|
||||
) -> error::Result<T> {
|
||||
let csrf_state = cookies
|
||||
.get("csrf")
|
||||
@@ -774,16 +779,9 @@ async fn exchange_code<T: DeserializeOwned>(
|
||||
if callback.state != csrf_state {
|
||||
return Err(error::Error::BadRequest("csrf did not match".to_string()));
|
||||
}
|
||||
let mut refresh_client = client.exchange_code(callback.code);
|
||||
if ["gcal", "gdrive", "gsheets", "gcloud", "gmail"]
|
||||
.into_iter()
|
||||
.any(|x| x == client_name)
|
||||
{
|
||||
refresh_client = refresh_client
|
||||
.param("access_type", "offline")
|
||||
.param("prompt", "consent");
|
||||
}
|
||||
refresh_client
|
||||
|
||||
client
|
||||
.exchange_code(callback.code)
|
||||
.with_client(http_client)
|
||||
.execute::<T>()
|
||||
.await
|
||||
@@ -908,6 +906,7 @@ fn oauth_redirect(
|
||||
for scope in scopes_iter.iter() {
|
||||
client.add_scope(scope);
|
||||
}
|
||||
|
||||
let url = client.authorize_url(&state);
|
||||
set_cookie(&state, cookies);
|
||||
Ok(Redirect::to(url.as_str()))
|
||||
|
||||
Reference in New Issue
Block a user