Skip to content

Commit 60ea10b

Browse files
committed
Fix clientCredentials scopes
1 parent 46bfcfe commit 60ea10b

File tree

3 files changed

+13
-35
lines changed

3 files changed

+13
-35
lines changed

dist/schema.json

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39250,29 +39250,7 @@
3925039250
"tokenUrl": "/oauth/token",
3925139251
"scopes": {
3925239252
"read": "Read access",
39253-
"write": "Write access",
39254-
"read:accounts": "Read access to accounts",
39255-
"read:blocks": "Read access to blocks",
39256-
"read:bookmarks": "Read access to bookmarks",
39257-
"read:favourites": "Read access to favourites",
39258-
"read:filters": "Read access to filters",
39259-
"read:follows": "Read access to follows",
39260-
"read:lists": "Read access to lists",
39261-
"read:mutes": "Read access to mutes",
39262-
"read:search": "Read access to search",
39263-
"read:statuses": "Read access to statuses",
39264-
"write:accounts": "Write access to accounts",
39265-
"write:blocks": "Write access to blocks",
39266-
"write:bookmarks": "Write access to bookmarks",
39267-
"write:conversations": "Write access to conversations",
39268-
"write:favourites": "Write access to favourites",
39269-
"write:filters": "Write access to filters",
39270-
"write:follows": "Write access to follows",
39271-
"write:lists": "Write access to lists",
39272-
"write:media": "Write access to media",
39273-
"write:mutes": "Write access to mutes",
39274-
"write:reports": "Write access to reports",
39275-
"write:statuses": "Write access to statuses"
39253+
"write:accounts": "Write access to accounts"
3927639254
}
3927739255
}
3927839256
}

src/__tests__/generators/SpecBuilder.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jest.mock('../../parsers/OAuthScopeParser', () => {
2828
scopes: [
2929
{ name: 'read', description: 'Read access' },
3030
{ name: 'write', description: 'Write access' },
31+
{ name: 'write:accounts', description: 'Manage your account' },
3132
],
3233
}),
3334
})),
@@ -187,11 +188,12 @@ describe('SpecBuilder', () => {
187188
'Write access'
188189
);
189190

190-
// Check clientCredentials flow has scopes
191+
// Check clientCredentials flow has limited scopes (read and write:accounts only)
191192
expect(oauth2.flows?.clientCredentials?.scopes).toBeDefined();
192193
expect(oauth2.flows?.clientCredentials?.scopes.read).toBe('Read access');
193-
expect(oauth2.flows?.clientCredentials?.scopes.write).toBe(
194-
'Write access'
194+
expect(oauth2.flows?.clientCredentials?.scopes.write).toBeUndefined();
195+
expect(oauth2.flows?.clientCredentials?.scopes['write:accounts']).toBe(
196+
'Manage your account'
195197
);
196198
});
197199
});

src/generators/SpecBuilder.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,15 @@ class SpecBuilder {
2424
scopesObject[scope.name] = scope.description;
2525
}
2626

27-
// Filter scopes for clientCredentials flow (typically only read/write scopes)
27+
// Filter scopes for clientCredentials flow (app tokens)
28+
// Per Mastodon docs, client credentials tokens can only be used for:
29+
// - GET /api/v1/apps/verify_credentials
30+
// - POST /api/v1/accounts (account creation)
31+
// So we only include minimal scopes needed for these endpoints
2832
const clientCredentialsScopes: Record<string, string> = {};
2933
for (const scope of oauthScopes.scopes) {
30-
// Include high-level scopes and non-user-specific scopes for client credentials
31-
if (
32-
['read', 'write'].includes(scope.name) ||
33-
(scope.name.startsWith('read:') &&
34-
!scope.name.includes('notifications')) ||
35-
(scope.name.startsWith('write:') &&
36-
!scope.name.includes('notifications'))
37-
) {
34+
// Only include read scope and write:accounts for account creation
35+
if (scope.name === 'read' || scope.name === 'write:accounts') {
3836
clientCredentialsScopes[scope.name] = scope.description;
3937
}
4038
}

0 commit comments

Comments
 (0)