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

Ability to Reject an authentication request instead of ignoring it #1453

Merged
merged 2 commits into from
Sep 5, 2024
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
14 changes: 10 additions & 4 deletions packages/extension-base/src/background/handlers/Extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,14 @@ export default class Extension {
return { list: remAuth };
}

private deleteAuthRequest (requestId: string): void {
return this.#state.deleteAuthRequest(requestId);
private rejectAuthRequest (id: string): void {
const queued = this.#state.getAuthRequest(id);

assert(queued, 'Unable to find request');

const { reject } = queued;

reject(new Error('Rejected'));
}

private updateCurrentTabs ({ urls }: RequestActiveTabsUrlUpdate) {
Expand All @@ -549,8 +555,8 @@ export default class Extension {
case 'pri(authorize.remove)':
return this.removeAuthorization(request as string);

case 'pri(authorize.delete.request)':
return this.deleteAuthRequest(request as string);
case 'pri(authorize.reject)':
return this.rejectAuthRequest(request as string);

case 'pri(authorize.requests)':
return port && this.authorizeSubscribe(id, port);
Expand Down
2 changes: 1 addition & 1 deletion packages/extension-base/src/background/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export interface RequestSignatures {
'pri(authorize.list)': [null, ResponseAuthorizeList];
'pri(authorize.requests)': [RequestAuthorizeSubscribe, boolean, AuthorizeRequest[]];
'pri(authorize.remove)': [string, ResponseAuthorizeList];
'pri(authorize.delete.request)': [string, void];
'pri(authorize.reject)': [string, void];
'pri(authorize.update)': [RequestUpdateAuthorizedAccounts, void];
'pri(activeTabsUrl.update)': [RequestActiveTabsUrlUpdate, void];
'pri(connectedTabsUrl.get)': [null, ConnectedTabsUrlResponse];
Expand Down
4 changes: 2 additions & 2 deletions packages/extension-ui/src/Popup/Authorize/NoAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React, { useCallback } from 'react';
import { Trans } from 'react-i18next';

import { Button, Warning } from '../../components/index.js';
import { deleteAuthRequest } from '../../messaging.js';
import { rejectAuthRequest } from '../../messaging.js';
import { styled } from '../../styled.js';

interface Props {
Expand All @@ -16,7 +16,7 @@ interface Props {

function NoAccount ({ authId, className }: Props): React.ReactElement<Props> {
const _onClick = useCallback(() => {
deleteAuthRequest(authId).catch(console.error);
rejectAuthRequest(authId).catch(console.error);
}, [authId]
);

Expand Down
6 changes: 3 additions & 3 deletions packages/extension-ui/src/Popup/Authorize/Request.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import React, { useCallback, useContext, useEffect } from 'react';

import { AccountContext, ActionBar, ActionContext, Button, Link } from '../../components/index.js';
import { useTranslation } from '../../hooks/index.js';
import { approveAuthRequest, deleteAuthRequest } from '../../messaging.js';
import { approveAuthRequest, rejectAuthRequest } from '../../messaging.js';
import { AccountSelection } from '../../partials/index.js';
import { styled } from '../../styled.js';
import NoAccount from './NoAccount.js';
Expand Down Expand Up @@ -44,7 +44,7 @@ function Request ({ authId, className, isFirst, request: { origin }, url }: Prop

const _onClose = useCallback(
(): void => {
deleteAuthRequest(authId)
rejectAuthRequest(authId)
.then(() => onAction())
.catch((error: Error) => console.error(error));
},
Expand Down Expand Up @@ -77,7 +77,7 @@ function Request ({ authId, className, isFirst, request: { origin }, url }: Prop
isDanger
onClick={_onClose}
>
{t('Ask again later')}
{t('Reject')}
</Link>
</ActionBar>
</div>
Expand Down
4 changes: 2 additions & 2 deletions packages/extension-ui/src/messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ export async function updateAuthorization (authorizedAccounts: string[], url: st
return sendMessage('pri(authorize.update)', { authorizedAccounts, url });
}

export async function deleteAuthRequest (requestId: string): Promise<void> {
return sendMessage('pri(authorize.delete.request)', requestId);
export async function rejectAuthRequest (requestId: string): Promise<void> {
return sendMessage('pri(authorize.reject)', requestId);
}

export async function subscribeMetadataRequests (cb: (accounts: MetadataRequest[]) => void): Promise<boolean> {
Expand Down