A crate to help you fetch and serve WebFinger resources
Find a file
2022-06-12 18:59:25 +00:00
src Remove unnecessary mut 2022-06-13 03:43:29 +09:00
.gitattributes add git attributes and remove executable bit from files in repo 2020-05-17 12:35:31 +02:00
.gitignore Add support for group: and custom prefixes (fixes #3) 2019-03-17 16:09:19 +01:00
.travis.yml add async tests to travis test script 2020-05-19 11:40:40 +02:00
Cargo.toml Specify async-trait version 2022-06-13 03:58:44 +09:00
coverage.sh Try to add codecov 2019-03-17 16:32:12 +01:00
LICENSE add git attributes and remove executable bit from files in repo 2020-05-17 12:35:31 +02:00
README.md add git attributes and remove executable bit from files in repo 2020-05-17 12:35:31 +02:00

WebFinger Crates.io Libraries.io dependency status for GitHub repo Codecov Build Status

A crate to help you fetch and serve WebFinger resources.

Examples

Fetching a resource:

use webfinger::resolve;

fn main() {
    let res = resolve("acct:test@example.org", true).expect("Error while fetching resource");

    println!("Places to get more informations about {}:", res.subject);
    for link in res.links.into_iter() {
        println!("- {}", link.href);
    }
}

Serving resources:

use webfinger::Resolver;

pub struct MyResolver;

impl Resolver<DatabaseConnection> for MyResolver {
    fn instance_domain<'a>() -> &'a str {
        "instance.tld"
    }

    fn find(acct: String, db: DatabaseConnection) -> Result<Webfinger, ResolverError> {
        if let Some(user) = db.find_user_by_name(acct) {
            Ok(Webfinger {
                subject: acct.clone(),
                aliases: vec![acct.clone()],
                links: vec![
                    Link {
                        rel: "http://webfinger.net/rel/profile-page".to_string(),
                        mime_type: None,
                        href: user.profile_url()
                    }
                ]
            })
        } else {
            Err(ResolverError::NotFound)
        }
    }
}

fn main() {
    // Start a web server and map /.well-known/webfinger to a function calling MyResolver::endpoint
}