Use the webfinger crate
This commit is contained in:
+28
-31
@@ -14,13 +14,13 @@ use openssl::{
|
||||
rsa::Rsa,
|
||||
sign::Signer
|
||||
};
|
||||
use webfinger::*;
|
||||
|
||||
use activity_pub::{
|
||||
ActivityStream, Id, IntoId,
|
||||
actor::{Actor as APActor, ActorType},
|
||||
inbox::WithInbox,
|
||||
sign,
|
||||
webfinger::*
|
||||
sign
|
||||
};
|
||||
use models::instance::*;
|
||||
use schema::blogs;
|
||||
@@ -91,9 +91,9 @@ impl Blog {
|
||||
|
||||
fn fetch_from_webfinger(conn: &PgConnection, acct: String) -> Option<Blog> {
|
||||
match resolve(acct.clone()) {
|
||||
Ok(url) => Blog::fetch_from_url(conn, url),
|
||||
Ok(wf) => wf.links.into_iter().find(|l| l.mime_type == Some(String::from("application/activity+json"))).and_then(|l| Blog::fetch_from_url(conn, l.href)),
|
||||
Err(details) => {
|
||||
println!("{}", details);
|
||||
println!("{:?}", details);
|
||||
None
|
||||
}
|
||||
}
|
||||
@@ -171,6 +171,30 @@ impl Blog {
|
||||
pub fn get_keypair(&self) -> PKey<Private> {
|
||||
PKey::from_rsa(Rsa::private_key_from_pem(self.private_key.clone().unwrap().as_ref()).unwrap()).unwrap()
|
||||
}
|
||||
|
||||
pub fn webfinger(&self, conn: &PgConnection) -> Webfinger {
|
||||
Webfinger {
|
||||
subject: format!("acct:{}@{}", self.actor_id, self.get_instance(conn).public_domain),
|
||||
aliases: vec![self.compute_id(conn)],
|
||||
links: vec![
|
||||
Link {
|
||||
rel: String::from("http://webfinger.net/rel/profile-page"),
|
||||
mime_type: None,
|
||||
href: self.compute_id(conn)
|
||||
},
|
||||
Link {
|
||||
rel: String::from("http://schemas.google.com/g/2010#updates-from"),
|
||||
mime_type: Some(String::from("application/atom+xml")),
|
||||
href: self.compute_box(conn, "feed.atom")
|
||||
},
|
||||
Link {
|
||||
rel: String::from("self"),
|
||||
mime_type: Some(String::from("application/activity+json")),
|
||||
href: self.compute_id(conn)
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoId for Blog {
|
||||
@@ -234,33 +258,6 @@ impl APActor for Blog {
|
||||
}
|
||||
}
|
||||
|
||||
impl Webfinger for Blog {
|
||||
fn webfinger_subject(&self, conn: &PgConnection) -> String {
|
||||
format!("acct:{}@{}", self.actor_id, self.get_instance(conn).public_domain)
|
||||
}
|
||||
fn webfinger_aliases(&self, conn: &PgConnection) -> Vec<String> {
|
||||
vec![self.compute_id(conn)]
|
||||
}
|
||||
fn webfinger_links(&self, conn: &PgConnection) -> Vec<Vec<(String, String)>> {
|
||||
vec![
|
||||
vec![
|
||||
(String::from("rel"), String::from("http://webfinger.net/rel/profile-page")),
|
||||
(String::from("href"), self.compute_id(conn))
|
||||
],
|
||||
vec![
|
||||
(String::from("rel"), String::from("http://schemas.google.com/g/2010#updates-from")),
|
||||
(String::from("type"), String::from("application/atom+xml")),
|
||||
(String::from("href"), self.compute_box(conn, "feed.atom"))
|
||||
],
|
||||
vec![
|
||||
(String::from("rel"), String::from("self")),
|
||||
(String::from("type"), String::from("application/activity+json")),
|
||||
(String::from("href"), self.compute_id(conn))
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
impl sign::Signer for Blog {
|
||||
fn get_key_id(&self, conn: &PgConnection) -> String {
|
||||
format!("{}#main-key", self.compute_id(conn))
|
||||
|
||||
+26
-28
@@ -24,6 +24,7 @@ use rocket::{
|
||||
};
|
||||
use serde_json;
|
||||
use url::Url;
|
||||
use webfinger::*;
|
||||
|
||||
use BASE_URL;
|
||||
use activity_pub::{
|
||||
@@ -31,7 +32,7 @@ use activity_pub::{
|
||||
actor::{ActorType, Actor as APActor},
|
||||
inbox::{Inbox, WithInbox},
|
||||
sign::{Signer, gen_keypair},
|
||||
webfinger::{Webfinger, resolve}
|
||||
webfinger::{resolve}
|
||||
};
|
||||
use db_conn::DbConn;
|
||||
use models::{
|
||||
@@ -336,6 +337,30 @@ impl User {
|
||||
json["fqn"] = serde_json::Value::String(self.get_fqn(conn));
|
||||
json
|
||||
}
|
||||
|
||||
pub fn webfinger(&self, conn: &PgConnection) -> Webfinger {
|
||||
Webfinger {
|
||||
subject: format!("acct:{}@{}", self.username, self.get_instance(conn).public_domain),
|
||||
aliases: vec![self.compute_id(conn)],
|
||||
links: vec![
|
||||
Link {
|
||||
rel: String::from("http://webfinger.net/rel/profile-page"),
|
||||
mime_type: None,
|
||||
href: self.compute_id(conn)
|
||||
},
|
||||
Link {
|
||||
rel: String::from("http://schemas.google.com/g/2010#updates-from"),
|
||||
mime_type: Some(String::from("application/atom+xml")),
|
||||
href: self.compute_box(conn, "feed.atom")
|
||||
},
|
||||
Link {
|
||||
rel: String::from("self"),
|
||||
mime_type: Some(String::from("application/activity+json")),
|
||||
href: self.compute_id(conn)
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'r> FromRequest<'a, 'r> for User {
|
||||
@@ -445,33 +470,6 @@ impl Inbox for User {
|
||||
}
|
||||
}
|
||||
|
||||
impl Webfinger for User {
|
||||
fn webfinger_subject(&self, conn: &PgConnection) -> String {
|
||||
format!("acct:{}@{}", self.username, self.get_instance(conn).public_domain)
|
||||
}
|
||||
fn webfinger_aliases(&self, conn: &PgConnection) -> Vec<String> {
|
||||
vec![self.compute_id(conn)]
|
||||
}
|
||||
fn webfinger_links(&self, conn: &PgConnection) -> Vec<Vec<(String, String)>> {
|
||||
vec![
|
||||
vec![
|
||||
(String::from("rel"), String::from("http://webfinger.net/rel/profile-page")),
|
||||
(String::from("href"), self.compute_id(conn))
|
||||
],
|
||||
vec![
|
||||
(String::from("rel"), String::from("http://schemas.google.com/g/2010#updates-from")),
|
||||
(String::from("type"), String::from("application/atom+xml")),
|
||||
(String::from("href"), self.compute_box(conn, "feed.atom"))
|
||||
],
|
||||
vec![
|
||||
(String::from("rel"), String::from("self")),
|
||||
(String::from("type"), String::from("application/activity+json")),
|
||||
(String::from("href"), self.compute_id(conn))
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
impl Signer for User {
|
||||
fn get_key_id(&self, conn: &PgConnection) -> String {
|
||||
format!("{}#main-key", self.compute_id(conn))
|
||||
|
||||
Reference in New Issue
Block a user