···
use atrium_identity::Error as IdError;
use atrium_oauth::Error as OAuthError;
match oauth.begin(¶ms.handle).await {
Ok(auth_url) => (jar, Redirect::to(&auth_url)).into_response(),
-
Err(OAuthError::Identity(IdError::NotFound)) => {
-
let info = json!({ "reason": "handle not found" });
-
(StatusCode::NOT_FOUND, RenderHtml("auth-fail", engine, info)).into_response()
-
Err(OAuthError::Identity(IdError::AtIdentifier(r))) => {
-
let info = json!({ "reason": r });
-
(StatusCode::NOT_FOUND, RenderHtml("auth-fail", engine, info)).into_response()
-
Err(OAuthError::Identity(IdError::HttpStatus(StatusCode::NOT_FOUND))) => {
-
let info = json!({ "reason": "handle not found" });
-
(StatusCode::NOT_FOUND, RenderHtml("auth-fail", engine, info)).into_response()
eprintln!("begin auth failed: {e:?}");
-
let info = json!({ "reason": "unknown" });
-
StatusCode::INTERNAL_SERVER_ERROR,
-
RenderHtml("auth-fail", engine, info),
-
impl OAuthCompleteError {
-
fn to_error_response(&self, engine: AppEngine) -> Response {
-
let (level, desc) = match self {
-
OAuthCompleteError::Denied { description, .. } => {
-
("warn", format!("asdf: {description:?}"))
-
OAuthCompleteError::Failed { .. } => (
-
"Something went wrong while requesting permission, sorry!".to_string(),
-
OAuthCompleteError::CallbackFailed(_) => (
-
"Something went wrong after permission was granted, sorry!".to_string(),
-
OAuthCompleteError::NoDid => (
-
"Something went wrong when trying to confirm your identity, sorry!".to_string(),
-
StatusCode::INTERNAL_SERVER_ERROR
···
Query(params): Query<OAuthCallbackParams>,
-
) -> Result<(SignedCookieJar, impl IntoResponse), Response> {
let did = match oauth.complete(params).await {
-
Err(e) => return Err(e.to_error_response(engine)),
let cookie = Cookie::build((DID_COOKIE_KEY, did.to_string()))
···
-
"fetch_key": fetch_key,
···
use atrium_identity::Error as IdError;
use atrium_oauth::Error as OAuthError;
+
let err = |code, reason| {
+
(code, RenderHtml("auth-fail", engine.clone(), info)).into_response()
match oauth.begin(¶ms.handle).await {
Ok(auth_url) => (jar, Redirect::to(&auth_url)).into_response(),
+
Err(OAuthError::Identity(
+
IdError::NotFound | IdError::HttpStatus(StatusCode::NOT_FOUND),
+
)) => err(StatusCode::NOT_FOUND, "handle not found"),
+
Err(OAuthError::Identity(IdError::AtIdentifier(r))) => err(StatusCode::BAD_REQUEST, &r),
eprintln!("begin auth failed: {e:?}");
+
err(StatusCode::INTERNAL_SERVER_ERROR, "unknown")
···
Query(params): Query<OAuthCallbackParams>,
+
let err = |code, result, reason| {
+
(code, RenderHtml("auth-fail", engine.clone(), info)).into_response()
let did = match oauth.complete(params).await {
+
OAuthCompleteError::Denied { description, .. } => {
+
let desc = description.unwrap_or("permission to share was denied".to_string());
+
err(StatusCode::FORBIDDEN, "deny", desc.as_str())
+
OAuthCompleteError::Failed { .. } => {
+
eprintln!("auth completion failed: {e:?}");
+
StatusCode::INTERNAL_SERVER_ERROR,
+
OAuthCompleteError::CallbackFailed(e) => {
+
eprintln!("auth callback failed: {e:?}");
+
StatusCode::INTERNAL_SERVER_ERROR,
+
"failed to complete callback",
+
OAuthCompleteError::NoDid => err(StatusCode::BAD_REQUEST, "fail", "no DID found"),
let cookie = Cookie::build((DID_COOKIE_KEY, did.to_string()))
···
+
"fetch_key": fetch_key,
+
(jar, RenderHtml("authorized", engine, info)).into_response()