add change redirect uri from oauth
This commit is contained in:
@@ -107,6 +107,29 @@ export default function AdminOAuthPage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleSaveRedirectUris(client: OAuthClient, redirectUris: string[]) {
|
||||||
|
if (!token) return;
|
||||||
|
if (!redirectUris.length) {
|
||||||
|
showToast('Укажите хотя бы один redirect URI');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const updated = await apiFetch<OAuthClient>(`/admin/rbac/oauth-clients/${client.clientId}`, {
|
||||||
|
method: 'PATCH',
|
||||||
|
body: JSON.stringify({ redirectUris })
|
||||||
|
}, token);
|
||||||
|
showToast('Redirect URI обновлены');
|
||||||
|
setSelectedClient((current) =>
|
||||||
|
current?.clientId === client.clientId
|
||||||
|
? { ...current, redirectUris: updated.redirectUris ?? redirectUris }
|
||||||
|
: current
|
||||||
|
);
|
||||||
|
await loadData();
|
||||||
|
} catch (error) {
|
||||||
|
showToast(error instanceof Error ? error.message : 'Не удалось сохранить redirect URI');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function handleRotateSecret(clientId: string) {
|
async function handleRotateSecret(clientId: string) {
|
||||||
if (!token) return;
|
if (!token) return;
|
||||||
try {
|
try {
|
||||||
@@ -227,6 +250,7 @@ export default function AdminOAuthPage() {
|
|||||||
onRotateSecret={(clientId) => void handleRotateSecret(clientId)}
|
onRotateSecret={(clientId) => void handleRotateSecret(clientId)}
|
||||||
onToggleActive={(client) => void handleToggleActive(client)}
|
onToggleActive={(client) => void handleToggleActive(client)}
|
||||||
onDelete={(client) => void handleDeleteClient(client)}
|
onDelete={(client) => void handleDeleteClient(client)}
|
||||||
|
onSaveRedirectUris={handleSaveRedirectUris}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Dialog open={dialogOpen} onOpenChange={setDialogOpen}>
|
<Dialog open={dialogOpen} onOpenChange={setDialogOpen}>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { Copy, ExternalLink, KeyRound, RefreshCw, Trash2 } from 'lucide-react';
|
import { useEffect, useState } from 'react';
|
||||||
|
import { Copy, ExternalLink, KeyRound, Loader2, RefreshCw, Trash2 } from 'lucide-react';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||||
import { OAuthClient } from '@/lib/api';
|
import { OAuthClient } from '@/lib/api';
|
||||||
@@ -28,7 +29,8 @@ export function OAuthClientDetailDialog({
|
|||||||
onCopy,
|
onCopy,
|
||||||
onRotateSecret,
|
onRotateSecret,
|
||||||
onToggleActive,
|
onToggleActive,
|
||||||
onDelete
|
onDelete,
|
||||||
|
onSaveRedirectUris
|
||||||
}: {
|
}: {
|
||||||
client: OAuthClient | null;
|
client: OAuthClient | null;
|
||||||
endpoints: OAuthEndpoints;
|
endpoints: OAuthEndpoints;
|
||||||
@@ -38,7 +40,16 @@ export function OAuthClientDetailDialog({
|
|||||||
onRotateSecret: (clientId: string) => void;
|
onRotateSecret: (clientId: string) => void;
|
||||||
onToggleActive: (client: OAuthClient) => void;
|
onToggleActive: (client: OAuthClient) => void;
|
||||||
onDelete: (client: OAuthClient) => void;
|
onDelete: (client: OAuthClient) => void;
|
||||||
|
onSaveRedirectUris: (client: OAuthClient, redirectUris: string[]) => Promise<void>;
|
||||||
}) {
|
}) {
|
||||||
|
const [redirectUrisDraft, setRedirectUrisDraft] = useState('');
|
||||||
|
const [savingRedirectUris, setSavingRedirectUris] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!client) return;
|
||||||
|
setRedirectUrisDraft(client.redirectUris.join('\n'));
|
||||||
|
}, [client]);
|
||||||
|
|
||||||
if (!client) return null;
|
if (!client) return null;
|
||||||
|
|
||||||
const primaryRedirect = client.redirectUris[0] ?? 'https://app.example.com/oauth/callback';
|
const primaryRedirect = client.redirectUris[0] ?? 'https://app.example.com/oauth/callback';
|
||||||
@@ -77,7 +88,48 @@ export function OAuthClientDetailDialog({
|
|||||||
Client Secret выдаётся один раз при создании или после «Новый secret». Храните только на backend.
|
Client Secret выдаётся один раз при создании или после «Новый secret». Храните только на backend.
|
||||||
</p>
|
</p>
|
||||||
) : null}
|
) : null}
|
||||||
<CopyRow label="Redirect URI" value={client.redirectUris.join('\n')} onCopy={onCopy} />
|
<div className="space-y-2">
|
||||||
|
<div className="flex items-center justify-between gap-2">
|
||||||
|
<span className="font-medium">Redirect URI</span>
|
||||||
|
{client.canManage ? null : (
|
||||||
|
<Button variant="ghost" size="icon" aria-label="Скопировать Redirect URI" onClick={() => onCopy(client.redirectUris.join('\n'), 'Redirect URI')}>
|
||||||
|
<Copy className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{client.canManage ? (
|
||||||
|
<>
|
||||||
|
<textarea
|
||||||
|
value={redirectUrisDraft}
|
||||||
|
onChange={(event) => setRedirectUrisDraft(event.target.value)}
|
||||||
|
placeholder="https://app.example.com/oauth/callback"
|
||||||
|
className="min-h-[96px] w-full rounded-xl border border-[#eceef4] bg-white px-3 py-2 text-sm"
|
||||||
|
/>
|
||||||
|
<p className="text-xs text-[#667085]">
|
||||||
|
По одному URI на строку. Должен точно совпадать с redirect_uri в запросе authorize (протокол, домен, путь, слэш).
|
||||||
|
</p>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
disabled={savingRedirectUris}
|
||||||
|
onClick={() => {
|
||||||
|
const redirectUris = redirectUrisDraft
|
||||||
|
.split('\n')
|
||||||
|
.map((item) => item.trim())
|
||||||
|
.filter(Boolean);
|
||||||
|
setSavingRedirectUris(true);
|
||||||
|
void onSaveRedirectUris(client, redirectUris).finally(() => setSavingRedirectUris(false));
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{savingRedirectUris ? <Loader2 className="mr-2 h-4 w-4 animate-spin" /> : null}
|
||||||
|
Сохранить redirect URI
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<div className="rounded-2xl bg-[#f4f5f8] p-4 text-sm">
|
||||||
|
<code className="block whitespace-pre-wrap break-all text-xs">{client.redirectUris.join('\n')}</code>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
<CopyRow label="Scopes" value={scope} onCopy={onCopy} />
|
<CopyRow label="Scopes" value={scope} onCopy={onCopy} />
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user