···
use atrium_identity::Error as IdError;
use atrium_oauth::Error as OAuthError;
250
+
let err = |code, reason| {
255
+
(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(),
252
-
Err(OAuthError::Identity(IdError::NotFound)) => {
253
-
let info = json!({ "reason": "handle not found" });
254
-
(StatusCode::NOT_FOUND, RenderHtml("auth-fail", engine, info)).into_response()
256
-
Err(OAuthError::Identity(IdError::AtIdentifier(r))) => {
257
-
let info = json!({ "reason": r });
258
-
(StatusCode::NOT_FOUND, RenderHtml("auth-fail", engine, info)).into_response()
260
-
Err(OAuthError::Identity(IdError::HttpStatus(StatusCode::NOT_FOUND))) => {
261
-
let info = json!({ "reason": "handle not found" });
262
-
(StatusCode::NOT_FOUND, RenderHtml("auth-fail", engine, info)).into_response()
260
+
Err(OAuthError::Identity(
261
+
IdError::NotFound | IdError::HttpStatus(StatusCode::NOT_FOUND),
262
+
)) => err(StatusCode::NOT_FOUND, "handle not found"),
263
+
Err(OAuthError::Identity(IdError::AtIdentifier(r))) => err(StatusCode::BAD_REQUEST, &r),
eprintln!("begin auth failed: {e:?}");
266
-
let info = json!({ "reason": "unknown" });
268
-
StatusCode::INTERNAL_SERVER_ERROR,
269
-
RenderHtml("auth-fail", engine, info),
266
+
err(StatusCode::INTERNAL_SERVER_ERROR, "unknown")
276
-
impl OAuthCompleteError {
277
-
fn to_error_response(&self, engine: AppEngine) -> Response {
278
-
let (level, desc) = match self {
279
-
OAuthCompleteError::Denied { description, .. } => {
280
-
("warn", format!("asdf: {description:?}"))
282
-
OAuthCompleteError::Failed { .. } => (
284
-
"Something went wrong while requesting permission, sorry!".to_string(),
286
-
OAuthCompleteError::CallbackFailed(_) => (
288
-
"Something went wrong after permission was granted, sorry!".to_string(),
290
-
OAuthCompleteError::NoDid => (
292
-
"Something went wrong when trying to confirm your identity, sorry!".to_string(),
296
-
if level == "warn" {
297
-
StatusCode::FORBIDDEN
299
-
StatusCode::INTERNAL_SERVER_ERROR
···
Query(params): Query<OAuthCallbackParams>,
323
-
) -> Result<(SignedCookieJar, impl IntoResponse), Response> {
282
+
let err = |code, result, reason| {
287
+
(code, RenderHtml("auth-fail", engine.clone(), info)).into_response()
let did = match oauth.complete(params).await {
326
-
Err(e) => return Err(e.to_error_response(engine)),
294
+
OAuthCompleteError::Denied { description, .. } => {
295
+
let desc = description.unwrap_or("permission to share was denied".to_string());
296
+
err(StatusCode::FORBIDDEN, "deny", desc.as_str())
298
+
OAuthCompleteError::Failed { .. } => {
299
+
eprintln!("auth completion failed: {e:?}");
301
+
StatusCode::INTERNAL_SERVER_ERROR,
303
+
"failed to complete",
306
+
OAuthCompleteError::CallbackFailed(e) => {
307
+
eprintln!("auth callback failed: {e:?}");
309
+
StatusCode::INTERNAL_SERVER_ERROR,
311
+
"failed to complete callback",
314
+
OAuthCompleteError::NoDid => err(StatusCode::BAD_REQUEST, "fail", "no DID found"),
let cookie = Cookie::build((DID_COOKIE_KEY, did.to_string()))
···
353
-
"fetch_key": fetch_key,
337
+
"fetch_key": fetch_key,
339
+
(jar, RenderHtml("authorized", engine, info)).into_response()