Skip to content
Merged
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
18 changes: 17 additions & 1 deletion src/handlers/openid_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use crate::{
auth::{AccessUserInfo, SessionInfo},
db::{
models::{auth_code::AuthCode, oauth2client::OAuth2Client},
DbPool, OAuth2AuthorizedApp, OAuth2Token, Session, User,
DbPool, OAuth2AuthorizedApp, OAuth2Token, Session, SessionState, User,
},
error::WebError,
handlers::{mail::send_new_device_ocid_login_email, SIGN_IN_COOKIE_NAME},
Expand Down Expand Up @@ -402,6 +402,22 @@ pub async fn authorization(
let _result = session.delete(&appstate.pool).await;
login_redirect(&data, private_cookies).await
} else {
let user = User::find_by_id(&appstate.pool, session.user_id)
.await?
.ok_or(WebError::Authorization("User not found".into()))?;

// Session exists even if user hasn't completed MFA verification yet,
// thus we need to check if MFA is enabled and the verification is done.
if user.mfa_enabled
&& session.state != SessionState::MultiFactorVerified
{
info!(
"MFA not verified for user id {}, redirecting to login",
session.user_id
);
return login_redirect(&data, private_cookies).await;
}

// If session is present check if app is in user authorized apps.
// If yes return auth code and state else redirect to consent form.
if let Some(app) =
Expand Down