[WIP] Register webfinger route

This commit is contained in:
Jeremy Dormitzer 2018-10-02 13:27:29 -04:00
parent 718c7c84a5
commit f89dd048a4
4 changed files with 49 additions and 2 deletions

View File

@ -4,6 +4,7 @@ namespace init;
require_once plugin_dir_path( __FILE__ ) . 'server/api.php';
require_once plugin_dir_path( __FILE__ ) . 'server/actors.php';
require_once plugin_dir_path( __FILE__ ) . 'migrations.php';
require_once plugin_dir_path( __FILE__ ) . 'server/webfinger.php';
add_action( 'rest_api_init', function() {
\api\register_routes();
@ -21,4 +22,9 @@ add_action( 'pterotype_init', function() {
add_action( 'pterotype_load', function() {
\migrations\run_migrations();
} );
add_action( 'generate_rewrite_rules', '\webfinger\generate_rewrite_rules', 111 );
add_action( 'parse_request', '\webfinger\parse_request', 111 );
add_filter( 'query_vars', '\webfinger\query_vars' );
add_action( 'well_known_webfinger', '\webfinger\handle' );
?>

View File

@ -68,6 +68,8 @@ function get_blog_actor() {
null, sprintf( '/pterotype/v1/actor/%s/outbox', PTEROTYPE_BLOG_ACTOR_SLUG )
),
'name' => get_bloginfo( 'name' ),
// TODO in the future, make this configurable, both here and in the Webfinger handler
'preferredUsername' => 'blog',
'summary' => get_bloginfo( 'description' ),
'url' => network_site_url( '/' ),
);

View File

@ -0,0 +1,29 @@
<?php
namespace webfinger;
function generate_rewrite_rules( $wp_rewrite ) {
$dot_well_known = array(
'.well-known/webfinger' => 'index.php?well-known=webfinger'
);
$wp_rewrite->rules = $dot_well_known + $wp_rewrite->rules;
}
function parse_request( $req ) {
if ( ! array_key_exists( 'well-known', $req->query_vars ) ) {
return;
}
if ( $req->query_vars['well-known'] === 'webfinger' ) {
do_action( 'well_known_webfinger', $req->query_vars );
}
}
function query_vars( $query_vars ) {
$query_vars[] = 'well-known';
return $query_vars;
}
function handle( $query ) {
echo var_dump( $query );
exit;
}
?>

View File

@ -8,9 +8,19 @@ define( 'PTEROTYPE_VERSION', '0.0.4' );
function pterotype_init() {
do_action( 'pterotype_init' );
flush_rewrite_rules();
}
do_action( 'pterotype_load' );
function pterotype_deactive() {
do_action( 'pterotype_deactivate' );
flush_rewrite_rules();
}
register_activation_hook( __FILE__, 'pterotype_init');
function pterotype_load() {
do_action( 'pterotype_load' );
}
add_action( 'plugins_loaded', 'pterotype_load' );
register_activation_hook( __FILE__, 'pterotype_init' );
register_deactivation_hook( __FILE__, 'pterotype_deactivate' );
?>