From 2073015b7fbe39ca7d51c216d8641045e956455e Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 18 Apr 2024 05:46:10 +0200 Subject: [PATCH] feat: mock oauth login wellknown looks like we will need oauth soon to be able to use even andstatus --- src/routes/activitypub/mod.rs | 1 + src/routes/activitypub/well_known.rs | 37 +++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/routes/activitypub/mod.rs b/src/routes/activitypub/mod.rs index 3eaf9cc1..1bc1f3b8 100644 --- a/src/routes/activitypub/mod.rs +++ b/src/routes/activitypub/mod.rs @@ -36,6 +36,7 @@ impl ActivityPubRouter for Router { .route("/.well-known/webfinger", get(ap::well_known::webfinger)) .route("/.well-known/host-meta", get(ap::well_known::host_meta)) .route("/.well-known/nodeinfo", get(ap::well_known::nodeinfo_discovery)) + .route("/.well-known/oauth-authorization-server", get(ap::well_known::oauth_authorization_server)) .route("/nodeinfo/:version", get(ap::well_known::nodeinfo)) // actor routes .route("/users/:id", get(ap::user::view)) diff --git a/src/routes/activitypub/well_known.rs b/src/routes/activitypub/well_known.rs index 5f6c6db7..b06da46e 100644 --- a/src/routes/activitypub/well_known.rs +++ b/src/routes/activitypub/well_known.rs @@ -2,7 +2,7 @@ use axum::{extract::{Path, Query, State}, http::StatusCode, response::{IntoRespo use jrd::{JsonResourceDescriptor, JsonResourceDescriptorLink}; use sea_orm::{EntityTrait, PaginatorTrait}; -use crate::{model, server::Context, VERSION}; +use crate::{model, server::Context, url, VERSION}; #[derive(serde::Serialize)] pub struct NodeInfoDiscovery { @@ -144,3 +144,38 @@ pub async fn host_meta(State(ctx): State) -> Response { ctx.protocol(), ctx.base()) ).into_response() } + +#[derive(Debug, serde::Serialize)] +pub struct OauthAuthorizationServerResponse { + issuer: String, + authorization_endpoint: String, + token_endpoint: String, + scopes_supported: Vec, + response_types_supported: Vec, + grant_types_supported: Vec, + service_documentation: String, + code_challenge_methods_supported: Vec, + authorization_response_iss_parameter_supported: bool, +} + +pub async fn oauth_authorization_server(State(ctx): State) -> crate::Result> { + Ok(Json(OauthAuthorizationServerResponse { + issuer: url!(ctx, ""), + authorization_endpoint: url!(ctx, "/auth"), + token_endpoint: "".to_string(), + scopes_supported: vec![ + "read:account".to_string(), + "write:account".to_string(), + "read:favorites".to_string(), + "write:favorites".to_string(), + "read:following".to_string(), + "write:following".to_string(), + "write:notes".to_string(), + ], + response_types_supported: vec!["code".to_string()], + grant_types_supported: vec!["authorization_code".to_string()], + service_documentation: "".to_string(), + code_challenge_methods_supported: vec![], + authorization_response_iss_parameter_supported: false, + })) +}