diff --git a/web/src/handlers/did.rs b/web/src/handlers/did.rs new file mode 100644 index 0000000..cca8154 --- /dev/null +++ b/web/src/handlers/did.rs @@ -0,0 +1,27 @@ +use axum::Json; +use axum::response::IntoResponse; +use serde_json::json; +use std::env; + +pub async fn did_json_handler() -> impl IntoResponse { + let oauth_host = env::var("OAUTH_HOST").unwrap_or_else(|_| "localhost".to_string()); + let did = format!("did:web:{oauth_host}"); + let service_endpoint = format!("https://{oauth_host}"); + + Json(json!({ + "@context": [ + "https://www.w3.org/ns/did/v1", + "https://w3id.org/security/multikey/v1" + ], + "id": did, + "alsoKnownAs": [], + "service": [ + { + "id": "#advent", + "type": "AdventChallengeService", + "serviceEndpoint": service_endpoint + } + ], + "verificationMethod": [] + })) +} diff --git a/web/src/handlers/mod.rs b/web/src/handlers/mod.rs index d01304d..865bbba 100644 --- a/web/src/handlers/mod.rs +++ b/web/src/handlers/mod.rs @@ -1,4 +1,5 @@ pub mod auth; pub mod day; +pub mod did; pub mod leaderboard; pub mod oauth_metadata; diff --git a/web/src/main.rs b/web/src/main.rs index adaf80b..5e43ce4 100644 --- a/web/src/main.rs +++ b/web/src/main.rs @@ -307,10 +307,15 @@ async fn main() -> Result<(), Box> { .nest_service("/public", axum_embed::ServeEmbed::::new()); if env::var("OAUTH_HOST").is_ok() { - app = app.route( - "/oauth-client-metadata.json", - get(handlers::oauth_metadata::oauth_client_metadata_handler), - ); + app = app + .route( + "/oauth-client-metadata.json", + get(handlers::oauth_metadata::oauth_client_metadata_handler), + ) + .route( + "/.well-known/did.json", + get(handlers::did::did_json_handler), + ); } let app = app