Skip to content

Commit 191651a

Browse files
authored
Show OAuth2 management link only for superusers (#57)
1 parent 240f45a commit 191651a

5 files changed

Lines changed: 41 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Changelog
22

3+
### Unreleased
4+
5+
- Updated the connect guidance so only superusers see the OAuth2 client management link, while other users are told to contact a superuser.
6+
37
### 5.0.2
48

59
- Disabled anonymous access to the MCP API endpoint and connect guidance page.

Controller.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ public function connect(): string
3131
$view = new View('@McpServer/connect');
3232
$this->setBasicVariablesView($view);
3333

34+
$hasSuperUserAccess = Access::getInstance()->hasSuperUserAccess();
35+
3436
$view->assign('isMcpEnabled', $this->systemSettings->isMcpEnabled());
3537
$view->assign('isOAuth2Enabled', $this->systemSettings->isOAuth2PluginEnabled());
36-
$view->assign('canAccessMcpSettings', Access::getInstance()->hasSuperUserAccess());
38+
$view->assign('canAccessMcpSettings', $hasSuperUserAccess);
39+
$view->assign('canManageOAuth2Clients', $hasSuperUserAccess);
3740
$view->assign('mcpApiEndpoint', $this->getMcpApiEndpointUrl());
3841
$view->assign('mcpSettingsUrl', $this->getMcpSettingsUrl());
3942
$view->assign('oauth2ClientManagementUrl', $this->getOAuth2ClientManagementUrl());

lang/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222
"ConnectNeedAuthMethod": "A compatible MCP client that supports your chosen authentication method",
2323
"ConnectNeedEndpoint": "The MCP server endpoint (URL)",
2424
"ConnectNeedOAuth2Client": "An OAuth2 client configured for your Matomo if you want to connect using OAuth2",
25+
"ConnectNeedOAuth2ClientNoPermission": "An OAuth2 client configured by a Matomo superuser if you want to connect using OAuth2",
2526
"ConnectNeedToken": "A Matomo %1$stoken_auth%2$s (used as a Bearer token)",
2627
"ConnectNeedTokenAlternative": "A Matomo %1$stoken_auth%2$s if you want to connect using token-based authentication",
2728
"ConnectOAuth2HelpLink": "OAuth2 is available for this MCP Server because the Matomo OAuth2 plugin is installed and enabled. If you do not already have an OAuth2 client for your MCP client, create one in %1$sAdministration -> Platform -> OAuth2 Clients%2$s first. OAuth2 allows you to use a dedicated client and can provide more granular access control.",
29+
"ConnectOAuth2HelpNoPermission": "OAuth2 is available for this MCP Server because the Matomo OAuth2 plugin is installed and enabled. If you do not already have an OAuth2 client for your MCP client, ask a Matomo superuser to create one for you. OAuth2 allows you to use a dedicated client and can provide more granular access control.",
2830
"ConnectOAuth2Title": "Recommended: Connect Using OAuth2",
2931
"ConnectPageTitle": "How to Connect to the MCP Server",
3032
"ConnectTokenAlternativeTitle": "Alternative: Connect Using token_auth",

templates/connect.twig

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424
<ul class="browser-default">
2525
<li>{{ 'McpServer_ConnectNeedEndpoint'|translate }}</li>
2626
{% if isOAuth2Enabled %}
27-
<li>{{ 'McpServer_ConnectNeedOAuth2Client'|translate }}</li>
27+
{% if canManageOAuth2Clients %}
28+
<li>{{ 'McpServer_ConnectNeedOAuth2Client'|translate }}</li>
29+
{% else %}
30+
<li>{{ 'McpServer_ConnectNeedOAuth2ClientNoPermission'|translate }}</li>
31+
{% endif %}
2832
<li>{{ 'McpServer_ConnectNeedAuthMethod'|translate }}</li>
2933
<li>{{ 'McpServer_ConnectNeedTokenAlternative'|translate('<code>', '</code>')|raw }}</li>
3034
{% else %}
@@ -82,7 +86,11 @@
8286
{% if isOAuth2Enabled %}
8387
<h3>{{ 'McpServer_ConnectOAuth2Title'|translate }}</h3>
8488
<p>
85-
{{ 'McpServer_ConnectOAuth2HelpLink'|translate('<a href="' ~ oauth2ClientManagementUrl|escape('html_attr') ~ '">', '</a>')|raw }}
89+
{% if canManageOAuth2Clients %}
90+
{{ 'McpServer_ConnectOAuth2HelpLink'|translate('<a href="' ~ oauth2ClientManagementUrl|escape('html_attr') ~ '">', '</a>')|raw }}
91+
{% else %}
92+
{{ 'McpServer_ConnectOAuth2HelpNoPermission'|translate }}
93+
{% endif %}
8694
</p>
8795
<h3>{{ 'McpServer_ConnectTokenAlternativeTitle'|translate }}</h3>
8896
<p>{{ 'McpServer_ConnectInClientTokenHelpAlternative'|translate('<code>', '</code>', '<a href="' ~ userSecurityUrl|escape('html_attr') ~ '">', '</a>', '<code>', '</code>')|raw }}</p>

tests/UI/McpServer_spec.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ describe('McpServer', function () {
254254
expect(await page.$(`${connectSelector} a[href*="module=CoreAdminHome"][href*="action=generalSettings"]`)).to.equal(null);
255255
});
256256

257-
it('should display OAuth2 guidance when the OAuth2 plugin is enabled', async function () {
257+
it('should display OAuth2 client management guidance for superusers when the OAuth2 plugin is enabled', async function () {
258258
await configureMcp(true);
259259
testEnvironment.mockOAuth2PluginEnabled = 1;
260260
testEnvironment.save();
@@ -286,4 +286,24 @@ describe('McpServer', function () {
286286

287287
expect(await page.screenshotSelector(connectSelector)).to.matchImage('connect_oauth2');
288288
});
289+
290+
it('should display contact-superuser OAuth2 guidance for view users when the OAuth2 plugin is enabled', async function () {
291+
await configureMcp(true);
292+
testEnvironment.mockOAuth2PluginEnabled = 1;
293+
testEnvironment.save();
294+
setViewUser();
295+
296+
await page.goto(connectUrl);
297+
await page.waitForNetworkIdle();
298+
await page.waitForSelector(connectSelector, { visible: true });
299+
300+
const text = await getConnectText();
301+
302+
expect(text).to.contain('OAuth2 is available for this MCP Server and is the recommended way to connect.');
303+
expect(text).to.contain('Recommended: Connect Using OAuth2');
304+
expect(text).to.contain('An OAuth2 client configured by a Matomo superuser if you want to connect using OAuth2');
305+
expect(text).to.contain('If you do not already have an OAuth2 client for your MCP client, ask a Matomo superuser to create one for you.');
306+
expect(text).to.not.contain('If you do not already have an OAuth2 client for your MCP client, create one in Administration -> Platform -> OAuth2 Clients first.');
307+
expect(await page.$(`${connectSelector} a[href*="module=OAuth2"][href*="action=index"]`)).to.equal(null);
308+
});
289309
});

0 commit comments

Comments
 (0)