Skip to content

Commit

Permalink
Handle JWT signing error
Browse files Browse the repository at this point in the history
  • Loading branch information
j-chmielewski committed Jan 24, 2023
1 parent 3503f5c commit 4dd264a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 6 additions & 0 deletions avanguard/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use actix_web::{
http::{header::ContentType, StatusCode},
HttpResponse, ResponseError,
};
use openidconnect::JsonWebTokenError;
use thiserror::Error;

#[derive(Debug, Error)]
Expand All @@ -12,6 +13,8 @@ pub enum ApiError {
WalletNotFound,
#[error("signature incorrect")]
SignatureIncorrect,
#[error("signing error")]
SigningError(#[from] JsonWebTokenError),
}

impl ApiError {
Expand All @@ -20,6 +23,7 @@ impl ApiError {
Self::Sqlx(_) => "DB",
Self::WalletNotFound => "WalletNotFound",
Self::SignatureIncorrect => "SignatureIncorrect",
Self::SigningError(_) => "SignatureIncorrect",
}
}

Expand All @@ -28,6 +32,7 @@ impl ApiError {
Self::Sqlx(_) => String::from("Internal error"),
Self::WalletNotFound => String::from("Wallet not found"),
Self::SignatureIncorrect => String::from("Signature incorrect"),
Self::SigningError(_) => String::from("Signing error"),
}
}
}
Expand Down Expand Up @@ -60,6 +65,7 @@ impl ResponseError for ApiError {
Self::Sqlx(_) => StatusCode::INTERNAL_SERVER_ERROR,
ApiError::WalletNotFound => StatusCode::UNAUTHORIZED,
ApiError::SignatureIncorrect => StatusCode::UNAUTHORIZED,
ApiError::SigningError(_) => StatusCode::UNAUTHORIZED,
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions avanguard/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,7 @@ pub async fn web3auth_end(
None,
&signature.nonce,
&app_state.config.client_id,
)
// TODO: handle JWT error
.unwrap();
)?;
wallet.challenge_signature = Some(signature.signature.clone());
wallet.save(&app_state.pool).await?;
Ok(Json(JwtToken {
Expand Down

0 comments on commit 4dd264a

Please sign in to comment.