Laravel-based OAuth/IAM service with Passport, Vue 3 frontend, and Docker Compose setup for local and production deployment. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
185 lines
6.5 KiB
Vue
185 lines
6.5 KiB
Vue
<script setup lang="ts">
|
|
import { onMounted, reactive, ref } from 'vue';
|
|
import axios from 'axios';
|
|
import { useI18n } from 'vue-i18n';
|
|
import type { OAuthClient } from '../types/models';
|
|
|
|
const { t } = useI18n();
|
|
|
|
const clients = ref<OAuthClient[]>([]);
|
|
const loading = ref(true);
|
|
const creating = ref(false);
|
|
const newSecret = ref<{ name: string; secret: string; id: string } | null>(null);
|
|
|
|
const form = reactive({
|
|
name: '',
|
|
grant_type: 'authorization_code',
|
|
redirect_uris: '',
|
|
confidential: true,
|
|
});
|
|
const errors = ref<Record<string, string[]>>({});
|
|
|
|
async function load(): Promise<void> {
|
|
loading.value = true;
|
|
const { data } = await axios.get<OAuthClient[]>('/web-api/clients');
|
|
clients.value = data;
|
|
loading.value = false;
|
|
}
|
|
|
|
async function createClient(): Promise<void> {
|
|
creating.value = true;
|
|
errors.value = {};
|
|
newSecret.value = null;
|
|
|
|
try {
|
|
const payload = {
|
|
name: form.name,
|
|
grant_type: form.grant_type,
|
|
confidential: form.grant_type === 'client_credentials' ? true : form.confidential,
|
|
redirect_uris: form.redirect_uris
|
|
? form.redirect_uris.split(',').map((u) => u.trim()).filter(Boolean)
|
|
: [],
|
|
};
|
|
|
|
const { data } = await axios.post<{ client: OAuthClient; plain_secret: string | null }>('/web-api/clients', payload);
|
|
|
|
if (data.plain_secret) {
|
|
newSecret.value = { name: data.client.name, secret: data.plain_secret, id: data.client.id };
|
|
}
|
|
|
|
form.name = '';
|
|
form.redirect_uris = '';
|
|
await load();
|
|
} catch (e: any) {
|
|
errors.value = e.response?.data?.errors ?? {};
|
|
} finally {
|
|
creating.value = false;
|
|
}
|
|
}
|
|
|
|
async function revoke(client: OAuthClient): Promise<void> {
|
|
if (!confirm(t('clients.revokeConfirm', { name: client.name }))) return;
|
|
|
|
await axios.delete(`/web-api/clients/${client.id}`);
|
|
await load();
|
|
}
|
|
|
|
function grantLabel(grantTypes: string[]): string {
|
|
if (grantTypes.includes('authorization_code')) return t('clients.grantAuthCode');
|
|
if (grantTypes.includes('client_credentials')) return t('clients.grantClientCredentials');
|
|
if (grantTypes.includes('password')) return t('clients.grantPassword');
|
|
return grantTypes.join(', ');
|
|
}
|
|
|
|
onMounted(load);
|
|
</script>
|
|
|
|
<template>
|
|
<div>
|
|
<h1 class="page-title">{{ t('clients.title') }}</h1>
|
|
<p class="page-subtitle">{{ t('clients.subtitle') }}</p>
|
|
|
|
<div v-if="newSecret" class="banner banner--warning">
|
|
<p class="banner__title">{{ t('clients.secretWarning') }}</p>
|
|
<p class="banner__line"><strong>{{ t('clients.clientIdLabel') }}</strong> <code class="banner__code">{{ newSecret.id }}</code></p>
|
|
<p class="banner__line"><strong>{{ t('clients.clientSecretLabel') }}</strong> <code class="banner__code">{{ newSecret.secret }}</code></p>
|
|
<button class="banner__close" @click="newSecret = null">{{ t('common.close') }}</button>
|
|
</div>
|
|
|
|
<form class="card clients__form" @submit.prevent="createClient">
|
|
<h2 class="card__title clients__form-title">{{ t('clients.newClient') }}</h2>
|
|
|
|
<div class="field">
|
|
<label class="field__label">{{ t('clients.name') }}</label>
|
|
<input v-model="form.name" required class="field__input" />
|
|
<p v-if="errors.name" class="field__error">{{ errors.name[0] }}</p>
|
|
</div>
|
|
|
|
<div class="field">
|
|
<label class="field__label">{{ t('clients.grantType') }}</label>
|
|
<select v-model="form.grant_type" class="field__select">
|
|
<option value="authorization_code">{{ t('clients.grantAuthCode') }}</option>
|
|
<option value="client_credentials">{{ t('clients.grantClientCredentials') }}</option>
|
|
<option value="password">{{ t('clients.grantPassword') }}</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div v-if="form.grant_type === 'authorization_code'" class="field clients__form-wide">
|
|
<label class="field__label">{{ t('clients.redirectUris') }}</label>
|
|
<input v-model="form.redirect_uris" placeholder="https://mi-app.com/callback" class="field__input" />
|
|
<p v-if="errors.redirect_uris" class="field__error">{{ errors.redirect_uris[0] }}</p>
|
|
</div>
|
|
|
|
<div v-if="form.grant_type === 'authorization_code'" class="field__checkbox-row">
|
|
<input id="confidential" type="checkbox" v-model="form.confidential" class="field__checkbox" />
|
|
<label for="confidential">{{ t('clients.confidentialLabel') }}</label>
|
|
</div>
|
|
|
|
<div class="clients__form-wide">
|
|
<button type="submit" :disabled="creating" class="btn btn--primary">
|
|
{{ creating ? t('common.creating') : t('clients.create') }}
|
|
</button>
|
|
</div>
|
|
</form>
|
|
|
|
<div class="clients__list">
|
|
<p v-if="loading" class="page-subtitle">{{ t('common.loading') }}</p>
|
|
<p v-else-if="!clients.length" class="page-subtitle">{{ t('clients.empty') }}</p>
|
|
|
|
<div v-for="client in clients" :key="client.id" class="card clients__item">
|
|
<div>
|
|
<p class="card__title">{{ client.name }}</p>
|
|
<p class="card__subtitle">{{ grantLabel(client.grant_types) }}</p>
|
|
<p class="clients__item-meta">{{ t('clients.clientIdShort') }}: {{ client.id }}</p>
|
|
<p v-if="client.redirect_uris?.length" class="clients__item-meta">
|
|
{{ t('clients.redirectLabel') }}: {{ client.redirect_uris.join(', ') }}
|
|
</p>
|
|
</div>
|
|
<button @click="revoke(client)" class="link link--danger">{{ t('clients.revoke') }}</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.clients__form {
|
|
margin-top: 1.5rem;
|
|
display: grid;
|
|
grid-template-columns: 1fr;
|
|
gap: 1rem;
|
|
}
|
|
|
|
.clients__form-title {
|
|
grid-column: 1 / -1;
|
|
}
|
|
|
|
.clients__form-wide {
|
|
grid-column: 1 / -1;
|
|
}
|
|
|
|
.clients__list {
|
|
margin-top: 1.5rem;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 0.75rem;
|
|
}
|
|
|
|
.clients__item {
|
|
display: flex;
|
|
align-items: flex-start;
|
|
justify-content: space-between;
|
|
}
|
|
|
|
.clients__item-meta {
|
|
margin-top: 0.25rem;
|
|
font-size: 0.75rem;
|
|
color: var(--color-text-muted);
|
|
}
|
|
|
|
@media (min-width: 640px) {
|
|
.clients__form {
|
|
grid-template-columns: 1fr 1fr;
|
|
}
|
|
}
|
|
</style>
|