Skip to content

Commit e04c9fe

Browse files
authored
feat: public_repo alternate scopes (#1831)
1 parent 1c8c17b commit e04c9fe

File tree

5 files changed

+59
-32
lines changed

5 files changed

+59
-32
lines changed

src/renderer/routes/Accounts.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ import { Header } from '../components/primitives/Header';
3131
import { AppContext } from '../context/App';
3232
import { type Account, Size } from '../types';
3333
import {
34-
formatRequiredScopes,
34+
formatAlternateOAuthScopes,
35+
formatRecommendedOAuthScopes,
3536
getAccountUUID,
3637
refreshAccount,
3738
} from '../utils/auth/utils';
@@ -194,8 +195,8 @@ export const AccountsRoute: FC = () => {
194195
<Stack direction="horizontal" gap="condensed">
195196
<IconButton
196197
icon={AlertFillIcon}
197-
aria-label={`This account is missing one or more required scopes: [${formatRequiredScopes()}]`}
198-
variant="danger"
198+
aria-label={`This account is missing one or more required scopes: [${formatRecommendedOAuthScopes()}] or [${formatAlternateOAuthScopes()}]`}
199+
style={{ color: 'orange' }}
199200
onClick={() => openDeveloperSettings(account)}
200201
size="small"
201202
data-testid="account-missing-scopes"

src/renderer/routes/LoginWithPersonalAccessToken.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { AppContext } from '../context/App';
2727
import type { Hostname, Token } from '../types';
2828
import type { LoginPersonalAccessTokenOptions } from '../utils/auth/types';
2929
import {
30-
formatRequiredScopes,
30+
formatRecommendedOAuthScopes,
3131
getNewTokenURL,
3232
isValidHostname,
3333
isValidToken,
@@ -192,7 +192,7 @@ export const LoginWithPersonalAccessTokenRoute: FC = () => {
192192

193193
<Text as="i" className="text-xs">
194194
The{' '}
195-
<Tooltip text={formatRequiredScopes()} direction="se">
195+
<Tooltip text={formatRecommendedOAuthScopes()} direction="se">
196196
<Text as="u">required scopes</Text>
197197
</Tooltip>{' '}
198198
will be automatically selected for you.

src/renderer/routes/__snapshots__/Accounts.test.tsx.snap

Lines changed: 27 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/renderer/utils/auth/utils.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ export function authGitHub(
3030
const authUrl = new URL(`https://${authOptions.hostname}`);
3131
authUrl.pathname = '/login/oauth/authorize';
3232
authUrl.searchParams.append('client_id', authOptions.clientId);
33-
authUrl.searchParams.append('scope', Constants.AUTH_SCOPE.toString());
33+
authUrl.searchParams.append(
34+
'scope',
35+
Constants.OAUTH_SCOPES.RECOMMENDED.toString(),
36+
);
3437

3538
openExternalLink(authUrl.toString() as Link);
3639

@@ -175,9 +178,13 @@ export async function refreshAccount(account: Account): Promise<Account> {
175178
?.split(',')
176179
.map((scope: string) => scope.trim());
177180

178-
account.hasRequiredScopes = Constants.AUTH_SCOPE.every((scope) =>
179-
accountScopes.includes(scope),
180-
);
181+
account.hasRequiredScopes =
182+
Constants.OAUTH_SCOPES.RECOMMENDED.every((scope) =>
183+
accountScopes.includes(scope),
184+
) ||
185+
Constants.OAUTH_SCOPES.ALTERNATE.every((scope) =>
186+
accountScopes.includes(scope),
187+
);
181188

182189
if (!account.hasRequiredScopes) {
183190
logWarn(
@@ -232,7 +239,10 @@ export function getNewTokenURL(hostname: Hostname): Link {
232239
'description',
233240
`${APPLICATION.NAME} (Created on ${date})`,
234241
);
235-
newTokenURL.searchParams.append('scopes', Constants.AUTH_SCOPE.join(','));
242+
newTokenURL.searchParams.append(
243+
'scopes',
244+
Constants.OAUTH_SCOPES.RECOMMENDED.join(','),
245+
);
236246

237247
return newTokenURL.toString() as Link;
238248
}
@@ -282,6 +292,10 @@ export function hasMultipleAccounts(auth: AuthState) {
282292
return auth.accounts.length > 1;
283293
}
284294

285-
export function formatRequiredScopes() {
286-
return Constants.AUTH_SCOPE.join(', ');
295+
export function formatRecommendedOAuthScopes() {
296+
return Constants.OAUTH_SCOPES.RECOMMENDED.join(', ');
297+
}
298+
299+
export function formatAlternateOAuthScopes() {
300+
return Constants.OAUTH_SCOPES.ALTERNATE.join(', ');
287301
}

src/renderer/utils/constants.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ export const Constants = {
88

99
NOTIFICATION_SOUND: 'clearly.mp3',
1010

11-
// GitHub OAuth
12-
AUTH_SCOPE: ['read:user', 'notifications', 'repo'],
11+
// GitHub OAuth Scopes
12+
OAUTH_SCOPES: {
13+
RECOMMENDED: ['read:user', 'notifications', 'repo'],
14+
ALTERNATE: ['read:user', 'notifications', 'public_repo'],
15+
},
1316

1417
DEFAULT_AUTH_OPTIONS: {
1518
hostname: 'github.com' as Hostname,

0 commit comments

Comments
 (0)