Skip to content

Commit

Permalink
fix(webserver): properly generate oauth error string for frontend (#1532
Browse files Browse the repository at this point in the history
)

* fix(webserver): properly generate oauth error string for frontend

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
wsxiaoys and autofix-ci[bot] authored Feb 24, 2024
1 parent e45dbb3 commit 0350a7f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
31 changes: 14 additions & 17 deletions ee/tabby-webserver/src/oauth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ async fn google_oauth_handler(
Query(param): Query<GoogleOAuthQueryParam>,
) -> Redirect {
if !param.error.is_empty() {
return make_error_redirect(OAuthProvider::Google, &param.error);
return make_error_redirect(OAuthProvider::Google, param.error);
}
match_auth_result(
OAuthProvider::Google,
Expand All @@ -140,26 +140,23 @@ fn match_auth_result(
);
Redirect::temporary(&uri)
}
Err(OAuthError::InvalidVerificationCode) => {
make_error_redirect(provider, "Invalid oauth code")
}
Err(OAuthError::CredentialNotActive) => {
make_error_redirect(provider, "OAuth is not enabled")
}
Err(OAuthError::UserNotInvited) => make_error_redirect(
provider,
"User is not invited, please contact your admin for help",
),
Err(e) => {
error!("Failed to authenticate: {:?}", e);
make_error_redirect(provider, "Unknown error")
}
Err(err) => match err {
OAuthError::InvalidVerificationCode
| OAuthError::UserNotInvited
| OAuthError::UserDisabled
| OAuthError::CredentialNotActive
| OAuthError::Unknown => make_error_redirect(provider, err.to_string()),
OAuthError::Other(e) => {
error!("Failed to authenticate: {:?}", e);
make_error_redirect(provider, OAuthError::Unknown.to_string())
}
},
}
}

fn make_error_redirect(provider: OAuthProvider, message: &str) -> Redirect {
fn make_error_redirect(provider: OAuthProvider, message: String) -> Redirect {
let query = querystring::stringify(vec![
("error_message", urlencoding::encode(message).as_ref()),
("error_message", urlencoding::encode(&message).as_ref()),
(
"provider",
serde_json::to_string(&provider).unwrap().as_str(),
Expand Down
8 changes: 4 additions & 4 deletions ee/tabby-webserver/src/schema/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,16 @@ pub struct OAuthResponse {

#[derive(Error, Debug)]
pub enum OAuthError {
#[error("The code passed is incorrect or expired")]
#[error("The oauth code passed is incorrect or expired")]
InvalidVerificationCode,

#[error("The credential is not active")]
#[error("OAuth is not enabled")]
CredentialNotActive,

#[error("The user is not invited to access the system")]
#[error("User is not invited, please contact admin for help")]
UserNotInvited,

#[error("User is disabled")]
#[error("User is disabled, please contact admin for help")]
UserDisabled,

#[error(transparent)]
Expand Down

0 comments on commit 0350a7f

Please sign in to comment.