Auth fixes (#664)

* Auth fixes

* destroy flows after use

* fix comp err

* add bearer err msg
This commit is contained in:
Geometrically
2023-08-04 16:22:15 -07:00
committed by GitHub
parent 039d26feeb
commit ca0468b8d5
6 changed files with 19 additions and 7 deletions

View File

@@ -1197,6 +1197,7 @@ pub async fn login_from_minecraft(
access_token: token,
}) = flow
{
Flow::remove(&login.flow, &redis).await?;
let provider = AuthProvider::Microsoft;
let oauth_user = provider.get_user(&token).await?;
let user_id_opt = provider.get_user_id(&oauth_user.id, &**client).await?;

View File

@@ -64,6 +64,12 @@ pub async fn route(
x.value_mut().clone()
};
ws_conn_try!(
"Removing login flow" StatusCode::INTERNAL_SERVER_ERROR,
Flow::remove(code, &redis).await
=> ws_conn
);
let access_token = ws_conn_try!(
"OAuth token exchange" StatusCode::INTERNAL_SERVER_ERROR,
stages::access_token::fetch_token(
@@ -122,7 +128,7 @@ pub async fn route(
let flow = &ws_conn_try!(
"Error creating microsoft login request flow." StatusCode::INTERNAL_SERVER_ERROR,
Flow::MicrosoftLogin {
access_token: bearer_token.clone(),
access_token: access_token.access_token.clone(),
}
.insert(Duration::hours(1), &redis)
.await

View File

@@ -22,6 +22,6 @@ pub async fn fetch_bearer(token: &str, uhs: &str) -> Result<String, Authenticati
.and_then(serde_json::Value::as_str)
.map(String::from)
.ok_or(AuthenticationError::Custom(
"Response didn't contain valid bearer token".to_string(),
format!("Response didn't contain valid bearer token. body: {body}"),
))
}