Skip to content

Commit ed740cf

Browse files
committed
fix(auth): fix old auth being broken
1 parent 8d47e99 commit ed740cf

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

src/endpoints/auth/github.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use actix_web::{dev::ConnectionInfo, post, web, Responder};
1+
use actix_web::http::StatusCode;
2+
use actix_web::{dev::ConnectionInfo, post, web, HttpResponse, Responder};
23
use serde::Deserialize;
34
use sqlx::{types::ipnetwork::IpNetwork, Acquire};
45
use uuid::Uuid;
@@ -125,7 +126,7 @@ pub async fn github_web_callback(
125126
error: "".to_string(),
126127
payload: TokensResponse {
127128
access_token: token.to_string(),
128-
refresh_token: Some(refresh.to_string()),
129+
refresh_token: refresh.to_string(),
129130
},
130131
}))
131132
}
@@ -212,13 +213,20 @@ pub async fn poll_github_login(
212213

213214
tx.commit().await.or(Err(ApiError::TransactionError))?;
214215

215-
Ok(web::Json(ApiResponse {
216-
error: "".to_string(),
217-
payload: TokensResponse {
218-
access_token: token.to_string(),
219-
refresh_token: refresh.map(|r| r.to_string()),
220-
},
221-
}))
216+
if expiry {
217+
Ok(HttpResponse::build(StatusCode::OK).json(ApiResponse {
218+
error: "".to_string(),
219+
payload: TokensResponse {
220+
access_token: token.to_string(),
221+
refresh_token: refresh.unwrap().to_string(),
222+
},
223+
}))
224+
} else {
225+
Ok(HttpResponse::build(StatusCode::OK).json(ApiResponse {
226+
error: "".to_string(),
227+
payload: token.to_string(),
228+
}))
229+
}
222230
}
223231

224232
#[post("v1/login/github/token")]
@@ -232,11 +240,12 @@ pub async fn github_token_login(
232240
);
233241

234242
let user = match client.get_user(&json.token).await {
235-
Err(_) => client.get_installation(&json.token).await.map_err(|_|
236-
ApiError::BadRequest(format!("Invalid access token: {}", json.token))
237-
)?,
243+
Err(_) => client
244+
.get_installation(&json.token)
245+
.await
246+
.map_err(|_| ApiError::BadRequest(format!("Invalid access token: {}", json.token)))?,
238247

239-
Ok(u) => u
248+
Ok(u) => u,
240249
};
241250

242251
let mut pool = data

src/endpoints/auth/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ pub mod github;
1212
#[derive(Serialize)]
1313
struct TokensResponse {
1414
access_token: String,
15-
#[serde(skip_serializing_if = "Option::is_none")]
16-
refresh_token: Option<String>,
15+
refresh_token: String,
1716
}
1817

1918
#[derive(Deserialize)]
@@ -60,7 +59,7 @@ pub async fn refresh_token(
6059
error: "".into(),
6160
payload: TokensResponse {
6261
access_token: new_auth.to_string(),
63-
refresh_token: Some(new_refresh.to_string()),
62+
refresh_token: new_refresh.to_string(),
6463
},
6564
}))
6665
}

src/types/models/github_login_attempt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub struct StoredLoginAttempt {
1414
#[serde(skip_serializing)]
1515
pub device_code: String,
1616
pub uri: String,
17-
#[serde(skip_serializing, alias = "code")]
17+
#[serde(rename = "code")]
1818
pub user_code: String,
1919
pub interval: i32,
2020
#[serde(skip_serializing)]

0 commit comments

Comments
 (0)