Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: public_repo alternate scopes #1831

Merged
merged 1 commit into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/renderer/routes/Accounts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import { Header } from '../components/primitives/Header';
import { AppContext } from '../context/App';
import { type Account, Size } from '../types';
import {
formatRequiredScopes,
formatAlternateOAuthScopes,
formatRecommendedOAuthScopes,
getAccountUUID,
refreshAccount,
} from '../utils/auth/utils';
Expand Down Expand Up @@ -194,8 +195,8 @@ export const AccountsRoute: FC = () => {
<Stack direction="horizontal" gap="condensed">
<IconButton
icon={AlertFillIcon}
aria-label={`This account is missing one or more required scopes: [${formatRequiredScopes()}]`}
variant="danger"
aria-label={`This account is missing one or more required scopes: [${formatRecommendedOAuthScopes()}] or [${formatAlternateOAuthScopes()}]`}
style={{ color: 'orange' }}
onClick={() => openDeveloperSettings(account)}
size="small"
data-testid="account-missing-scopes"
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/routes/LoginWithPersonalAccessToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { AppContext } from '../context/App';
import type { Hostname, Token } from '../types';
import type { LoginPersonalAccessTokenOptions } from '../utils/auth/types';
import {
formatRequiredScopes,
formatRecommendedOAuthScopes,
getNewTokenURL,
isValidHostname,
isValidToken,
Expand Down Expand Up @@ -192,7 +192,7 @@ export const LoginWithPersonalAccessTokenRoute: FC = () => {

<Text as="i" className="text-xs">
The{' '}
<Tooltip text={formatRequiredScopes()} direction="se">
<Tooltip text={formatRecommendedOAuthScopes()} direction="se">
<Text as="u">required scopes</Text>
</Tooltip>{' '}
will be automatically selected for you.
Expand Down
45 changes: 27 additions & 18 deletions src/renderer/routes/__snapshots__/Accounts.test.tsx.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 21 additions & 7 deletions src/renderer/utils/auth/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ export function authGitHub(
const authUrl = new URL(`https://${authOptions.hostname}`);
authUrl.pathname = '/login/oauth/authorize';
authUrl.searchParams.append('client_id', authOptions.clientId);
authUrl.searchParams.append('scope', Constants.AUTH_SCOPE.toString());
authUrl.searchParams.append(
'scope',
Constants.OAUTH_SCOPES.RECOMMENDED.toString(),
);

openExternalLink(authUrl.toString() as Link);

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

account.hasRequiredScopes = Constants.AUTH_SCOPE.every((scope) =>
accountScopes.includes(scope),
);
account.hasRequiredScopes =
Constants.OAUTH_SCOPES.RECOMMENDED.every((scope) =>
accountScopes.includes(scope),
) ||
Constants.OAUTH_SCOPES.ALTERNATE.every((scope) =>
accountScopes.includes(scope),
);

if (!account.hasRequiredScopes) {
logWarn(
Expand Down Expand Up @@ -232,7 +239,10 @@ export function getNewTokenURL(hostname: Hostname): Link {
'description',
`${APPLICATION.NAME} (Created on ${date})`,
);
newTokenURL.searchParams.append('scopes', Constants.AUTH_SCOPE.join(','));
newTokenURL.searchParams.append(
'scopes',
Constants.OAUTH_SCOPES.RECOMMENDED.join(','),
);

return newTokenURL.toString() as Link;
}
Expand Down Expand Up @@ -282,6 +292,10 @@ export function hasMultipleAccounts(auth: AuthState) {
return auth.accounts.length > 1;
}

export function formatRequiredScopes() {
return Constants.AUTH_SCOPE.join(', ');
export function formatRecommendedOAuthScopes() {
return Constants.OAUTH_SCOPES.RECOMMENDED.join(', ');
}

export function formatAlternateOAuthScopes() {
return Constants.OAUTH_SCOPES.ALTERNATE.join(', ');
}
7 changes: 5 additions & 2 deletions src/renderer/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ export const Constants = {

NOTIFICATION_SOUND: 'clearly.mp3',

// GitHub OAuth
AUTH_SCOPE: ['read:user', 'notifications', 'repo'],
// GitHub OAuth Scopes
OAUTH_SCOPES: {
RECOMMENDED: ['read:user', 'notifications', 'repo'],
ALTERNATE: ['read:user', 'notifications', 'public_repo'],
},

DEFAULT_AUTH_OPTIONS: {
hostname: 'github.com' as Hostname,
Expand Down
Loading