Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.
PHP ai-agentsblueskyfacebookinstagramlaravellinkedinmastodonmcpmcp-serveropen-sourcerest-apiself-hostedsocial-mediasocial-media-managementsocial-media-schedulerthreadstiktokvuejsxyoutube
Serve /.well-known files from the environment (#426)
Paulo Castellanofe5cab01fe40
diff --git a/.ai/rules/index.md b/.ai/rules/index.mdindex ae7fa9465..6da72a938 100644--- a/.ai/rules/index.md+++ b/.ai/rules/index.md@@ -19,6 +19,7 @@ Before planning or editing, find the row whose globs match the file's path and r| app/Jobs/PostHog/** | .ai/rules/post-hog.md || app/Enums/PostPlatform/ContentType.php | .ai/rules/post-platform.md || app/Actions/Post/FinalizePostPublication.php, app/Jobs/PublishPost.php, app/Actions/Post/UpdatePost.php, app/Actions/Post/** | .ai/rules/post.md |+| routes/well-known.php, app/Http/Controllers/WellKnownController.php | .ai/rules/routes.md || app/Enums/SocialAccount/Platform.php | .ai/rules/social-account.md || app/Services/Social/GoogleBusinessPublisher.php, app/Support/Social/GoogleBusinessDerivativeCleaner.php, app/Actions/Post/DeletePost.php, app/Actions/Post/UpdatePost.php, app/Actions/Workspace/PurgeWorkspace.php, app/Http/Controllers/Auth/SocialController.php, app/Support/Social/ThreadProgress.php, app/Support/ThreadReplies.php, app/Services/Social/Concerns/PublishesThreads.php, app/Services/Social/FacebookPublisher.php, app/Services/Social/InstagramPublisher.php | .ai/rules/social.md || app/Support/PostPlatformMetaRules.php | .ai/rules/support.md |diff --git a/.ai/rules/routes.md b/.ai/rules/routes.mdnew file mode 100644index 000000000..d33dc486d--- /dev/null+++ b/.ai/rules/routes.md@@ -0,0 +1,15 @@+---+paths:+ - routes/well-known.php+ - app/Http/Controllers/WellKnownController.php+---++# Routes++## New /.well-known files go in config, never a new route or a public/ file+Every /.well-known/{name} file is one entry in config('trypost.well_known') read from its own env variable (e.g. OPENAI_APPS_CHALLENGE), served by WellKnownController as plain text; an empty value answers 404. Never hard-code a token or drop a file in public/.well-known: the repo is open source and self-hosted installs must not serve TryPost Cloud's tokens. Cover each new entry in tests/Feature/WellKnownTest.php and add the env key to .env.example.++- The route is required from routes/web.php but runs `withoutMiddleware('web')`: a verifier or crawler hit must not start a session (sessions live in the database).+- `whereIn` keeps {file} to the configured names so it never shadows another /.well-known route (laravel/mcp's oauth-*); the test that registers a later /.well-known route proves it.+- The route is only registered when the config has names: `whereIn` with an empty list throws on route compile and would break every request and `route:cache`.+- Plain-text tokens only. A JSON file (apple-app-site-association, assetlinks.json) needs its content type decided first; do not serve JSON as text/plain.diff --git a/.env.example b/.env.exampleindex 61d3a26a0..06bc0934d 100644--- a/.env.example+++ b/.env.example@@ -24,6 +24,10 @@ X_DEFUSE_LINKS=falseCHANGELOG_ENABLED=trueMETA_PAGE_WALK_SECONDS=20+# Domain verification tokens served at /.well-known/{name} (config trypost.well_known).+# Leave empty unless you list the app in that provider's directory.+OPENAI_APPS_CHALLENGE=+# Passport OAuth keys (API tokens / MCP). Prefer env vars over key files so# every node behind a load balancer shares the same key pair. Use literal \n# for newlines in the PEM. When unset, Passport falls back to storage/oauth-*.keydiff --git a/app/Http/Controllers/WellKnownController.php b/app/Http/Controllers/WellKnownController.phpnew file mode 100644index 000000000..84900ea84--- /dev/null+++ b/app/Http/Controllers/WellKnownController.php@@ -0,0 +1,22 @@+<?php++declare(strict_types=1);++namespace App\Http\Controllers;++use Illuminate\Http\Response;++class WellKnownController extends Controller+{+ public function __invoke(string $file): Response+ {+ $content = config()->collection('trypost.well_known')->get($file);++ abort_unless(filled($content), Response::HTTP_NOT_FOUND);++ return response($content, Response::HTTP_OK, [+ 'Content-Type' => 'text/plain; charset=UTF-8',+ 'X-Content-Type-Options' => 'nosniff',+ ]);+ }+}diff --git a/config/trypost.php b/config/trypost.phpindex f1c8841db..bca461521 100644--- a/config/trypost.php+++ b/config/trypost.php@@ -48,6 +48,22 @@ return ['privacy_url' => env('LEGAL_PRIVACY_URL', 'https://trypost.it/privacy'),],+ /*+ |--------------------------------------------------------------------------+ | Well-known files+ |--------------------------------------------------------------------------+ |+ | Files served at /.well-known/{name} as plain text, keyed by name. The+ | content always comes from the environment so no install serves another+ | install's tokens; an empty value answers 404. Add a provider with one+ | line here and one env variable.+ |+ */++ 'well_known' => [+ 'openai-apps-challenge' => env('OPENAI_APPS_CHALLENGE'),+ ],+/*|--------------------------------------------------------------------------| Meta page walk budgetdiff --git a/routes/web.php b/routes/web.phpindex 81265863a..11d183ffc 100644--- a/routes/web.php+++ b/routes/web.php@@ -3,5 +3,6 @@declare(strict_types=1);require __DIR__.'/webhook.php';+require __DIR__.'/well-known.php';require __DIR__.'/auth.php';require __DIR__.'/app.php';diff --git a/routes/well-known.php b/routes/well-known.phpnew file mode 100644index 000000000..7aeecaaf7--- /dev/null+++ b/routes/well-known.php@@ -0,0 +1,15 @@+<?php++declare(strict_types=1);++use App\Http\Controllers\WellKnownController;+use Illuminate\Support\Facades\Route;++$wellKnownFiles = config()->collection('trypost.well_known')->keys();++if ($wellKnownFiles->isNotEmpty()) {+ Route::get('.well-known/{file}', WellKnownController::class)+ ->whereIn('file', $wellKnownFiles->all())+ ->withoutMiddleware('web')+ ->name('well-known');+}diff --git a/tests/Feature/WellKnownTest.php b/tests/Feature/WellKnownTest.phpnew file mode 100644index 000000000..2ecec2210--- /dev/null+++ b/tests/Feature/WellKnownTest.php@@ -0,0 +1,80 @@+<?php++declare(strict_types=1);++use App\Models\User;+use Illuminate\Routing\RouteCollection;+use Illuminate\Support\Facades\Route;++test('a configured well-known file is served as plain text, without a session', function () {+ config()->set('trypost.well_known.openai-apps-challenge', 'challenge-token-123');++ $this->get(route('well-known', 'openai-apps-challenge'))+ ->assertOk()+ ->assertContent('challenge-token-123')+ ->assertHeader('Content-Type', 'text/plain; charset=UTF-8')+ ->assertHeader('X-Content-Type-Options', 'nosniff')+ ->assertHeaderMissing('Set-Cookie');+});++test('a configured well-known file is served to signed-in users too', function () {+ config()->set('trypost.well_known.openai-apps-challenge', 'challenge-token-123');++ $this->actingAs(User::factory()->create())+ ->get(route('well-known', 'openai-apps-challenge'))+ ->assertOk()+ ->assertContent('challenge-token-123');+});++test('a configured well-known file without a value is not found', function (?string $value) {+ config()->set('trypost.well_known.openai-apps-challenge', $value);++ $this->get(route('well-known', 'openai-apps-challenge'))->assertNotFound();+})->with([+ 'unset' => null,+ 'empty' => '',+ 'blank' => ' ',+]);++test('a well-known path outside the configured names is not found', function (string $path) {+ config()->set('trypost.well_known.openai-apps-challenge', 'challenge-token-123');++ $this->get($path)->assertNotFound();+})->with([+ 'another file' => '/.well-known/security.txt',+ 'different case' => '/.well-known/OPENAI-APPS-CHALLENGE',+ 'nested path' => '/.well-known/openai-apps-challenge/extra',+ 'extension' => '/.well-known/openai-apps-challenge.txt',+]);++test('a well-known file only answers GET and HEAD', function () {+ config()->set('trypost.well_known.openai-apps-challenge', 'challenge-token-123');++ $this->head(route('well-known', 'openai-apps-challenge'))->assertOk();+ $this->post(route('well-known', 'openai-apps-challenge'))->assertMethodNotAllowed();+});++test('a well-known route registered after this one still answers', function () {+ Route::get('.well-known/security.txt', fn () => 'other')->name('test.well-known.security');+ Route::getRoutes()->refreshNameLookups();++ $this->get(route('test.well-known.security'))->assertOk()->assertContent('other');+});++test('the MCP OAuth discovery routes keep answering', function (string $name, array $parameters, string $key) {+ $this->get(route($name, $parameters))->assertOk()->assertJsonStructure([$key]);+})->with([+ 'authorization server' => ['mcp.oauth.authorization-server', [], 'issuer'],+ 'nested authorization server' => ['mcp.oauth.authorization-server.nested', ['path' => 'mcp/trypost'], 'issuer'],+ 'protected resource' => ['mcp.oauth.protected-resource', [], 'resource'],+ 'nested protected resource' => ['mcp.oauth.protected-resource.nested', ['path' => 'mcp/trypost'], 'resource'],+]);++test('no well-known file configured registers no route', function () {+ config()->set('trypost.well_known', []);+ Route::setRoutes(new RouteCollection);++ require base_path('routes/well-known.php');++ expect(Route::getRoutes()->getRoutes())->toBeEmpty();+});