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
<?php
declare(strict_types=1);
use App\Http\Middleware\App\EnsureCanAuthorizeMcp;
use App\Models\Account;
use App\Models\User;
use App\Models\Workspace;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
/**
* @return list<string>
*/
function mcpNativeAgentSchemes(): array
{
return [
'antigravity',
'chatgpt',
'claude',
'claude-cli',
'claude-code',
'claude-desktop',
'claudeai',
'codex',
'codium',
'continue',
'cursor',
'devin',
'goose',
'grok',
'hermes',
'jetbrains',
'kiro',
'lmstudio',
'opencode',
'raycast',
'trae',
'vscode',
'vscode-insiders',
'warp',
'windsurf',
'xai',
'zed',
];
}
test('dynamic oauth client registration is rate limited', function () {
$payload = [
'client_name' => 'MCP Client',
'redirect_uris' => ['https://client.example/callback'],
'grant_types' => ['authorization_code'],
'response_types' => ['code'],
'token_endpoint_auth_method' => 'none',
];
for ($attempt = 0; $attempt < 30; $attempt++) {
$this->postJson('/oauth/register', $payload)->assertSuccessful();
}
$this->postJson('/oauth/register', $payload)->assertTooManyRequests();
});
test('dynamic oauth client registration is not rate limited from chatgpt or claude', function (string $ip) {
fakeChatGptEgressRanges(['203.0.113.0/24']);
$payload = [
'client_name' => 'MCP Client',
'redirect_uris' => ['https://client.example/callback'],
'grant_types' => ['authorization_code'],
'response_types' => ['code'],
'token_endpoint_auth_method' => 'none',
];
for ($attempt = 0; $attempt < 31; $attempt++) {
$this->withServerVariables(['REMOTE_ADDR' => $ip])
->postJson('/oauth/register', $payload)
->assertSuccessful();
}
})->with([
'chatgpt' => '203.0.113.5',
'claude' => '160.79.104.10',
]);
test('oauth discovery metadata is never rate limited', function (string $routeName, array $parameters) {
for ($attempt = 0; $attempt < 31; $attempt++) {
$this->getJson(route($routeName, $parameters))->assertSuccessful();
}
})->with([
'protected resource' => ['mcp.oauth.protected-resource', []],
'nested protected resource' => ['mcp.oauth.protected-resource.nested', ['path' => 'mcp/trypost']],
'authorization server' => ['mcp.oauth.authorization-server', []],
'nested authorization server' => ['mcp.oauth.authorization-server.nested', ['path' => 'mcp/trypost']],
]);
test('oauth discovery advertises the authentication method used by public clients', function (string $routeName, array $parameters) {
$registration = $this->postJson(route('mcp.oauth.register'), [
'client_name' => 'Discovery Test Client',
'redirect_uris' => ['https://client.example/callback'],
'grant_types' => ['authorization_code'],
'response_types' => ['code'],
'token_endpoint_auth_method' => 'none',
])->assertCreated()->assertJsonPath('token_endpoint_auth_method', 'none');
$metadata = $this->getJson(route($routeName, $parameters))
->assertOk()
->assertJsonPath('token_endpoint', route('passport.token'))
->assertJsonPath('registration_endpoint', route('mcp.oauth.register'));
expect($metadata->json('token_endpoint_auth_methods_supported'))
->toBeArray()
->toContain($registration->json('token_endpoint_auth_method'));
})->with([
'authorization server' => ['mcp.oauth.authorization-server', []],
'nested authorization server' => ['mcp.oauth.authorization-server.nested', ['path' => 'mcp/trypost']],
]);
test('mcp custom schemes config lists every supported native agent', function () {
expect(config('mcp.custom_schemes'))->toEqual(mcpNativeAgentSchemes());
});
test('dynamic oauth registration accepts every configured custom callback scheme', function (string $scheme) {
$this->postJson('/oauth/register', [
'client_name' => 'Native MCP Client',
'redirect_uris' => ["{$scheme}://oauth/callback"],
'grant_types' => ['authorization_code'],
'response_types' => ['code'],
'token_endpoint_auth_method' => 'none',
])->assertCreated();
})->with(mcpNativeAgentSchemes());
test('dynamic oauth registration accepts documented native and loopback callbacks', function (string $redirectUri) {
$this->postJson('/oauth/register', [
'client_name' => 'Native MCP Client',
'redirect_uris' => [$redirectUri],
'grant_types' => ['authorization_code'],
'response_types' => ['code'],
'token_endpoint_auth_method' => 'none',
])->assertCreated();
})->with([
'cursor anysphere' => 'cursor://anysphere.cursor-mcp/oauth/callback',
'cursor mcp host' => 'cursor://cursor.mcp/oauth/callback',
'raycast oauth' => 'raycast://oauth',
'cursor loopback' => 'http://localhost:8787/callback',
'opencode loopback' => 'http://127.0.0.1:19876/mcp/oauth/callback',
'hermes loopback' => 'http://127.0.0.1:8765/callback',
'claude https' => 'https://claude.ai/api/mcp/auth_callback',
'chatgpt https' => 'https://chatgpt.com/aip/mcp/oauth/callback',
'cursor web' => 'https://www.cursor.com/agents/mcp/oauth/callback',
'antigravity https' => 'https://antigravity.google/oauth-callback',
]);
test('dynamic oauth registration rejects unknown and unsafe callback schemes', function (string $redirectUri) {
$this->postJson('/oauth/register', [
'client_name' => 'Native MCP Client',
'redirect_uris' => [$redirectUri],
'grant_types' => ['authorization_code'],
'response_types' => ['code'],
'token_endpoint_auth_method' => 'none',
])
->assertBadRequest()
->assertJson([
'error' => 'invalid_redirect_uri',
]);
})->with([
'javascript' => 'javascript:alert(1)',
'data' => 'data:text/html,hi',
'file' => 'file:///etc/passwd',
'unknown' => 'notanagent://oauth/callback',
'cursor missing host' => 'cursor:/callback',
]);
test('dynamic oauth registration accepts extra custom schemes from config', function () {
config()->set('mcp.custom_schemes', [...config('mcp.custom_schemes'), 'myagent']);
$this->postJson('/oauth/register', [
'client_name' => 'Custom Agent',
'redirect_uris' => ['myagent://oauth/callback'],
'grant_types' => ['authorization_code'],
'response_types' => ['code'],
'token_endpoint_auth_method' => 'none',
])->assertCreated();
});
test('mcp oauth consent page is available for members who need approval', function () {
$account = Account::factory()->create();
$owner = User::factory()->create(['account_id' => $account->id]);
$account->update(['owner_id' => $owner->id]);
$workspace = Workspace::factory()->create([
'account_id' => $account->id,
'user_id' => $owner->id,
'name' => 'Requester Workspace',
]);
$workspace->members()->attach($owner->id, membershipPivot('admin'));
$requester = User::factory()->create(['account_id' => $account->id]);
$workspace->members()->attach($requester->id, membershipPivot('approval'));
$requester->update(['current_workspace_id' => $workspace->id]);
$clientId = mcpOauthClient('Requester Agent');
DB::table('oauth_clients')->where('id', $clientId)->update([
'redirect_uris' => json_encode(['https://client.example/callback']),
]);
$this->actingAs($requester)
->get(route('passport.authorizations.authorize', oauthAuthorizeQuery($clientId)))
->assertOk()
->assertInertia(fn ($page) => $page
->component('mcp/Authorize')
->where('client.name', 'Requester Agent')
->where('user.email', $requester->email)
->where('selectedWorkspaceId', (string) $workspace->id)
->has('workspaces', 1)
->where('workspaces.0.id', (string) $workspace->id)
->where('workspaces.0.name', 'Requester Workspace')
->has('scopes', 1)
->where('scopes.0.id', 'mcp:use')
->has('authToken')
->where('state', 'test-state'));
expect(view()->exists('mcp.authorize-denied'))->toBeFalse()
->and(class_exists(EnsureCanAuthorizeMcp::class))->toBeFalse();
});
test('mcp oauth consent page uses the active locale', function () {
app()->setLocale('pt-BR');
expect(__('mcp.authorize.heading', ['client' => 'Claude']))->toBe('Autorizar Claude')
->and(__('mcp.authorize.logged_in_as'))->toBe('Conectado como:')
->and(__('mcp.authorize.workspace_scope'))->toBe('Esta conexão terá acesso somente ao workspace selecionado.')
->and(__('mcp.authorize.approve'))->toBe('Autorizar')
->and(__('mcp.authorize.cancel'))->toBe('Cancelar');
});
test('mcp oauth consent page lists every workspace the user can access', function () {
$account = Account::factory()->create();
$user = User::factory()->create(['account_id' => $account->id]);
$account->update(['owner_id' => $user->id]);
$alpha = Workspace::factory()->create([
'account_id' => $account->id,
'user_id' => $user->id,
'name' => 'Alpha',
]);
$beta = Workspace::factory()->create([
'account_id' => $account->id,
'user_id' => $user->id,
'name' => 'Beta',
]);
$alpha->members()->attach($user->id, membershipPivot('admin'));
$beta->members()->attach($user->id, membershipPivot('admin'));
$user->update(['current_workspace_id' => $alpha->id]);
$clientId = mcpOauthClient('Claude');
DB::table('oauth_clients')->where('id', $clientId)->update([
'redirect_uris' => json_encode(['https://client.example/callback']),
]);
$this->actingAs($user)
->get(route('passport.authorizations.authorize', oauthAuthorizeQuery($clientId)))
->assertOk()
->assertInertia(fn ($page) => $page
->component('mcp/Authorize')
->where('selectedWorkspaceId', (string) $alpha->id)
->has('workspaces', 2)
->where('workspaces.0.name', 'Alpha')
->where('workspaces.1.name', 'Beta')
->where('workspaces.0.id', (string) $alpha->id)
->where('workspaces.1.id', (string) $beta->id));
});
test('mcp oauth always shows consent even when scopes were previously granted', function () {
$account = Account::factory()->create();
$user = User::factory()->create(['account_id' => $account->id]);
$account->update(['owner_id' => $user->id]);
$workspace = Workspace::factory()->create([
'account_id' => $account->id,
'user_id' => $user->id,
]);
$workspace->members()->attach($user->id, membershipPivot('admin'));
$user->update(['current_workspace_id' => $workspace->id]);
$clientId = mcpOauthClient('Reconnect Agent');
DB::table('oauth_clients')->where('id', $clientId)->update([
'redirect_uris' => json_encode(['https://client.example/callback']),
]);
mcpAccessToken($user, $clientId, $workspace);
$query = oauthAuthorizeQuery($clientId);
unset($query['prompt']);
$this->actingAs($user)
->get(route('passport.authorizations.authorize', $query))
->assertOk()
->assertInertia(fn ($page) => $page
->component('mcp/Authorize')
->where('client.name', 'Reconnect Agent')
->where('selectedWorkspaceId', (string) $workspace->id));
});
test('passport approve route has no mcp create-post role gate', function () {
$route = app('router')->getRoutes()->getByName('passport.authorizations.approve');
expect($route)->not->toBeNull();
$middleware = collect($route->gatherMiddleware())
->map(fn (mixed $middleware): string => is_string($middleware) ? $middleware : $middleware::class)
->implode(',');
expect($middleware)->not->toContain('EnsureCanAuthorizeMcp');
});
test('guests are redirected to login before an unknown oauth client is rejected', function () {
$unknownClientId = (string) Str::uuid();
$this->get(route('passport.authorizations.authorize', oauthAuthorizeQuery($unknownClientId)))
->assertRedirect(route('login'));
});
test('guests are redirected to login before consent for a registered oauth client', function () {
$clientId = mcpOauthClient('Guest Login Agent');
DB::table('oauth_clients')->where('id', $clientId)->update([
'redirect_uris' => json_encode(['https://client.example/callback']),
]);
$this->get(route('passport.authorizations.authorize', oauthAuthorizeQuery($clientId)))
->assertRedirect(route('login'));
});
test('authenticated users still receive invalid_client for an unknown oauth client', function () {
$user = User::factory()->create();
$unknownClientId = (string) Str::uuid();
$this->actingAs($user)
->getJson(route('passport.authorizations.authorize', oauthAuthorizeQuery($unknownClientId)))
->assertUnauthorized()
->assertJson([
'error' => 'invalid_client',
]);
});
test('browser requests render an inertia error page for an unknown oauth client', function () {
$user = User::factory()->create();
$unknownClientId = (string) Str::uuid();
$this->actingAs($user)
->get(route('passport.authorizations.authorize', oauthAuthorizeQuery($unknownClientId)))
->assertOk()
->assertInertia(fn ($page) => $page
->component('mcp/AuthorizeError')
->where('error', 'invalid_client')
->where('errorDescription', 'Client authentication failed'));
});
test('post-login redirect to authorize renders inertia instead of raw oauth json', function () {
$unknownClientId = (string) Str::uuid();
$user = User::factory()->create();
$this->get(route('passport.authorizations.authorize', oauthAuthorizeQuery($unknownClientId)))
->assertRedirect(route('login'));
$login = $this->post(route('login.store'), [
'email' => $user->email,
'password' => 'password',
'locale' => 'en',
]);
$login->assertRedirect();
$this->get($login->headers->get('Location'))
->assertOk()
->assertInertia(fn ($page) => $page
->component('mcp/AuthorizeError')
->where('error', 'invalid_client'));
});
test('prompt=none guests receive login_required redirect instead of an inertia error page', function () {
$redirectUri = 'https://client.example/callback';
$clientId = mcpOauthClient('Silent Auth Guest');
DB::table('oauth_clients')->where('id', $clientId)->update([
'redirect_uris' => json_encode([$redirectUri]),
]);
$response = $this->get(route(
'passport.authorizations.authorize',
oauthAuthorizeQuery($clientId, $redirectUri, prompt: 'none'),
));
$response->assertRedirect();
expect($response->headers->get('Location'))
->toStartWith($redirectUri)
->toContain('error=login_required');
});
test('prompt=none authenticated users receive consent_required redirect instead of an inertia error page', function () {
$user = User::factory()->create();
$redirectUri = 'https://client.example/callback';
$clientId = mcpOauthClient('Silent Auth User');
DB::table('oauth_clients')->where('id', $clientId)->update([
'redirect_uris' => json_encode([$redirectUri]),
]);
$response = $this->actingAs($user)
->get(route(
'passport.authorizations.authorize',
oauthAuthorizeQuery($clientId, $redirectUri, prompt: 'none'),
));
$response->assertRedirect();
expect($response->headers->get('Location'))
->toStartWith($redirectUri)
->toContain('error=consent_required');
});