mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-29 09:43:16 +00:00
Update FederationController, add webfinger support for actor uri. Fixes #5068
This commit is contained in:
parent
8177ed11ea
commit
24194f7d16
1 changed files with 34 additions and 4 deletions
|
@ -45,8 +45,11 @@ class FederationController extends Controller
|
||||||
$resource = $request->input('resource');
|
$resource = $request->input('resource');
|
||||||
$domain = config('pixelfed.domain.app');
|
$domain = config('pixelfed.domain.app');
|
||||||
|
|
||||||
if (config('federation.activitypub.sharedInbox') &&
|
// Instance Actor
|
||||||
$resource == 'acct:'.$domain.'@'.$domain) {
|
if (
|
||||||
|
config('federation.activitypub.sharedInbox') &&
|
||||||
|
$resource == 'acct:'.$domain.'@'.$domain
|
||||||
|
) {
|
||||||
$res = [
|
$res = [
|
||||||
'subject' => 'acct:'.$domain.'@'.$domain,
|
'subject' => 'acct:'.$domain.'@'.$domain,
|
||||||
'aliases' => [
|
'aliases' => [
|
||||||
|
@ -68,6 +71,33 @@ class FederationController extends Controller
|
||||||
|
|
||||||
return response()->json($res, 200, [], JSON_UNESCAPED_SLASHES);
|
return response()->json($res, 200, [], JSON_UNESCAPED_SLASHES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(str_starts_with($resource, 'https://')) {
|
||||||
|
if(str_starts_with($resource, 'https://' . $domain . '/users/')) {
|
||||||
|
$username = str_replace('https://' . $domain . '/users/', '', $resource);
|
||||||
|
if(strlen($username) > 15) {
|
||||||
|
return response('', 400);
|
||||||
|
}
|
||||||
|
$stripped = str_replace(['_', '.', '-'], '', $username);
|
||||||
|
if(!ctype_alnum($stripped)) {
|
||||||
|
return response('', 400);
|
||||||
|
}
|
||||||
|
$key = 'federation:webfinger:sha256:url-username:'.$username;
|
||||||
|
if ($cached = Cache::get($key)) {
|
||||||
|
return response()->json($cached, 200, [], JSON_UNESCAPED_SLASHES);
|
||||||
|
}
|
||||||
|
$profile = Profile::whereUsername($username)->first();
|
||||||
|
if (! $profile || $profile->status !== null || $profile->domain) {
|
||||||
|
return response('', 400);
|
||||||
|
}
|
||||||
|
$webfinger = (new Webfinger($profile))->generate();
|
||||||
|
Cache::put($key, $webfinger, 1209600);
|
||||||
|
return response()->json($webfinger, 200, [], JSON_UNESCAPED_SLASHES)
|
||||||
|
->header('Access-Control-Allow-Origin', '*');
|
||||||
|
} else {
|
||||||
|
return response('', 400);
|
||||||
|
}
|
||||||
|
}
|
||||||
$hash = hash('sha256', $resource);
|
$hash = hash('sha256', $resource);
|
||||||
$key = 'federation:webfinger:sha256:'.$hash;
|
$key = 'federation:webfinger:sha256:'.$hash;
|
||||||
if ($cached = Cache::get($key)) {
|
if ($cached = Cache::get($key)) {
|
||||||
|
@ -81,8 +111,8 @@ class FederationController extends Controller
|
||||||
return response('', 400);
|
return response('', 400);
|
||||||
}
|
}
|
||||||
$username = $parsed['username'];
|
$username = $parsed['username'];
|
||||||
$profile = Profile::whereNull('domain')->whereUsername($username)->first();
|
$profile = Profile::whereUsername($username)->first();
|
||||||
if (! $profile || $profile->status !== null) {
|
if (! $profile || $profile->status !== null || $profile->domain) {
|
||||||
return response('', 400);
|
return response('', 400);
|
||||||
}
|
}
|
||||||
$webfinger = (new Webfinger($profile))->generate();
|
$webfinger = (new Webfinger($profile))->generate();
|
||||||
|
|
Loading…
Reference in a new issue